Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t_eval of CyRK behaves different to solve_ivp #45

Open
fvollmer opened this issue Jan 16, 2024 · 1 comment
Open

t_eval of CyRK behaves different to solve_ivp #45

fvollmer opened this issue Jan 16, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@fvollmer
Copy link

I just figured out that t_eval isn't behaving in the same way as scipy.integrate.solve_ivp:

solve_ivp solves the ode for the points in t_eval

Times at which to store the computed solution, must be sorted and lie within t_span. If None (default), use points selected by the solver.

CyRK interpolates the solution t_eval

Both solvers uses an adaptive time stepping protocol based on the recent error at each step. This results in a final non-uniform time domain of variable size. If the user would like the results at specific time steps then they can provide a np.ndarray array at the desired steps via t_eval. The solver will then interpolate the results to fit this array.

In my kind of special case CyRK is actually slower than solve_ivp.

@fvollmer fvollmer changed the title t_eval of CyRK behaves different to solve_ivp t_eval of CyRK behaves different to solve_ivp Jan 16, 2024
@jrenaud90
Copy link
Owner

jrenaud90 commented Jan 17, 2024

Hi, @fvollmer! Yes this is a missing feature of CyRK. It would not be too difficult to implement: solve_ivp uses a dense output which estimates the value of your problem inbetween solution steps (sorta like a faster, more accurate interpolation).

See here for the main implementation in SciPy and here for the RK specific implementation.

  • Update RK constants to include the versions used for dense output.
  • For nbrk: Create a python class that largely mimics the dense output class used in SciPy. Add this as an optional return to nbrk_ode.
  • For cyrk and CySolver: Create a cython class that does the same. For cyrk_ode this can be an additional output. For CySolver this class could be partially instantiated early on and then stored in the CySolver class as <instance_name>.dense and used like <instance_name>.dense(new_x) -> new_y.

I will mark this as a todo for a future update (PRs are welcome if you or others want to work on this!)

In the mean time feel free to share a simple working example of your code. I would be curious why the interpolation is so severely impacting performance. If you are not using the CySolver approach then that would be a way to greatly improve performance.

Cheers!

@jrenaud90 jrenaud90 added enhancement New feature or request good first issue Good for newcomers labels Jan 17, 2024
@jrenaud90 jrenaud90 added this to the 0.10.0 milestone Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants