Which seems to ignore the callback that changes a parameter in the integration. Not sure what is going on… Is it a problem on my end? Or is this something else?
I’m running Julia Version 1.11.1 (2024-10-16), Pluto v0.20.3 and DifferentialEquations v7.14.0 (and Plots v1.40.8, although the same is produced with CairoMakie)
Pluto has no internal state of the notebook unless you work with mutable objects That’s pretty subtle, but I guess it makes sense (?)
And allows one to “hack” the notebook a bit by creating constructs that do depend on cell order.
So modifying a Vector for example will persist if the cell defining (and thus “resetting”) the Vector is not re-run explicitly.
In Pluto’s internal dependency graph, running [Cell 7] does not trigger [Cell 4] because that code does not depend on anything from [Cell 7], but the object that was created in [Cell 4] (the parameter vector) can be modified and re-used without problem.
One solution to your problem might be to either use an immutable type for your parameters (not sure if that’s possible with the callback) or making sure that a new parameter vector is generated when you run the solve cell. Something like this perhaps:
make_problem() = ODEProblem(...)
...
sol = solve(make_problem(), ...)
Then every time, the solve cell is re-run, it re-generates a new problem. But make sure to not re-use the same object in the problem again, so this probably still won’t work (there is only one testP object which will be re-used all the time)
make_problem() = ODEProblem(..., testP, ...)
and might need to be this (I’m sure there are nicer ways to write it though, depends on what you need):
Pluto.jl cannot track arbitrary dependencies between cells (and if you think about it this also doesn’t make because you ran into ambiguous situations very quickly - find an example below). Pluto generally tracks assignments to variables and nothing else. Since you affect! modifies only the value inside something a variable refers to, Pluto.jl has no chance of seeing this dependency.
In general you should keep things, that mutate inside the cell that defines what is being mutated to keep things consistent. I agree that it is a bit difficult to see in your scenario.
Example: Ambigous cell order
# Cell 1
var = [1,2]
# Cell 2
var[1] += 3
# Cell 3
var[1] *= 2
# Cell 4
var # what should this print?!
As you can see the order of Cells 2 and 3 is completely ambiguous.
I ended up wrapping some parts of my code inside of functions to make it more predictable and benefit from the updating of Pluto when changing stuff around.