diffrax icon indicating copy to clipboard operation
diffrax copied to clipboard

Use values computed in ODETerms inside of SaveAt

Open Ricky5389 opened this issue 1 year ago • 4 comments

Hi, I would like to save some values that are computed inside of my ODETerms. Is it possible to have the term output other things than the differential equations parameters ? For example, if my term looks like this.

def terms(t,y,args):
    y_dot = y + args
    args_changed = args / y_dot
    return y_dot

Would it be possible to save args_changed and use it inside of SaveAt? (This is a dummy example but it captures the idea)

Ricky5389 avatar Aug 05 '24 14:08 Ricky5389

You can use SaveAt(fn=...). This is a separate function to the one used in the vector field.

In general we don't allow saving extra values from the vector field. The reason is that the times at which this is evaluated are frequently not the same as the times at which we output values.

patrick-kidger avatar Aug 05 '24 15:08 patrick-kidger

Is there a way to have access to y_dot inside of SaveAt ?

Ricky5389 avatar Aug 05 '24 16:08 Ricky5389

No. As above this is intended -- the values at which you save may not be the values at which you evaluate the vector field. So there's no way to map the values from one to the other.

patrick-kidger avatar Aug 05 '24 22:08 patrick-kidger

Is there a way to have access to y_dot inside of SaveAt ?

Maybe what you want to do is putting the option "steps=True" to sync the values at which you save to the values that you evaluate.

etienney avatar Aug 06 '24 08:08 etienney