Skip to content

Add isolated_copy, a JumpProblem with its own jump state - #714

Merged
isaacsas merged 4 commits into
SciML:masterfrom
isaacsas:isolated-copy
Nov 11, 2026
Merged

isaacsas merged 4 commits into
SciML:masterfrom
isaacsas:isolated-copy

Conversation

@isaacsas

@isaacsas isaacsas commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Adds isolated_copy(jprob), which returns a JumpProblem that can be solved concurrently with jprob, or used for an integrator alive at the same time as one of its, without copying the wrapped problem or the jumps (#287). It replaces #711; thanks to @kaandocal for the report and for the tests, which are adapted here.

What is copied and what is shared

  • New: the jump aggregator, with copies of its working data (current rates, priority queue or table, …), and the jump callbacks rebuilt around it: DiscreteCallback(new_agg), and for VR_Direct/VR_DirectFW a new cache through build_variable_integcallback. VR_FRM's callbacks are reused, since their state lives in the integrator's u.jump_u.
  • Shared: the wrapped problem (f, the symbolic system, u0, p, tspan), the jumps with their functions and FunctionWrappers, the JumpDependencies, and the stored callbacks and tstops. No closure or wrapper is copied.

Each type that holds jump state (the aggregators, the spatial rate tables, the priority tables, the VR_Direct cache) declares next to its definition the fields that hold definitions, shared_fields, which joins the methods a new aggregator defines. A generated function rebuilds the object through its default constructor, sharing those fields and copying all the others, so a field nobody classified is copied, or makes isolated_copy throw with an explanation if its type can't be copied, but is never shared by mistake. A test checks that every aggregator and hopping-rate type declares its shared fields.

The copy starts from the source's working data, which every solver re-initializes at init; only SortingDirect's learned search order carries over. A copy may be taken between step! calls of a live integrator (the agent-based-model case), but not while another thread is solving the source.

StochasticDiffEq

resetted_jump_problem, which StochasticDiffEq calls for alias_jumps = false (the default off thread 1), now returns an isolated_copy instead of a deepcopy, so that copy becomes cheap with no downstream change.

Docs

The JumpProblem and remake docstrings, the API page, FAQ, jump types page, migration guide and the ensembles tutorial now recommend isolated_copy (with a short agent-based-model pattern in the tutorial). deepcopy stays documented as the fully isolating option, with its limits for jumps stored in FunctionWrappers: the copy may call the original's rate and affect functions and needs the original kept alive. The upstream fix for that is JuliaLang/FunctionWrappers.jl#39. The isolated_copy docstring also lists what a copy doesn't isolate: p and u0, state captured by user functions, and a noise process passed to an SDEProblem, which StochasticDiffEq writes back into prob.noise after each solve.

Timing

Median times on Julia 1.13 for one isolated_copy, one deepcopy and one solve over tspan = (0, 1) (about 10 jumps per reaction channel, save_positions = (false, false)). These problems are built without an aggregator, so each row uses the aggregator that automatic selection picks:

Problem Jumps Aggregator chosen isolated_copy deepcopy Solve
mass-action ring 10 Direct 0.06 µs 7.1 µs 5.3 µs
mass-action ring 50 RSSA 0.14 µs 37 µs 26 µs
mass-action ring 100 RSSACR 0.28 µs 78 µs 46 µs
mass-action ring 1,000 RSSACR 1.4 µs 0.70 ms 0.60 ms
mass-action ring 10,000 RSSACR 8.0 µs 10.1 ms 7.7 ms
ConstantRateJump ring, dependency graph only 10 Direct 0.06 µs 3.0 µs 4.9 µs
ConstantRateJump ring, dependency graph only 100 SortingDirect 0.10 µs 55 µs 113 µs
ConstantRateJump ring, dependency graph only 1,000 DirectCR 0.39 µs 0.56 ms 1.2 ms
ConstantRateJump ring, dependency graph only 10,000 DirectCR 1.7 µs 6.1 ms 12.0 ms
Catalyst, Hill rates 20 RSSA 0.11 µs 0.61 ms 3.0 µs
Catalyst, Hill rates 200 RSSACR 0.64 µs 4.2 ms 45 µs
Catalyst, Hill rates 2,000 RSSACR 5.2 µs 47.7 ms 1.9 ms

For these aggregators a copy costs at most 4% of such a solve, while deepcopy costs 50 to 9,000 times as much as a copy (5,500 to 9,000 times for the Catalyst problems, where it also copies the symbolic system). Across all 12 SSA aggregators, a copy costs at most 11% of such a solve (CCNRM at 10 jumps) and at most 3% from 100 jumps up.

All 12 SSA aggregators

Each aggregator given explicitly, on the mass-action ring for 10 to 10,000 jumps and, for some, on the Catalyst problem (2N jumps: N Hill-rate ConstantRateJumps and N mass-action decays). The copy column also gives the memory allocated.

Problem Jumps Aggregator isolated_copy deepcopy Solve Copy / solve
mass-action ring 10 Direct 0.06 µs, 0.7 KiB 7.1 µs 5.3 µs 0.011
mass-action ring 100 Direct 0.1 µs, 2.2 KiB 39 µs 152 µs 0.00066
mass-action ring 1,000 Direct 0.55 µs, 16.5 KiB 378 µs 15.4 ms <0.0001
mass-action ring 10,000 Direct 3.2 µs, 160 KiB 4.2 ms 1.4 s <0.0001
mass-action ring 10 RSSA 0.09 µs, 1.2 KiB 12.5 µs 2.9 µs 0.031
mass-action ring 100 RSSA 0.21 µs, 5 KiB 75.5 µs 97.1 µs 0.0022
mass-action ring 1,000 RSSA 1.3 µs, 40.8 KiB 685 µs 6.3 ms 0.0002
mass-action ring 10,000 RSSA 7.9 µs, 401 KiB 10 ms 580 ms <0.0001
mass-action ring 10 RSSACR 0.14 µs, 1.7 KiB 15.4 µs 4 µs 0.035
mass-action ring 100 RSSACR 0.28 µs, 5.5 KiB 79.3 µs 46.1 µs 0.0061
mass-action ring 1,000 RSSACR 1.3 µs, 41.3 KiB 712 µs 608 µs 0.0022
mass-action ring 10,000 RSSACR 8 µs, 401 KiB 10.5 ms 7.7 ms 0.001
mass-action ring 10 SortingDirect 0.07 µs, 0.8 KiB 10 µs 3.5 µs 0.02
mass-action ring 100 SortingDirect 0.14 µs, 3.1 KiB 60.3 µs 78.7 µs 0.0018
mass-action ring 1,000 SortingDirect 0.82 µs, 24.6 KiB 518 µs 4.7 ms 0.00018
mass-action ring 10,000 SortingDirect 4.8 µs, 241 KiB 7.4 ms 417 ms <0.0001
mass-action ring 10 DirectCR 0.11 µs, 1.2 KiB 12 µs 7.2 µs 0.015
mass-action ring 100 DirectCR 0.16 µs, 2.8 KiB 61.7 µs 65.5 µs 0.0024
mass-action ring 1,000 DirectCR 0.63 µs, 17.1 KiB 545 µs 789 µs 0.0008
mass-action ring 10,000 DirectCR 3.3 µs, 161 KiB 7.5 ms 8.7 ms 0.00038
mass-action ring 10 Coevolve 0.32 µs, 1.2 KiB 11.2 µs 4.6 µs 0.07
mass-action ring 100 Coevolve 0.36 µs, 2.8 KiB 55.9 µs 59.5 µs 0.0061
mass-action ring 1,000 Coevolve 0.81 µs, 17.1 KiB 545 µs 830 µs 0.00098
mass-action ring 10,000 Coevolve 3.5 µs, 161 KiB 7.4 ms 10.9 ms 0.00032
mass-action ring 10 DirectFW 0.06 µs, 0.7 KiB 7.6 µs 5.5 µs 0.011
mass-action ring 100 DirectFW 0.1 µs, 2.2 KiB 37.1 µs 153 µs 0.00065
mass-action ring 1,000 DirectFW 0.58 µs, 16.5 KiB 383 µs 13 ms <0.0001
mass-action ring 10,000 DirectFW 3.2 µs, 160 KiB 4.4 ms 1.3 s <0.0001
mass-action ring 10 FRM 0.06 µs, 0.7 KiB 7.2 µs 5.1 µs 0.012
mass-action ring 100 FRM 0.1 µs, 2.2 KiB 37.8 µs 381 µs 0.00026
mass-action ring 1,000 FRM 0.57 µs, 16.5 KiB 351 µs 41.3 ms <0.0001
mass-action ring 10,000 FRM 3.2 µs, 160 KiB 4.2 ms 4.1 s <0.0001
mass-action ring 10 FRMFW 0.06 µs, 0.7 KiB 7.6 µs 5.2 µs 0.012
mass-action ring 100 FRMFW 0.1 µs, 2.2 KiB 37.8 µs 385 µs 0.00026
mass-action ring 1,000 FRMFW 0.59 µs, 16.5 KiB 391 µs 40.5 ms <0.0001
mass-action ring 10,000 FRMFW 3.2 µs, 160 KiB 4.2 ms 4 s <0.0001
mass-action ring 10 NRM 0.34 µs, 1.2 KiB 10.6 µs 3.6 µs 0.094
mass-action ring 100 NRM 0.36 µs, 2.7 KiB 61.5 µs 49.6 µs 0.0073
mass-action ring 1,000 NRM 0.81 µs, 17 KiB 536 µs 735 µs 0.0011
mass-action ring 10,000 NRM 3.5 µs, 161 KiB 7.7 ms 10 ms 0.00035
mass-action ring 10 RDirect 0.06 µs, 0.7 KiB 10.5 µs 3.6 µs 0.017
mass-action ring 100 RDirect 0.1 µs, 2.2 KiB 59.4 µs 32 µs 0.0031
mass-action ring 1,000 RDirect 0.58 µs, 16.5 KiB 524 µs 410 µs 0.0014
mass-action ring 10,000 RDirect 3.2 µs, 160 KiB 7.5 ms 5.2 ms 0.00063
mass-action ring 10 CCNRM 0.5 µs, 5.8 KiB 29.3 µs 4.5 µs 0.11
mass-action ring 100 CCNRM 1.5 µs, 19.8 KiB 112 µs 54.7 µs 0.027
mass-action ring 1,000 CCNRM 6 µs, 93.3 KiB 719 µs 670 µs 0.009
mass-action ring 10,000 CCNRM 23.4 µs, 622 KiB 9 ms 8.6 ms 0.0027
Catalyst, Hill rates 20 Direct 0.09 µs, 1.2 KiB 569 µs 4.9 µs 0.018
Catalyst, Hill rates 20 RSSACR 0.18 µs, 2.1 KiB 591 µs 3.4 µs 0.053
Catalyst, Hill rates 200 RSSACR 0.59 µs, 9.5 KiB 4.1 ms 45.2 µs 0.013
Catalyst, Hill rates 2,000 RSSACR 5.1 µs, 81 KiB 54.6 ms 1.9 ms 0.0027
Catalyst, Hill rates 20 SortingDirect 0.09 µs, 1.3 KiB 586 µs 4.6 µs 0.02
Catalyst, Hill rates 200 SortingDirect 0.47 µs, 7.1 KiB 4 ms 78.8 µs 0.006
Catalyst, Hill rates 2,000 SortingDirect 4.4 µs, 64.2 KiB 44.9 ms 5.2 ms 0.00085
Catalyst, Hill rates 20 DirectFW 0.08 µs, 1 KiB 583 µs 10 µs 0.008
Catalyst, Hill rates 200 DirectFW 0.38 µs, 5.4 KiB 4 ms 1.2 ms 0.00031
Catalyst, Hill rates 2,000 DirectFW 3.5 µs, 48.1 KiB 47.8 ms 838 ms <0.0001
Catalyst, Hill rates 20 NRM 0.33 µs, 1.5 KiB 588 µs 5 µs 0.066
Catalyst, Hill rates 200 NRM 0.65 µs, 5.9 KiB 4 ms 51.4 µs 0.013
Catalyst, Hill rates 2,000 NRM 4 µs, 48.6 KiB 43.9 ms 2 ms 0.002

Tests

New test/isolated_copy.jl, also in the ThreadSafety group: shared and copied fields for every aggregator (including spatial and the variable-rate caches), seeded equivalence, integrators alive at the same time, threaded solves (SSA and jump-ODE problems), copies taken from live SSAStepper and ODE integrators (with the original continuing unchanged, also when the copy's integrator type differs), stored versus init callbacks, independence from the original's memory, jump-diffusions through resetted_jump_problem, alias_u0 = true, and PureLeaping.

Follow-ups (not in this PR)

  • SciMLBase: an isolated_copy hook for safetycopy and a trait to skip the per-task copy in EnsembleThreads, so ensembles stop deep-copying jump problems.
  • An opt-in for jumps whose functions keep per-integrator state (the jump counterpart of Fix callbacks with mutable state SciMLBase.jl#1661), planned with JumpProcesses 11.

🤖 Generated with Claude Code 2.1.319 (model: claude-opus-5-5)

`isolated_copy(jprob)` returns a problem that can be solved concurrently with `jprob`, or
used for an integrator alive at the same time as one of its, and shares everything that
solvers don't modify: the wrapped problem, the jumps and their functions, the dependency
maps and the stored callbacks. Each aggregator lists its working fields; the copy rebuilds
it through its default constructor from copies of those fields and its other fields as
they are, and rebuilds the jump callbacks around it (a new VR_Direct cache; VR_FRM's
callbacks are reused). No closure or FunctionWrapper is copied.

`resetted_jump_problem`, which StochasticDiffEq calls for `alias_jumps = false` (the
default off thread 1), now returns an `isolated_copy` instead of a `deepcopy`. The docs
recommend `isolated_copy` over `deepcopy`, and give `deepcopy`'s limitations with
FunctionWrapper-based aggregators.

Replaces SciML#711, whose tests of concurrent and interleaved use are adapted here.

Co-Authored-By: Kaan Öcal <26488673+kaandocal@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isaacsas

isaacsas commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

@kaandocal we can potentially add a kwarg to do a deeper level of copying like your PR if you need that, but I'd prefer this as the default. Let me know your thoughts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master edd8d18 master / edd8d18
aggregators/CCNRM 0.0954 ± 0.0036 ms 0.1 ± 0.0034 ms 0.95 ± 0.048
aggregators/Coevolve 0.108 ± 0.005 ms 0.112 ± 0.0033 ms 0.966 ± 0.053
aggregators/DirectCR 0.108 ± 0.0052 ms 0.114 ± 0.0035 ms 0.943 ± 0.054
aggregators/DirectFW 0.0763 ± 0.0026 ms 0.0758 ± 0.0049 ms 1.01 ± 0.073
aggregators/FRM 0.0741 ± 0.0044 ms 0.0852 ± 0.0025 ms 0.87 ± 0.058
aggregators/FRMFW 0.0775 ± 0.0043 ms 0.0826 ± 0.0039 ms 0.938 ± 0.068
aggregators/NRM 0.0928 ± 0.0057 ms 0.0985 ± 0.0061 ms 0.942 ± 0.082
aggregators/RDirect 0.0945 ± 0.0037 ms 0.102 ± 0.003 ms 0.925 ± 0.045
aggregators/RSSA 0.0864 ± 0.0036 ms 0.0918 ± 0.0032 ms 0.942 ± 0.051
aggregators/RSSACR 0.102 ± 0.0045 ms 0.103 ± 0.0047 ms 0.991 ± 0.062
aggregators/SortingDirect 0.0759 ± 0.0028 ms 0.087 ± 0.0034 ms 0.873 ± 0.047
construct/jumpproblem_constantrate 0.08 ± 0.001 μs 0.08 ± 0.001 μs 1 ± 0.018
construct/jumpproblem_massaction 0.251 ± 0.011 μs 0.251 ± 0.01 μs 1 ± 0.059
construct/vr_direct 3.63 ± 0.29 μs 3.56 ± 0.36 μs 1.02 ± 0.13
construct/vr_frm 5.58 ± 3.3 μs 5.61 ± 3.4 μs 0.995 ± 0.85
events/ode_division/Direct 0.335 ± 0.0062 ms 0.323 ± 0.0068 ms 1.04 ± 0.029
events/sde_dosing/Direct 0.184 ± 0.0041 ms 0.179 ± 0.0071 ms 1.03 ± 0.047
events/ssa_dosing/Direct 0.0644 ± 0.0012 ms 0.0618 ± 0.0029 ms 1.04 ± 0.053
events/vrj_reset/VR_Direct 0.951 ± 0.015 ms 0.893 ± 0.0092 ms 1.06 ± 0.02
events/vrj_reset/VR_FRM 1.48 ± 0.048 ms 1.41 ± 0.05 ms 1.05 ± 0.051
ode/mixed/VR_Direct 0.988 ± 0.016 ms 0.971 ± 0.028 ms 1.02 ± 0.034
ode/mixed/VR_FRM 1.71 ± 0.023 ms 1.63 ± 0.073 ms 1.05 ± 0.049
ode/sir_zero_drift/Direct 0.269 ± 0.0066 ms 0.257 ± 0.0078 ms 1.05 ± 0.041
ode/sir_zero_drift/NRM 0.294 ± 0.0064 ms 0.281 ± 0.0092 ms 1.05 ± 0.041
ode/telegraph/Coevolve 0.125 ± 0.0027 ms 0.12 ± 0.0016 ms 1.04 ± 0.026
ode/telegraph/Direct 0.115 ± 0.0028 ms 0.109 ± 0.0017 ms 1.05 ± 0.031
ode/telegraph/NRM 0.118 ± 0.0025 ms 0.109 ± 0.0039 ms 1.08 ± 0.045
pure_jump/bounded_vrj/Coevolve 0.224 ± 0.0064 ms 0.218 ± 0.0078 ms 1.03 ± 0.047
pure_jump/chain/CCNRM 0.412 ± 0.014 ms 0.421 ± 0.018 ms 0.979 ± 0.053
pure_jump/chain/Direct 2.14 ± 0.073 ms 2.42 ± 0.063 ms 0.886 ± 0.038
pure_jump/chain/DirectCR 0.316 ± 0.012 ms 0.313 ± 0.012 ms 1.01 ± 0.055
pure_jump/chain/NRM 0.386 ± 0.015 ms 0.39 ± 0.012 ms 0.989 ± 0.048
pure_jump/chain/RSSA 1.02 ± 0.032 ms 1.05 ± 0.022 ms 0.975 ± 0.037
pure_jump/chain/RSSACR 0.254 ± 0.0084 ms 0.247 ± 0.0088 ms 1.03 ± 0.05
pure_jump/chain/SortingDirect 0.637 ± 0.017 ms 0.66 ± 0.03 ms 0.966 ± 0.051
sde/mixed/VR_Direct 0.654 ± 0.025 ms 0.694 ± 0.013 ms 0.942 ± 0.04
sde/mixed/VR_FRM 3.75 ± 0.036 ms 3.77 ± 0.045 ms 0.996 ± 0.015
sde/telegraph/Direct 0.187 ± 0.0043 ms 0.186 ± 0.0044 ms 1 ± 0.033
solve/constantrate 0.0767 ± 0.0058 ms 0.077 ± 0.0048 ms 0.997 ± 0.098
solve/massaction 0.0773 ± 0.0052 ms 0.0759 ± 0.003 ms 1.02 ± 0.079
vrj/m1_1/VR_Direct 0.207 ± 0.0051 ms 0.204 ± 0.0062 ms 1.02 ± 0.04
vrj/m1_1/VR_DirectFW 0.225 ± 0.0044 ms 0.224 ± 0.0061 ms 1 ± 0.033
vrj/m1_1/VR_FRM 0.317 ± 0.0062 ms 0.298 ± 0.0055 ms 1.07 ± 0.029
vrj/m1_16/Coevolve 0.119 ± 0.0047 ms 0.113 ± 0.0046 ms 1.05 ± 0.06
vrj/m1_16/VR_Direct 0.427 ± 0.0075 ms 0.408 ± 0.0074 ms 1.05 ± 0.026
vrj/m1_16/VR_DirectFW 0.491 ± 0.0082 ms 0.476 ± 0.0083 ms 1.03 ± 0.025
vrj/m1_16/VR_FRM 1.45 ± 0.017 ms 1.46 ± 0.063 ms 0.993 ± 0.045
time_to_load 0.692 ± 0.015 s 0.696 ± 0.039 s 0.995 ± 0.06
Memory benchmarks
master edd8d18 master / edd8d18
aggregators/CCNRM 3.65 k allocs: 0.231 MB 3.65 k allocs: 0.231 MB 1
aggregators/Coevolve 3.65 k allocs: 0.232 MB 3.65 k allocs: 0.232 MB 1
aggregators/DirectCR 3.66 k allocs: 0.232 MB 3.66 k allocs: 0.232 MB 1
aggregators/DirectFW 3.71 k allocs: 0.234 MB 3.71 k allocs: 0.234 MB 1
aggregators/FRM 3.68 k allocs: 0.233 MB 3.68 k allocs: 0.233 MB 1
aggregators/FRMFW 3.68 k allocs: 0.233 MB 3.68 k allocs: 0.233 MB 1
aggregators/NRM 3.65 k allocs: 0.232 MB 3.65 k allocs: 0.232 MB 1
aggregators/RDirect 3.69 k allocs: 0.233 MB 3.69 k allocs: 0.233 MB 1
aggregators/RSSA 3.63 k allocs: 0.231 MB 3.63 k allocs: 0.231 MB 1
aggregators/RSSACR 3.71 k allocs: 0.234 MB 3.71 k allocs: 0.234 MB 1
aggregators/SortingDirect 3.69 k allocs: 0.233 MB 3.69 k allocs: 0.233 MB 1
construct/jumpproblem_constantrate 15 allocs: 0.625 kB 15 allocs: 0.625 kB 1
construct/jumpproblem_massaction 14 allocs: 0.688 kB 14 allocs: 0.688 kB 1
construct/vr_direct 0.106 k allocs: 5.08 kB 0.106 k allocs: 5.08 kB 1
construct/vr_frm 0.086 k allocs: 13 kB 0.086 k allocs: 13 kB 1
events/ode_division/Direct 0.082 k allocs: 4.34 kB 0.082 k allocs: 4.34 kB 1
events/sde_dosing/Direct 0.184 k allocs: 9.94 kB 0.184 k allocs: 9.94 kB 1
events/ssa_dosing/Direct 15 allocs: 1 kB 15 allocs: 1 kB 1
events/vrj_reset/VR_Direct 0.099 k allocs: 5.64 kB 0.099 k allocs: 5.64 kB 1
events/vrj_reset/VR_FRM 0.142 k allocs: 7.58 kB 0.142 k allocs: 7.58 kB 1
ode/mixed/VR_Direct 0.082 k allocs: 4.36 kB 0.082 k allocs: 4.36 kB 1
ode/mixed/VR_FRM 0.123 k allocs: 6.09 kB 0.123 k allocs: 6.09 kB 1
ode/sir_zero_drift/Direct 0.068 k allocs: 3.62 kB 0.068 k allocs: 3.62 kB 1
ode/sir_zero_drift/NRM 0.075 k allocs: 3.91 kB 0.075 k allocs: 3.91 kB 1
ode/telegraph/Coevolve 0.079 k allocs: 4.05 kB 0.079 k allocs: 4.05 kB 1
ode/telegraph/Direct 0.07 k allocs: 3.69 kB 0.07 k allocs: 3.69 kB 1
ode/telegraph/NRM 0.077 k allocs: 3.97 kB 0.077 k allocs: 3.97 kB 1
pure_jump/bounded_vrj/Coevolve 25 allocs: 2.2 kB 25 allocs: 2.2 kB 1
pure_jump/chain/CCNRM 19 allocs: 8.8 kB 19 allocs: 8.8 kB 1
pure_jump/chain/Direct 16 allocs: 5.61 kB 16 allocs: 5.61 kB 1
pure_jump/chain/DirectCR 16 allocs: 5.61 kB 16 allocs: 5.61 kB 1
pure_jump/chain/NRM 26 allocs: 18.4 kB 26 allocs: 18.4 kB 1
pure_jump/chain/RSSA 16 allocs: 5.61 kB 16 allocs: 5.61 kB 1
pure_jump/chain/RSSACR 16 allocs: 5.61 kB 16 allocs: 5.61 kB 1
pure_jump/chain/SortingDirect 16 allocs: 5.61 kB 16 allocs: 5.61 kB 1
sde/mixed/VR_Direct 0.204 k allocs: 11.6 kB 0.204 k allocs: 11.6 kB 1
sde/mixed/VR_FRM 0.328 k allocs: 17.9 kB 0.328 k allocs: 17.9 kB 1
sde/telegraph/Direct 0.183 k allocs: 9.81 kB 0.183 k allocs: 9.81 kB 1
solve/constantrate 3.71 k allocs: 0.234 MB 3.71 k allocs: 0.234 MB 1
solve/massaction 3.71 k allocs: 0.234 MB 3.71 k allocs: 0.234 MB 1
vrj/m1_1/VR_Direct 0.082 k allocs: 4.33 kB 0.082 k allocs: 4.33 kB 1
vrj/m1_1/VR_DirectFW 0.082 k allocs: 4.33 kB 0.082 k allocs: 4.33 kB 1
vrj/m1_1/VR_FRM 0.123 k allocs: 6.19 kB 0.123 k allocs: 6.19 kB 1
vrj/m1_16/Coevolve 0.079 k allocs: 6.67 kB 0.079 k allocs: 6.67 kB 1
vrj/m1_16/VR_Direct 0.082 k allocs: 6.52 kB 0.082 k allocs: 6.52 kB 1
vrj/m1_16/VR_DirectFW 0.082 k allocs: 6.52 kB 0.082 k allocs: 6.52 kB 1
vrj/m1_16/VR_FRM 0.159 k allocs: 20.3 kB 0.159 k allocs: 20.3 kB 1
time_to_load 0.2 k allocs: 11.7 kB 0.2 k allocs: 11.7 kB 1

Benchmark Results (Julia lts)

Time benchmarks
master edd8d18 master / edd8d18
aggregators/CCNRM 0.184 ± 0.0094 ms 0.186 ± 0.0086 ms 0.991 ± 0.068
aggregators/Coevolve 0.229 ± 0.01 ms 0.233 ± 0.011 ms 0.982 ± 0.064
aggregators/DirectCR 0.211 ± 0.0098 ms 0.212 ± 0.01 ms 0.996 ± 0.066
aggregators/DirectFW 0.168 ± 0.0059 ms 0.166 ± 0.0051 ms 1.01 ± 0.047
aggregators/FRM 0.145 ± 0.0043 ms 0.154 ± 0.0057 ms 0.94 ± 0.045
aggregators/FRMFW 0.15 ± 0.0058 ms 0.153 ± 0.0056 ms 0.982 ± 0.053
aggregators/NRM 0.188 ± 0.0091 ms 0.189 ± 0.0091 ms 0.997 ± 0.068
aggregators/RDirect 0.189 ± 0.0078 ms 0.193 ± 0.0083 ms 0.982 ± 0.059
aggregators/RSSA 0.171 ± 0.0078 ms 0.169 ± 0.0049 ms 1.01 ± 0.055
aggregators/RSSACR 0.205 ± 0.01 ms 0.207 ± 0.01 ms 0.993 ± 0.069
aggregators/SortingDirect 0.16 ± 0.0056 ms 0.163 ± 0.0048 ms 0.978 ± 0.045
construct/jumpproblem_constantrate 0.31 ± 0.11 μs 0.281 ± 0.02 μs 1.1 ± 0.4
construct/jumpproblem_massaction 0.641 ± 0.11 μs 0.641 ± 0.05 μs 1 ± 0.19
construct/vr_direct 7.21 ± 0.43 μs 7.04 ± 0.51 μs 1.02 ± 0.096
construct/vr_frm 12.5 ± 0.64 μs 12.4 ± 0.53 μs 1.01 ± 0.068
events/ode_division/Direct 0.537 ± 0.0095 ms 0.536 ± 0.0093 ms 1 ± 0.025
events/sde_dosing/Direct 0.302 ± 0.0095 ms 0.301 ± 0.0092 ms 1 ± 0.044
events/ssa_dosing/Direct 0.115 ± 0.0019 ms 0.115 ± 0.0016 ms 0.998 ± 0.022
events/vrj_reset/VR_Direct 1.68 ± 0.013 ms 1.69 ± 0.0094 ms 0.993 ± 0.0095
events/vrj_reset/VR_FRM 2.39 ± 0.019 ms 2.4 ± 0.014 ms 0.994 ± 0.0098
ode/mixed/VR_Direct 1.65 ± 0.013 ms 1.66 ± 0.012 ms 0.998 ± 0.01
ode/mixed/VR_FRM 2.62 ± 0.018 ms 2.61 ± 0.013 ms 1 ± 0.0085
ode/sir_zero_drift/Direct 0.428 ± 0.0092 ms 0.423 ± 0.0074 ms 1.01 ± 0.028
ode/sir_zero_drift/NRM 0.445 ± 0.01 ms 0.462 ± 0.0088 ms 0.963 ± 0.028
ode/telegraph/Coevolve 0.175 ± 0.0063 ms 0.171 ± 0.0051 ms 1.02 ± 0.048
ode/telegraph/Direct 0.151 ± 0.002 ms 0.152 ± 0.0017 ms 0.995 ± 0.017
ode/telegraph/NRM 0.165 ± 0.003 ms 0.167 ± 0.0019 ms 0.986 ± 0.021
pure_jump/bounded_vrj/Coevolve 0.363 ± 0.0095 ms 0.357 ± 0.0093 ms 1.02 ± 0.037
pure_jump/chain/CCNRM 0.826 ± 0.01 ms 0.826 ± 0.01 ms 1 ± 0.018
pure_jump/chain/Direct 4.65 ± 0.031 ms 4.68 ± 0.024 ms 0.993 ± 0.0084
pure_jump/chain/DirectCR 0.572 ± 0.012 ms 0.555 ± 0.012 ms 1.03 ± 0.031
pure_jump/chain/NRM 0.765 ± 0.011 ms 0.755 ± 0.011 ms 1.01 ± 0.021
pure_jump/chain/RSSA 2.15 ± 0.011 ms 2.15 ± 0.012 ms 1 ± 0.0074
pure_jump/chain/RSSACR 0.51 ± 0.012 ms 0.505 ± 0.012 ms 1.01 ± 0.034
pure_jump/chain/SortingDirect 1.33 ± 0.015 ms 1.35 ± 0.014 ms 0.984 ± 0.015
sde/mixed/VR_Direct 1.1 ± 0.0083 ms 1.07 ± 0.0075 ms 1.03 ± 0.011
sde/mixed/VR_FRM 5.48 ± 0.023 ms 5.38 ± 0.036 ms 1.02 ± 0.0081
sde/telegraph/Direct 0.308 ± 0.0092 ms 0.317 ± 0.0096 ms 0.971 ± 0.041
solve/constantrate 0.151 ± 0.0056 ms 0.153 ± 0.0067 ms 0.99 ± 0.057
solve/massaction 0.16 ± 0.0057 ms 0.166 ± 0.0091 ms 0.962 ± 0.063
vrj/m1_1/VR_Direct 0.403 ± 0.0095 ms 0.381 ± 0.0094 ms 1.06 ± 0.036
vrj/m1_1/VR_DirectFW 0.415 ± 0.0094 ms 0.416 ± 0.009 ms 0.996 ± 0.031
vrj/m1_1/VR_FRM 0.589 ± 0.01 ms 0.577 ± 0.01 ms 1.02 ± 0.025
vrj/m1_16/Coevolve 0.208 ± 0.0033 ms 0.205 ± 0.0034 ms 1.01 ± 0.023
vrj/m1_16/VR_Direct 0.752 ± 0.0048 ms 0.755 ± 0.0043 ms 0.996 ± 0.0085
vrj/m1_16/VR_DirectFW 0.837 ± 0.0048 ms 0.841 ± 0.0043 ms 0.995 ± 0.0077
vrj/m1_16/VR_FRM 2.64 ± 0.022 ms 2.6 ± 0.021 ms 1.01 ± 0.012
time_to_load 1.41 ± 0.038 s 1.48 ± 0.027 s 0.952 ± 0.031
Memory benchmarks
master edd8d18 master / edd8d18
aggregators/CCNRM 1.82 k allocs: 0.192 MB 1.82 k allocs: 0.192 MB 1
aggregators/Coevolve 1.83 k allocs: 0.192 MB 1.83 k allocs: 0.192 MB 1
aggregators/DirectCR 1.83 k allocs: 0.193 MB 1.83 k allocs: 0.193 MB 1
aggregators/DirectFW 1.85 k allocs: 0.194 MB 1.85 k allocs: 0.194 MB 1
aggregators/FRM 1.84 k allocs: 0.194 MB 1.84 k allocs: 0.194 MB 1
aggregators/FRMFW 1.84 k allocs: 0.194 MB 1.84 k allocs: 0.194 MB 1
aggregators/NRM 1.83 k allocs: 0.192 MB 1.83 k allocs: 0.192 MB 1
aggregators/RDirect 1.84 k allocs: 0.194 MB 1.84 k allocs: 0.194 MB 1
aggregators/RSSA 1.82 k allocs: 0.192 MB 1.82 k allocs: 0.192 MB 1
aggregators/RSSACR 1.85 k allocs: 0.194 MB 1.85 k allocs: 0.194 MB 1
aggregators/SortingDirect 1.84 k allocs: 0.194 MB 1.84 k allocs: 0.194 MB 1
construct/jumpproblem_constantrate 12 allocs: 0.781 kB 12 allocs: 0.781 kB 1
construct/jumpproblem_massaction 10 allocs: 0.703 kB 10 allocs: 0.703 kB 1
construct/vr_direct 0.1 k allocs: 5.36 kB 0.1 k allocs: 5.36 kB 1
construct/vr_frm 0.097 k allocs: 15 kB 0.097 k allocs: 15 kB 1
events/ode_division/Direct 0.059 k allocs: 4.8 kB 0.059 k allocs: 4.8 kB 1
events/sde_dosing/Direct 0.133 k allocs: 10.7 kB 0.133 k allocs: 10.7 kB 1
events/ssa_dosing/Direct 10 allocs: 1.03 kB 10 allocs: 1.03 kB 1
events/vrj_reset/VR_Direct 0.072 k allocs: 6.09 kB 0.072 k allocs: 6.09 kB 1
events/vrj_reset/VR_FRM 0.093 k allocs: 8.06 kB 0.093 k allocs: 8.06 kB 1
ode/mixed/VR_Direct 0.059 k allocs: 4.81 kB 0.059 k allocs: 4.81 kB 1
ode/mixed/VR_FRM 0.079 k allocs: 6.58 kB 0.079 k allocs: 6.58 kB 1
ode/sir_zero_drift/Direct 0.052 k allocs: 4.17 kB 0.052 k allocs: 4.17 kB 1
ode/sir_zero_drift/NRM 0.056 k allocs: 4.45 kB 0.056 k allocs: 4.45 kB 1
ode/telegraph/Coevolve 0.057 k allocs: 4.53 kB 0.057 k allocs: 4.53 kB 1
ode/telegraph/Direct 0.052 k allocs: 4.17 kB 0.052 k allocs: 4.17 kB 1
ode/telegraph/NRM 0.056 k allocs: 4.45 kB 0.056 k allocs: 4.45 kB 1
pure_jump/bounded_vrj/Coevolve 16 allocs: 2.28 kB 16 allocs: 2.28 kB 1
pure_jump/chain/CCNRM 12 allocs: 9.34 kB 12 allocs: 9.34 kB 1
pure_jump/chain/Direct 11 allocs: 6.09 kB 11 allocs: 6.09 kB 1
pure_jump/chain/DirectCR 11 allocs: 6.09 kB 11 allocs: 6.09 kB 1
pure_jump/chain/NRM 15 allocs: 19 kB 15 allocs: 19 kB 1
pure_jump/chain/RSSA 11 allocs: 6.09 kB 11 allocs: 6.09 kB 1
pure_jump/chain/RSSACR 11 allocs: 6.09 kB 11 allocs: 6.09 kB 1
pure_jump/chain/SortingDirect 11 allocs: 6.09 kB 11 allocs: 6.09 kB 1
sde/mixed/VR_Direct 0.144 k allocs: 12.1 kB 0.144 k allocs: 12.1 kB 1
sde/mixed/VR_FRM 0.21 k allocs: 19 kB 0.21 k allocs: 19 kB 1
sde/telegraph/Direct 0.133 k allocs: 10.6 kB 0.133 k allocs: 10.6 kB 1
solve/constantrate 1.85 k allocs: 0.194 MB 1.85 k allocs: 0.194 MB 1
solve/massaction 1.85 k allocs: 0.194 MB 1.85 k allocs: 0.194 MB 1
vrj/m1_1/VR_Direct 0.059 k allocs: 4.78 kB 0.059 k allocs: 4.78 kB 1
vrj/m1_1/VR_DirectFW 0.059 k allocs: 4.78 kB 0.059 k allocs: 4.78 kB 1
vrj/m1_1/VR_FRM 0.079 k allocs: 6.67 kB 0.079 k allocs: 6.67 kB 1
vrj/m1_16/Coevolve 0.057 k allocs: 7.17 kB 0.057 k allocs: 7.17 kB 1
vrj/m1_16/VR_Direct 0.059 k allocs: 6.97 kB 0.059 k allocs: 6.97 kB 1
vrj/m1_16/VR_DirectFW 0.059 k allocs: 6.97 kB 0.059 k allocs: 6.97 kB 1
vrj/m1_16/VR_FRM 0.107 k allocs: 20.8 kB 0.107 k allocs: 20.8 kB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

isaacsas added a commit that referenced this pull request Nov 8, 2026
typos flagged the affects `ab!` and `ba!` of an A <--> B test problem (in #714) as
misspellings of `by` and `be`. Two-letter identifiers are almost always names, so ignore
them; longer misspellings are still caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaandocal

Copy link
Copy Markdown
Contributor

This looks even better! Together with the callback sharing PR I submitted to SciMLBase I think this will work quite nicely, thanks Sam!

@isaacsas

isaacsas commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Yeah, that PR looks helpful too. I think the only other thing we need outside of JumpProcesses is the trait to opt out of type erasure for specific callbacks and we should be in good shape.

@kaandocal

Copy link
Copy Markdown
Contributor

How exactly? I can add this to that PR, or feel free to update it!

@isaacsas

isaacsas commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

If you build a JumpProblem over an ODEProblem all callbacks, including the jumps, get type erased. I think this was done to enable reuse of integrators without recompilation, but it has significant performance impacts on models with jumps. SSAStepper avoids it, and JumpProblem over SDEProblem avoids it as the jump callback gets added after user callbacks are type erased. The trait would be something a callback can opt into to tell DiffEqBase not to type erase it, but honestly I don't know how easy this would be to implement at a individual callback level (i.e. it might require storing two sets of callbacks). The easier solution would be if any one callback declares it shouldn't be type erased you just don't type erase any.

In the meantime one should always declare JumpProblems over ODEProblems with full specialization for the ODEProblem unless solver performance really doesn't matter.

@isaacsas

isaacsas commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

i.e. you should do:

oprob = ODEProblem{true, SciMLBase.FullSpecialize}(f, u0, tspan, p)
jprob = JumpProblem(oprob, RSSA(), maj, crj; deps...)

@isaacsas

isaacsas commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

(ModelingToolkit now constructs JumpProblems over any other problem type to fully specialize by default, so this shouldn't be an issue with Catalyst-generated models.)

@kaandocal

Copy link
Copy Markdown
Contributor

I see, you raised that issue in DiffEqBase.jl the other day. I will leave that one to you experts...

isaacsas and others added 2 commits November 9, 2026 08:53
… buffers

From review: copying arrays of non-bits numbers element by element read the unassigned
entries of a fresh aggregator's buffers (`Vector{BigFloat}(undef, n)`), so `isolated_copy`
threw `UndefRefError` for unsolved problems with `BigFloat` times or `BigInt` states. Arrays
of numbers are now copied as containers.

Each type that holds jump state now declares, next to its definition, the fields that hold
definitions (`shared_fields`), and `isolated_copy` copies every other field. A field nobody
classified is copied, or makes `isolated_copy` throw with an explanation if its type can't
be copied, instead of being shared by mistake; this caught `TimeGrouper`, which isn't a bits
type with `BigFloat` times. The generated rebuild now calls `shared_fields` from the
generated code rather than in the generator, so declarations made in other packages are
seen. Copy times are unchanged.

Tests copy unsolved problems with BigFloat times for each aggregator that supports them, a
BigInt state with RSSA and BigFloat ODEs with VR_Direct and VR_DirectFW, and check that every
aggregator and hopping-rate type declares its shared fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test/isolated_copy.jl uses `subtypes` to check that every aggregator declares its shared
fields; Pkg.test only loads declared test dependencies, so the ThreadSafety jobs stopped
with "Package InteractiveUtils not found".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isaacsas isaacsas changed the title WIP: Add isolated_copy, a JumpProblem with its own jump state Add isolated_copy, a JumpProblem with its own jump state Nov 10, 2026
@isaacsas
isaacsas merged commit 8585a2b into SciML:master Nov 11, 2026
18 checks passed
@isaacsas
isaacsas deleted the isolated-copy branch November 11, 2026 02:23
@isaacsas isaacsas mentioned this pull request Nov 11, 2026
@kaandocal kaandocal mentioned this pull request Nov 11, 2026
5 tasks done
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.

2 participants