Skip to content

Commit 5f5a121

Browse files
Merge pull request #192 from patrick-kidger/some-fixes2
Minor fixes
2 parents e9e2a69 + 32c514d commit 5f5a121

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

diffrax/step_size_controller/adaptive.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ def adapt_step_size(
465465
#
466466

467467
def _scale(_y0, _y1_candidate, _y_error):
468+
# In case the solver steps into a region for which the vector field isn't
469+
# defined.
470+
_nan = jnp.isnan(_y1_candidate).any()
471+
_y1_candidate = jnp.where(_nan, _y0, _y1_candidate)
468472
_y = jnp.maximum(jnp.abs(_y0), jnp.abs(_y1_candidate))
469473
return _y_error / (self.atol + _y * self.rtol)
470474

docs/further_details/faq.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Use `scan_stages=True`, e.g. `Tsit5(scan_stages=True)`. This is supported for all Runge--Kutta methods. This will substantially reduce compile time at the expense of a slightly slower run time.
66
- Set `dt0=<not None>`, e.g. `diffeqsolve(..., dt0=0.01)`. In contrast `dt0=None` will determine the initial step size automatically, but will increase compilation time.
7+
- Prefer `SaveAt(t0=True, t1=True)` over `SaveAt(ts=[t0, t1])`, if possible.
78
- It's an internal (subject-to-change) API, but you can also try adding `equinox.internal.noinline` to your vector field (s). eg. `ODETerm(noinline(...))`. This stages the vector field out into a separate compilation graph. This can greatly decrease compilation time whilst greatly increasing runtime.
89

910
### The solve is taking loads of steps / I'm getting NaN gradients / other weird behaviour.
@@ -24,7 +25,7 @@ diffeqsolve(
2425
)
2526
```
2627

27-
In practice, [`diffrax.Tsit5`][] is usually a better solver than [`diffrax.Dopri5`][]. And the default adjoint method ([`diffrax.DirectAdjoint`][]) is usually a better choice than [`diffrax.BacksolveAdjoint`][].
28+
In practice, [`diffrax.Tsit5`][] is usually a better solver than [`diffrax.Dopri5`][]. And the default adjoint method ([`diffrax.RecursiveCheckpointAdjoint`][]) is usually a better choice than [`diffrax.BacksolveAdjoint`][].
2829

2930
### I'm getting a `CustomVJPException`.
3031

0 commit comments

Comments
 (0)