You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
then we have two "terms": a drift and a diffusion. Each of these terms has two parts: a *vector field* ($f$ or $g$) and a *control* ($\mathrm{d}t$ or $\mathrm{d}w(t)$). There is also an implicit assumption about how the vector field and control interact: $f$ and $\mathrm{d}t$ interact as a vector-scalar product. $g$ and $\mathrm{d}w(t)$ interact as a matrix-vector product. (This interaction is always linear.)
7
+
then we have two "terms": a drift and a diffusion. Each of these terms has two parts: a *vector field* ($f$ or $g$) and a *control* ($\mathrm{d}t$ or $\mathrm{d}w(t)$). In addition (often not represented in mathematical notation), there is also a choice of how the vector field and control interact: $f$ and $\mathrm{d}t$ interact as a vector-scalar product. $g$ and $\mathrm{d}w(t)$ interact as a matrix-vector product. (In general this interaction is always bilinear.)
8
8
9
9
"Terms" are thus the building blocks of differential equations.
10
10
11
11
!!! example
12
12
13
13
Consider the ODE $\frac{\mathrm{d}{y}}{\mathrm{d}t} = f(t, y(t))$. Then this has vector field $f$, control $\mathrm{d}t$, and their interaction is a vector-scalar product. This can be described as a single [`diffrax.ODETerm`][].
14
14
15
-
If multiple terms affect the same evolving state, then they should be grouped into a single [`diffrax.MultiTerm`][].
15
+
#### Adding multiple terms, such as SDEs
16
+
17
+
We can add multiple terms together by grouping them into a single [`diffrax.MultiTerm`][].
16
18
17
19
!!! example
18
20
19
-
An SDE would have its drift described by [`diffrax.ODETerm`][] and the diffusion described by a [`diffrax.ControlTerm`][]. As these affect the same evolving state variable, they should be passed to the solver as `MultiTerm(ODETerm(...), ControlTerm(...))`.
21
+
The SDE above would have its drift described by [`diffrax.ODETerm`][] and the diffusion described by a [`diffrax.ControlTerm`][]. As these affect the same evolving state variable, they should be passed to the solver as `MultiTerm(ODETerm(...), ControlTerm(...))`.
22
+
23
+
#### Independent terms, such as Hamiltonian systems
20
24
21
-
If terms affect different pieces of the state, then they should be placed in some PyTree structure. (The exact structure will depend on what the solver accepts.)
25
+
If terms affect different pieces of the state, then they should be placed in some PyTree structure.
22
26
23
27
!!! example
24
28
@@ -28,7 +32,31 @@ If terms affect different pieces of the state, then they should be placed in som
28
32
29
33
These would be passed to the solver as the 2-tuple of `(ODETerm(...), ODETerm(...))`.
30
34
31
-
Each solver is capable of handling certain classes of problems, as described by their `solver.term_structure`.
35
+
#### What each solver accepts
36
+
37
+
Each solver in Diffrax will specify what kinds of problems it can handle, as described by their `.term_structure` attribute. Not all solvers are able to handle all problems!
38
+
39
+
Some example term structures include:
40
+
41
+
1.`solver.term_structure = AbstractTerm`
42
+
43
+
In this case the solver can handle a simple ODE as descibed above: `ODETerm` is a subclass of `AbstractTerm`.
44
+
45
+
It can also handle SDEs: `MultiTerm(ODETerm(...), ControlTerm(...))` includes everything wrapped into a single term (the `MultiTerm`), and at that point this defines an interface the solver knows how to handle.
In this case the solver is used to solve ODEs like the Hamiltonian system described above: we have a PyTree of terms, each of which is treated individually.
58
+
59
+
---
32
60
33
61
??? abstract "`diffrax.AbstractTerm`"
34
62
@@ -41,10 +69,12 @@ Each solver is capable of handling certain classes of problems, as described by
41
69
- vf_prod
42
70
- is_vf_expensive
43
71
44
-
---
72
+
??? note "Defining your own term types"
73
+
74
+
For advanced users: you can create your own terms if appropriate. For example if your diffusion is matrix, itself computed as a matrix-matrix product, then you may wish to define a custom term and specify its [`diffrax.AbstractTerm.vf_prod`][] method. By overriding this method you could express the contraction of the vector field - control as a matrix-(matix-vector) product, which is more efficient than the default (matrix-matrix)-vector product.
45
75
46
-
!!! note
47
-
You can create your own terms if appropriate: e.g. if a diffusion matrix has some particular structure, and you want to use a specialised more efficient matrix-vector product algorithm in `prod`.
0 commit comments