patrick-kidger / patrick-kidger/diffrax

Steady-state event occurs immediately if state with large value constant

Open
#448 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi Patrick,

I noticed that steady state events occur much earlier if a state with a large value is constant. This behavior occurs irrespective of the optx.norm specified, even though I would assume it not to occur when using optx.max_norm.
(So it looks like an additional concern, even if it is related to #131).

Here is some code that reproduces this:

import jax.numpy as jnp
import diffrax as dfx
import optimistix as optx

def dydt(t, y, k):
    return -k * y

# Scenario A: one state constant at high value
k0_a = jnp.array([0., 1.]) 
y0_a = jnp.array([1e05, 5.])

# Scenario B: only dynamic state, rate and value identical
k0_b = jnp.array([1.])
y0_b = jnp.array([5.])

# Steady state reached earlier in scenario A, holds for all norms
norms = [optx.max_norm, optx.two_norm, optx.rms_norm]
for norm in norms:
    steady_state = dfx.SteadyStateEvent(atol=1e-06, rtol=1e-03, norm=norm)

    # Scenario A
    solution_a = dfx.diffeqsolve(
        dfx.ODETerm(dydt),
        dfx.Tsit5(),
        0, 100., 0.1, y0_a, args=k0_a,
        discrete_terminating_event=steady_state,
    )
    assert solution_a.result == dfx.RESULTS.discrete_terminating_event_occurred

    # Scenario B: steady state reached much later
    solution_b = dfx.diffeqsolve(
        dfx.ODETerm(dydt),
        dfx.Tsit5(),
        0, 100., 0.1, y0_b, args=k0_b,
        discrete_terminating_event=steady_state,
    )
    assert solution_b.result == dfx.RESULTS.discrete_terminating_event_occurred

    # Compare the times
    print(solution_a.ts, solution_b.ts)

Changing the tolerances will change the time points at which the event occurs, but the system will still reach a (spurious) steady state in scenario A.

I use these in practice to find steady-states of models representing biological systems, where state values can be wildly different, but "small" states can still exert great influence on other states.
(I have two large constant states because I set their growth-rates to zero while trying to get rid of parameter-dependent transients on the small states.)

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

Start by running the supplied reproduction with diffrax.SteadyStateEvent, diffeqsolve, and the listed optimistix norms. Read the steady-state event handling and compare the event times for the two scenarios; done means large constant states no longer cause a premature event across the tested norms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.