patrick-kidger / patrick-kidger/diffrax

SaveAt dense and fn

Open
#301 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactor
Dominant language
Python
Stars
2.1k
Forks
189
Avg merge
3d 18h
Merged PRs (30d)
1

Description

When using dense=True in SaveAt and a custom fn, I was expected that the interpolation of the sol will respect the custom fn but it's not the case.

For now, it seems impossible to have an interpolation only on "statisctics" which have be saved with a custom fn without saved all the info.

    def f(t, x, args):
        y = x
        return y

    solver = diffrax.Kvaerno5()
    stepsize_controller = diffrax.PIDController(rtol=1e-8, atol=1e-8)  # rtol=1e-8, atol=1e-8


    t0 = 0.
    t1 = 10
    y0 = jnp.array([3.0,2.0,10.0])
    dt0 = 0.0002

    sol = diffrax.diffeqsolve(
        diffrax.ODETerm(f),
        solver,
        t0,
        t1,
        dt0,
        y0,
        saveat=diffrax.SaveAt(dense=True,steps=True,fn=lambda t,y,args: y[:2]),
        stepsize_controller=stepsize_controller,
        max_steps=100000,
    )

    print(sol.interpolation.infos) # dim 3 ko
    print(sol.ys) # -> dim 2 ok

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided diffrax.diffeqsolve example with SaveAt(dense=True, steps=True, fn=...) and compare sol.interpolation.infos with sol.ys. Trace how SaveAt's custom fn is applied to saved values versus dense interpolation; done means dense interpolation respects the custom function without retaining the full state.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.