SciML / DifferentialEquations.jl

Multi-language suite for high-performance solvers of differential equations and scientific machine learning (SciML) components. Ordinary differential equations (ODEs), stochastic differential equations (SDEs), delay differential equations (DDEs), differential-algebraic equations (DAEs), and more in Julia.
https://docs.sciml.ai/DiffEqDocs/stable/
Other
2.86k stars 228 forks source link

Add more user-friendly interface for output at specified timesteps #132

Closed Datseris closed 7 years ago

Datseris commented 7 years ago

My suggestion is to turn this: sol = solve(prob; saveat=0.0:0.01:tspan[end],save_timeseries=false,dense=false) into this: sol = solve(prob; dt =0.01) where the solve is given for a adaptive size solver.

The visual noise of requesting solution at fixed timesteps is a bit big, and maybe, internally a magic takes place that maps the dt=0.01 to a saveat=0.0:0.01:tspan[end],save_timeseries=false,dense=false .

Very often a solution is required at fixed timesteps, even if it comes at the expense of memory (for e.g. a fourier transform). The above consideration would help greatly users that prefer the solutions at fixed timesteps for research purposes.

(I am aware of what the current dt keyword does. I think the suggestion here makes dt much more useful, while keeps its use for fixed timestep methods completely un-altered)

ChrisRackauckas commented 7 years ago

Being able to set the initial dt for adaptive solvers is pretty crucial because the heuristics that are employed aren't necessarily great. I just had a idea for this. What about the following: if you give saveat a number, it expands it into the range tspan[1]:saveat_num:tspan[end]? Then the following would work:

sol = solve(prob; saveat=0.01,save_timeseries=false)

This is using the fact that dense=false if save_timeseries=false. It's easy to understand why this must be the case (you can't interpolate using derivatives if you don't know the values at the endpoints!), but I just checked and realized I didn't mention this in the docs.

Is that concise enough? I'm scared of putting in too much magic.

Datseris commented 7 years ago

Good enough compromise to have saveat::Number which makes the range by itself. I had not understood the importance of dt, sorry for that :/

Datseris commented 7 years ago

Also, see the new issue that suggests to make save_timeseries default to false when a saveat is provided. That would greatly reduce all the above to just: sol = solve(prob; saveat = my_dt)

ChrisRackauckas commented 7 years ago

I do like the suggestion. I'll let the issue hang here for a bit and see if anyone else has a preference on it.

ChrisRackauckas commented 7 years ago

I will definitely be adding the saveat= my_dt change in the next release (not the one for this week: I don't want to mix too much in there), along with saveat_idxs for choosing components to save (https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/139), and the output kwarg change (https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/133). I think it's best to put these output changes all together so it's clear there's a change (and easier to do the depwarns).

ChrisRackauckas commented 7 years ago

Implemented