patrick-kidger / patrick-kidger/diffrax

diffeqsolve time parameters

Open
#316 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Wondering if this is desired behaviour:

The following fails because t0 and t1 only accept scalars. However, the code below used to work for older versions of jax/equinox/diffrax (not sure at which level this breaks):

from diffrax import diffeqsolve, Dopri5, ODETerm, SaveAt, PIDController

vector_field = lambda t, y, args: -y
term = ODETerm(vector_field)
solver = Dopri5()
saveat = SaveAt(ts=[0., 1., 2., 3.])
stepsize_controller = PIDController(rtol=1e-5, atol=1e-5)

ts = np.array([0.0, 3.0])
sol = diffeqsolve(term, solver, t0=ts[0], t1=ts[1], dt0=0.1, y0=1, saveat=saveat,
                  stepsize_controller=stepsize_controller)

Output:

_ValueError Traceback (most recent call last)
/Users/marcel.vangerven/Code/github/artcogsys/tutorials/simple_ode.ipynb Cell 3 line 1
7 stepsize_controller = PIDController(rtol=1e-5, atol=1e-5)
9 ts =np.array([0.0, 3.0])
---> 10 sol = diffeqsolve(term, solver, t0=ts[0], t1=ts[1], dt0=0.1, y0=1, saveat=saveat,
11 stepsize_controller=stepsize_controller)

File ~/opt/anaconda3/envs/research/lib/python3.10/site-packages/equinox/_jit.py:107, in _JitWrapper.call(self, *args, **kwargs)
106 def call(self, /, *args, **kwargs):
--> 107 return self._call(False, args, kwargs)

File ~/opt/anaconda3/envs/research/lib/python3.10/site-packages/equinox/_jit.py:103, in _JitWrapper._call(self, is_lower, args, kwargs)
101 out = self._cached(dynamic, static)
102 else:
--> 103 out = self._cached(dynamic, static)
104 return _postprocess(out)

[... skipping hidden 13 frame]

File ~/opt/anaconda3/envs/research/lib/python3.10/site-packages/diffrax/integrate.py:572, in diffeqsolve(terms, solver, t0, t1, dt0, y0, args, saveat, stepsize_controller, adjoint, discrete_terminating_event, max_steps, throw, solver_state, controller_state, made_jump)
570 with jax.ensure_compile_time_eval():
571 pred = (t1 - t0) * dt0 < 0
--> 572 dt0 = eqxi.error_if(dt0, pred, msg)
574 # Backward compatibility
...
--> 264 raise ValueError("No arrays to thread error on to.")
265 dynamic_x = _error(dynamic_x, pred, index, msgs=msgs, on_error=on_error)
266 return combine(dynamic_x, static_x)

ValueError: No arrays to thread error on to._

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

Reproduce the example at the diffeqsolve entry point and inspect diffrax/integrate.py around line 572, where the traceback reports the failure. Determine whether the reported scalar time-parameter case is supported, then document the expected behavior and verify it with a regression test if the issue is confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.