diffsol_jax¶
ODEProblem ¶
ODEProblem(rhs: Callable, state: int | PyTree, params: int | PyTree = None, *, out: Callable | None = None, mass: Callable | None = None, algebraic: int | Sequence[bool] | PyTree | None = None, root: Callable | None = None, reset: Callable | None = None, solver: Solver = 'bdf', linear_solver: LinearSolver = 'default', matrix_type: MatrixType = 'nalgebra_dense', max_checkpoints: int = 8, dtype: DTypeLike | None = None)
An ODE, or a semi-explicit index-1 DAE, together with the diffsol solver for it.
The state and the parameters are pytrees, declared by state= and params=. Each is
either an int n, meaning one flat array of shape (n,), or a template pytree whose
float-array leaves give the shapes and dtypes.
Building a problem builds the equations and the diffsol solver, so build it once and
reuse it across solves. To solve the same equations with different options, use
ODEProblem.replace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rhs
|
Callable
|
the vector field, |
required |
state
|
int | PyTree
|
the layout of the state: an int, or a template whose every leaf is a float array. |
required |
params
|
int | PyTree
|
the layout of the parameters: an int, |
None
|
out
|
Callable | None
|
|
None
|
mass
|
Callable | None
|
the mass matrix action |
None
|
algebraic
|
int | Sequence[bool] | PyTree | None
|
a |
None
|
root
|
Callable | None
|
the event condition |
None
|
reset
|
Callable | None
|
the state jump at an event, |
None
|
solver
|
Solver
|
the diffsol solver: |
'bdf'
|
linear_solver
|
LinearSolver
|
|
'default'
|
matrix_type
|
MatrixType
|
|
'nalgebra_dense'
|
max_checkpoints
|
int
|
how many adjoint checkpoints to keep alive at once. |
8
|
dtype
|
DTypeLike | None
|
the scalar type the solver works in: |
None
|
Source code in python/diffsol_jax/_problem.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
callback_stats ¶
The callback counters (ncalls, nstaged, nviews) for the given batch size.
clear_checkpoints ¶
num_checkpoints ¶
num_recomputes ¶
How many backward solves had to re-run their forward solve, because the checkpoint had been evicted.
replace ¶
Returns a new problem with the given constructor arguments replaced.
For example, problem.replace(solver="tsit45"). The new problem has its own
diffsol solver; the original is unchanged.
Source code in python/diffsol_jax/_problem.py
solve ¶
solve(problem: ODEProblem, y0: PyTree, params: PyTree, t0: float, t1: float, *, saveat: ArrayLike | None = None, rtol: float | None = None, atol: float | None = None, max_steps: int = 10000, ad: Ad | None = None) -> PyTree
Solves problem from the state y0 at t0 to t1.
Works under jax.jit, jax.grad, jax.jacfwd and jax.vmap, and is differentiable
with respect to both y0 and params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
ODEProblem
|
an |
required |
y0
|
PyTree
|
the state at |
required |
params
|
PyTree
|
the parameter values, in the problem's |
required |
t0
|
float
|
the initial time. |
required |
t1
|
float
|
the final time. |
required |
saveat
|
ArrayLike | None
|
the times to return the solution at: shape |
None
|
rtol
|
float | None
|
the relative tolerance of the solver. Defaults to |
None
|
atol
|
float | None
|
the absolute tolerance of the solver, with the same default as |
None
|
max_steps
|
int
|
the most steps the solver may take to reach the last time it returns. |
10000
|
ad
|
Ad | None
|
how to take the reverse-mode derivative: |
None
|
Returns:
| Type | Description |
|---|---|
PyTree
|
|
PyTree
|
|