patrick-kidger / patrick-kidger/diffrax

Diffrax activating the event on a rejected step

Open
#464 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi

I'm using diffrax 0.5.1 with events like that :

def condition(state, **kwargs):
"some condition"
...
return cdn
event = dx.DiscreteTerminatingEvent(cond_fn=condition)
solution = dx.diffeqsolve(
...
discrete_terminating_event=event 
)

and I noticed that diffrax is activating the terminating event even if the step has been rejected.
I suppose this is an undesirable behavior ?
Also as far as I tried I've been unable to find a way to get the knowledge of whether the step has been rejected or not in the event through "state" or "kwargs"

I'm sorry to be unable to give a minimal working exemple here because I don't now how to reproduce it by making an event trigger at the "right moment" that is at the moment a time step has just been rejected ! (and the code I'm using is too large to be considered a working exemple).
Though I'm pretty sure it happens as described since solutions.stats gives me 'num_accepted_steps': Array(0, dtype=int32), 'num_rejected_steps': Array(1, dtype=int32) and my event is triggered

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 with diffrax 0.5.1's DiscreteTerminatingEvent and the call to diffrax.diffeqsolve, then inspect solutions.stats alongside the condition callback's state and kwargs. Reproduce the rejected-step case if possible; done when the terminating event behavior is correct for rejected steps and the observed statistics remain consistent.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.