patrick-kidger / patrick-kidger/diffrax
Endless loop after jax.jacrev(ode solver)(args)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.1k
- Forks
- 189
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 1
Description
Hello,
I have a simple (I think so) use-case with
def ode(t, M, args):
x,y,z,w = M
a,b,c,d,lam,mu,g,h,f,p,q = args
#
....
#
return jnp.array([d_x, d_y, d_z, d_w])
t0 = 0.
t1 = 10000
dt0 = 1e-2
# init value
x0 = 0.01
y0 = 1.0
z0 = 0.01
w0 = 1.0
M0 = jnp.array([x0,y0,z0,w0])
@jax.jit
def run(params):
# params = a,b,c,d,lam,mu,g,h,f,p,q
term = ODETerm(ode)
solver = Dopri5()
saveat = SaveAt(ts=jnp.linspace(t0, t1, 10000))
sols = diffeqsolve(terms=term, solver=solver, t0=t0, t1=t1,dt0=dt0,
y0=M0, args=params,
saveat=saveat, max_steps=100_000, throw=False)
return sols.ys[:,0] # x
# to get x(t) : that's ok
#tmp= run(params)
# to get dx/dparams THIS IS THE QUESTION
tmp= jax.jacrev(run)(params)
The diemnsion of tmp is (10000,11) ( number of time saved, number of params)
The problem is that something a simple as
tmp[:10,0]
to get the first 10 values of dx/a (a: first parameter) is starting a endless loop.
Any idea, where is my mistake?
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the shown example, comparing run(params) with jax.jacrev(run)(params) and then the tmp[:10,0] access. Inspect the interaction between jax.jacrev, the @jax.jit-wrapped run function, and diffeqsolve with Dopri5 and SaveAt; done means the Jacobian can be sliced without an endless loop.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100