Skip to content

Merge JumpProblem kwargs once when init-ing with an SDE/RODE algorithm - #4707

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-4439-jump-callback-twice
Oct 3, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-4439-jump-callback-twice

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

init(jprob, EM()) on a JumpProblem that wraps an SDEProblem merged jprob.kwargs twice, so a callback stored in the JumpProblem fired twice. The first merge happens in DiffEqBase's init_call. The second happens because JumpProcesses' JumpProcessesOrdinaryDiffEqCoreExt.__init(::JumpProblem, ::Union{StochasticDiffEqAlgorithm, StochasticDiffEqRODEAlgorithm}) won dispatch and merged again. StochasticDiffEqCore now defines __init(::JumpProblem, ::StochasticDiffEqAlgorithm) and __init(::JumpProblem, ::StochasticDiffEqRODEAlgorithm), which are more specific than that method and call _sde_init directly. That is the path solve already takes. They also cover the TauLeaping-style jump algorithms that the method this replaces handled.

The solve path reported in the issue already fires once on master: #4409 made __solve(::JumpProblem, ...) call _sde_init directly (StochasticDiffEqCore 2.2.1; the issue was filed against 2.2.0). Reproduced on master with the issue's script: solve(...) gives fire_count[] = 1, init(...) |> solve! gives fire_count[] = 2. The regression test extends the existing callback from JumpProblem.kwargs fires exactly once testset to the init path.

Failing before (fix stashed)

callback from JumpProblem.kwargs fires exactly once: Test Failed at .../lib/StochasticDiffEq/test/jump_kwarg_forwarding_tests.jl:76
  Expression: fire_count[] == 1
   Evaluated: 2 == 1
JumpProblem kwarg forwarding                                     |   30     1     31  1m01.7s

Passing after

Test Summary:                | Pass  Total   Time
JumpProblem kwarg forwarding |   31     31  57.7s

Test groups run locally (Julia 1.12)

  • GROUP=Interface1 in lib/StochasticDiffEq (contains the jump kwarg, rng/integrator init and tstops tests): Testing StochasticDiffEq tests passed
  • GROUP=Interface2 in lib/StochasticDiffEq (contains tau_leaping.jl, which inits a JumpProblem with TauLeaping):
    Basic Tau Leaping Tests |   18     18  17m09.0s
    ...
    Testing StochasticDiffEq tests passed
    
  • GROUP=QA in lib/StochasticDiffEqCore (Aqua incl. method ambiguities, JET): QA (Aqua and JET) | 21 21 and Testing StochasticDiffEqCore tests passed
  • Runic and typos on both changed files: clean.

Not verified

  • Other StochasticDiffEq groups (Interface3, convergence, Multithreaded, which has multithreaded_jump_test.jl), Julia LTS/pre, and downstream (ModelingToolkitBase's SDEs + jumps with symbolic tstops test from the issue).
  • Older JumpProcesses versions within compat. If a version lacks the extension method, StochasticDiffEqCore's new methods are still more specific than JumpProcesses' generic __init(::JumpProblem, ::AbstractDEAlgorithm), so behaviour is the same.

Push back on

  • init with an SDE/RODE algorithm now goes through _sde_init instead of JumpProcesses' __jump_init, so init and solve share one path. This deliberately overrides the JumpProcesses extension method by being more specific. The cleaner long-term fix may be to delete those StochasticDiffEqAlgorithm/StochasticDiffEqRODEAlgorithm methods from JumpProcessesOrdinaryDiffEqCoreExt. That's a JumpProcesses change and isn't part of this PR. The ODE methods in that extension likely double-merge on init the same way (not checked here).
  • No StochasticDiffEqCore version bump; releases here are bumped separately.

Fixes #4439

Please ignore this draft until reviewed by @ChrisRackauckas.

Risk assessment

pending independent review

🤖 Generated with Claude Code 2.1.285 (model: claude-opus-5-5), transcript /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-OrdinaryDiffEq.jl-4439/log.txt on amdci2.julia.csail.mit.edu

Risk assessment

  • Risk: low
  • Blast radius: Only code that calls init (not solve) on a JumpProblem with a StochasticDiffEq SDE/RODE algorithm, including the TauLeaping-style StochasticDiffEqJumpAlgorithm/StochasticDiffEqJumpAdaptiveAlgorithm. Both are subtypes of StochasticDiffEqAlgorithm in OrdinaryDiffEqCore/src/algorithms.jl, so the removed __init method is fully replaced. Downstream users of that path include MTK/Catalyst jump-diffusion code that uses the integrator interface. solve and ODE-algorithm jump paths are unchanged.
  • Evidence: On head e0b5c08: 166 pass, 4 fail, 1 skipping (the sublibrary-ci matrix template row). The four failures are SciMLSensitivity.jl/Core1/1 / Downstream Tests - Core1, downgrade-sublibraries / test (lib/DiffEqBase), downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation) and tests / GPU (julia 1, self-hosted Linux X64 gpu). All four also fail on the base commit 7393799 and on the two master commits before it (14f664a, cc57721), so they are pre-existing, not regressions. Every relevant suite passes on head: StochasticDiffEq Interface1/2/3 on Julia 1, lts and pre; Multithreaded; all convergence groups; QA; StaticAnalysis; StochasticDiffEqCore Core on 1/lts/pre plus QA, so Aqua found no new ambiguities; StochasticDiffEqLeaping; the downgrade jobs for every StochasticDiffEq* package; and the MTK downstream groups. No tests were weakened. One assertion was added, and the description shows it failing before the fix (2 == 1) and passing after.
  • Independent review: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence: the change is a 9-line dispatch tweak that sends init through the same _sde_init path solve already uses (since Fix TauLeaping JumpProblem initialization #4409), the new methods are strictly more specific than the JumpProcesses extension method they override, and CI shows no regressions.
  • Merge: needs human review. Findings:
    1. The PR is a draft that says "ignore until reviewed by @ChrisRackauckas".
    2. The description doesn't mention three other behavior changes on the init path, each of which brings it in line with solve:
      • Callback order flips. CallbackSet(callback, jump_callback) replaces JumpProcesses' CallbackSet(jump_callback, callback).
      • seed now seeds the SDE noise as well; before, __jump_init swallowed it. The jump RNG is also reseeded on every init, even without a seed.
      • JumpProcesses' alias_jump kwarg is no longer honored on this path; the alias = SDEAliasSpecifier(alias_jumps=…) option is used instead.
    3. Which method wins depends on dispatch specificity across packages, overriding a method from JumpProcesses' JumpProcessesOrdinaryDiffEqCoreExt. The description discloses this. It uses no new non-public internals; _sde_init belongs to this package, and JumpProcesses.resetted_jump_problem/reset_jump_problem! were already called. Technically it is type piracy, since neither JumpProblem nor StochasticDiffEqAlgorithm is owned by StochasticDiffEqCore, but the method it replaces did the same.
    4. The existing Union{AbstractRODEProblem, JumpProblem} __init method can no longer be reached for JumpProblem.
    5. Comment lines are 4 of 14 added lines (about 29%).
    6. There is no version bump (disclosed). It's a patch-level fix with no public API change.

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Claude Code 2.1.285 (Mac) fleet-master head, model claude-opus-5-5[1m]
Conversation: local session 3c311569-dda6-4687-bc9f-65febb212c33 (~/.claude/projects/-Users-chrisrackauckas-sandbox-master/3c311569-dda6-4687-bc9f-65febb212c33.jsonl)

`init(jprob::JumpProblem, EM())` merged `jprob.kwargs` twice: once in
DiffEqBase's `init_call`, and again in JumpProcesses'
`JumpProcessesOrdinaryDiffEqCoreExt.__init(::JumpProblem,
::Union{StochasticDiffEqAlgorithm, StochasticDiffEqRODEAlgorithm})`, which
won dispatch over StochasticDiffEqCore's `__init`. A callback stored in the
JumpProblem therefore fired twice. StochasticDiffEqCore now defines
`__init(::JumpProblem, ::StochasticDiffEqAlgorithm)` and
`__init(::JumpProblem, ::StochasticDiffEqRODEAlgorithm)`, which are more
specific than the extension method and go straight to `_sde_init`, the same
path `solve` uses.

Fixes SciML#4439

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Agent-Harness: Claude Code 2.1.285
Agent-Model: claude-opus-5-5
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-OrdinaryDiffEq.jl-4439/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 3, 2026 11:51
@ChrisRackauckas
ChrisRackauckas merged commit 9ff3389 into SciML:master Oct 3, 2026
169 of 173 checks passed
ChrisRackauckas referenced this pull request Oct 13, 2026
…inaryDiffEqBDF, OrdinaryDiffEqExplicitRK, OrdinaryDiffEqFIRK, OrdinaryDiffEqFeagin, OrdinaryDiffEqHighOrderRK, OrdinaryDiffEqPDIRK, OrdinaryDiffEqRKN, OrdinaryDiffEqSDIRK, StochasticDiffEqHighOrder, StochasticDiffEqLowOrder, and StochasticDiffEqMilstein for release (#4871)

Agent-Harness: Devin CLI 3000.11.3
Agent-Model: Fusion (Claude Opus 5.5 Medium + SWE-2 Medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/flash-hour.json

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ChrisRackauckas pushed a commit that referenced this pull request Oct 25, 2026
…#4914)

* Narrow StochasticDiffEqCore's union `__init` to RODE problems

A `JumpProblem` with an SDE or RODE algorithm already dispatches to the
per-algorithm `__init` methods added in #4707, which are more specific
than the union method, so no call changes method. Under JumpProcesses 10
the union method is ambiguous, at signature level, with JumpProcesses'
`__init(::JumpProblem, ...)` extension method, whose algorithm union now
also covers ODE and DAE algorithms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Allow JumpProcesses 10 in StochasticDiffEqCore, Implicit, and Leaping

Widen the JumpProcesses compat to "9.26.0, 10" and bump the patch
versions (Core 2.2.5, Implicit 2.2.2, Leaping 2.1.1). No source changes
are needed: Core's only JumpProcesses calls, `resetted_jump_problem` and
`reset_jump_problem!`, are kept by JumpProcesses 10 for StochasticDiffEq
compatibility (as a `deepcopy` and a no-op, since jumps now draw from the
integrator's RNG), and JumpProcesses 9 behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StochasticDiffEq: JumpProblem callback stored in kwargs fires twice

2 participants