JuliaDynamics / DynamicalSystems.jl

Award winning software library for nonlinear dynamics and nonlinear timeseries analysis

Home Page:https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyword `dt` is already used by diff eq -> conflict with fixed step solvers

TianzhuangXu opened this issue · comments

Hey, everybody. I have encountered one problem when using dynamical systems. There are some cases that one want to use fixed time step solvers instead of adaptive ones with TOL while simulating continuous systems, a typical example is the lorenz06 model where Lorenz changed the time step and found the model may have different Lyapunov exponents. However, in DynamicalSystems.jl, one cannot conveniently do that. I hope the dt parameter can be aligned with that in DifferentialEquations, which is better to conduct customized simulations (In DifferentialEquations.jl, one can set the "dt" and “adaptive” to false to conduct fixed step simulation. While in DynamicalSystems.jl, dt is used to specify the output instead of the actual time step. I think maybe its better to align with the expression in DifferentialEquations.jl with "saveat" to express the output dt).

for example :

lor = Systems.lorenz()
λλ = lyapunovs(lor, 10000, dt = 0.1)
Here, dt does only specify the output time step. One cannot conduct a fixed-step simulation to assign the time step with dt.

While in DifferentialEquations.jl, one use dt to set the time step during simulation and saveat to set the time step to output:
solve(lor, TsitPap8(), adaptive=false, dt=1e-4, saveat=0.1)

I think it's necessary to add that function in DynamicalSystems.jl


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Correct if I am wrong, but shouldn't you be able to use adaptive = false and init_dt = dt, and it would work for any solver? @ChrisRackauckas ?

Correct if I am wrong, but shouldn't you be able to use adaptive = false and init_dt = dt, and it would work for any solver? @ChrisRackauckas ?

I have tried that parameter and that makes no difference. Would you mind providing me some reference about the parameter init_dt? I cannot find it in the documentation about time evolution, also Juno seems fail to recognize that parameter?

Ah damn, the keyword dt stands for the initial dt in DiffEq.

Okay, so, where is the problem? You've tried dt = 0.1, adaptive = false as keywords to lyapunovs and it didn't work? Can you provide a MWE?

I tried it, yes, the result is correct. I tried an extremely sensitive system, the result was wrong when I used @inline and @inbounds when defining the ODE, when I delete it the result is coherent with that computed with DiffEq.

For example:
trajectory(ds, 10000, dt=1e-3, alg = TsitPap8(), adaptive=false)
it works, however it also has some problem about memory when using tiny dt=1e-5.

However, there seems another problem when I tried the exact same setup in function lyapunovs:
lyapunovs(ds, 10000, dt=1e-3, alg = TsitPap8(), adaptive=false)
it declares > Fixed timestep methods require a choice of dt or choosing the tstops. It seems dt is not recognized here?

Oh wait. I think we actually have a problem here. In lyapunovs dt is not the timestep the integrator takes. It is the time between successive re-normalizations of the tangent space. Similarly, in trajectory in fact dt only ends up configuring the saveat argument, it doesn't do anything about the initial step (and thus all subsequent step sizes if adaptive = false).

This means, that at the moment, there is no way to configure the initial dt of an integrator for diff eq. We have to think about this!

Yes, that makes sense why lyaunovs fail but in trajectory it seems to work. I think it's better to make the dt more aligned with that in DiffEq, the current dt here is a little misleading for users.

It isn't as trivial as you say. Changing dt to mean something entirely different is a majorly breaking change that I can't do yet. A better alternative needs to be found. In the future, where DynamicalSystmes 2.0 will be released we can safely change dt. In DynamicalSystems.jl we can use the symbol Δt or δt to mean what the current dt means.

Maybe you are up for making a PR that does this? allow both keywords and show deprecation warning when using keyword dt ?

Sure, I am very willing to take a shot to make some contributions to the issue if I can. But till now I lack the expierence, say, developing for packages. Would you be so kind to provide some simple suggestions for me to get started with that problem?

You have to go into the definition of functions from DynamicalSystems.jl that use the dt keyword. There, in the function definition you have to change the argument dt = 1 to :

dt = nothing, Δt = 1

and inside the core of the function add the statement:

if dt != nothing
  @warn "Keyword `dt` is deprecated in favor of `Δt`. In the future `dt` will not exist, and be propagate to DifferentialEquations.jl (and thus mean the initial timestep of the integrator)"
  Δt = dt
end

and then subsequently swap the usage of dt with Δt in the function core.

Regarding package development, there are several tutorials on both using Git as well as Julia specific package development, so it is best to not repeat here. Googling will give you plenty of results, for example: https://www.youtube.com/watch?v=QVmU29rCjaA

check also the Julia Pkg docs on "developing packages".

Once you have the changes done in your local version, you have to upload them to github and start a pull request to the appropriate repo (DynamicalSystemsBase / ChaosTools).

Thanks a lot! Your suggestions are clear and informative, I will try that.