patrick-kidger / patrick-kidger/diffrax
example on solving system of ODEs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.1k
- Forks
- 189
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 1
Description
Hi, I am absolutely new to diffrax and trying to get the basics of it (great work by the way).
I am a bit confused concerning the syntax for solving systems of ODEs. In the documentation discussing Terms you mention you can solve an Hamiltonian system (coupled ODEs) as a 2-tuple of diffrax.ODETerm.
Consider as a minimal example a simple falling object:
$$\dot{y}(t) = v(t) \quad \dot{v}(t) = -g$$
with g the gravitational constant. What is the correct way of expressing this? I tried the most likely wrong form:
def f1(t,y,args):
return v
def f2(t,v,args):
return -g
term1 = ODETerm(f1)
term2 = ODETerm(f2)
solver = SemiImplicitEuler()
solution = diffeqsolve(terms= (term1, term2), solver= solver, t0=0., t1=1. ,dt0=0.02, y0=(0., 5.) )
And I get: TypeError: unsupported operand type(s) for *: 'DynamicJaxprTracer' and 'function'
That means I am not providing the input in the right form. Could you provide an example on how to implement this correctly ?
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
Start with the linked Terms documentation and the ODETerm/SemiImplicitEuler entry points; first run the minimal falling-object example from the issue to reproduce the tracer error. Done means the documentation contains a correct, runnable coupled-ODE example and explains the expected state and term structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100