patrick-kidger / patrick-kidger/diffrax

Allowing for state change after each step

Open
#277 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

In some settings we want to reset the state of the system after each solver step depending on the state. E.g. when performing a voltage reset in a leaky integrate-and-fire model. This seems unsupported at the moment. The most logical route seems to be to add support for an AbstractStateChangingEvent (similar to DiscreteTerminatingEvent) which changes the state but does not terminate. Would it be possible to add this?

The alternative used now is to overload the solver as in the example below but this is very clunky:

class CustomEuler(Euler):
"""
Custom solver. Needed to implement reset of the membrane potential and recording of spikes for the LIF model
"""

Vthresh: float
EL: float

def step(
    self,
    terms: AbstractTerm,
    t0: Scalar,
    t1: Scalar,
    y0: PyTree,
    args: PyTree,
    solver_state: _SolverState,
    made_jump: Bool,
) -> Tuple[PyTree, _ErrorEstimate, DenseInfo, _SolverState, RESULTS]:
   
    y1, _, dense_info, _, RESULTS.successful = super().step(terms, t0, t1, y0, args, solver_state, made_jump)

    V = y1[0]

    # membrane potential reset
    spikes = jnp.float32(V > self.Vthresh)
    Vnew = (1.0 - spikes) * V + spikes * self.EL

    return (Vnew, spikes), None, dense_info, None, RESULTS.successful

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 reading the Euler.step entry point and the existing DiscreteTerminatingEvent handling. Trace how AbstractTerm, solver state, and event results move through a step. Done means supporting a state-changing event that resets values, such as the membrane potential, without terminating the solve; the issue does not name tests or files.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.