Repository navigation
Conversation
When Coevolve handles the bounded VariableRateJumps, JumpProblem passes the remaining ones (cvrjs) to the VR aggregator. VR_FRM builds its callbacks from them, but VR_Direct and VR_DirectFW built their cache from all of jumps.variable_jumps, so they also simulated the bounded jumps that Coevolve handles, which then fired twice as often (a rate-1 jump fired about 40 times by t = 20 instead of 20). The cache is now built from cvrjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`JumpDependencies` gains `vrjtovars_map` and `vrj_dep_graph`, indexed over the problem's `VariableRateJump`s. When either is given, `JumpProblem` prepares the list each general `VariableRateJump` hands the SSA aggregator: the jumps whose rates to recompute (from `vrj_dep_graph`, or derived from `vrjtovars_map` and `vartojumps_map`), or for RSSA and RSSACR the changed variables. After the jump's affect, the VR_FRM, VR_Direct and VR_DirectFW callbacks find the SSA aggregator among the integrator's discrete callbacks (an unrolled search over a tuple) and call `update_after_external_change!`, which recomputes the listed rates, redraws the next jump, and registers its time if it is later than `t`. Without these maps nothing changes. Coevolve's `update_dependent_rates!` and `next_time` take the executed jump (0 for an outside change), so jumps with constant rates rescale their times after an outside change instead of the next jump redrawing its time, which biased it. The per-aggregator `missing_dep_graph_message` methods become one `missing_map_message` used for every missing map, the new ones included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The recursion through `Base.tail` stopped being resolved at compile time beyond 32 discrete callbacks: with the aggregator after 40 user callbacks (StochasticDiffEq's order) the search took 8 µs instead of 2 ns. The generated function picks the position from the callbacks' types, so its body is the field access. The test now checks the typed code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
Benchmark Results (Julia lts)Time benchmarks
Memory benchmarks
|
# Conflicts: # HISTORY.md # src/variable_rate.jl
The test passed it as a JumpProblem keyword, which SciML#709 deprecated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage runs (the Downgrade workflow) add code_coverage_effect statements to the typed code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The typed-code check read compiler internals (CodeInfo, ReturnNode, IR expression heads). Time 10^4 searches instead, storing each result so none is skipped: the generated lookup takes at most 0.05 ms among 41 callbacks (coverage included), the earlier Base.tail recursion 89-113 ms (Julia 1.10 and 1.13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # HISTORY.md
… lists From the review of SciML#713: - CCNRM searches its time table from the bin where its last search stopped. An outside update happens before the next jump, possibly in an earlier bin, so a jump it moved there was skipped (and surfaced later as a tstop in the past). If the table had been rebuilt to start at a later jump time, the new time could even fall before its window, an out-of-bounds insert. The update now moves the search back to the bin of `t`, or rebuilds the window to start at `t`. - After an affect stops the solve, the outside update does nothing: a new tstop restarted SDE solves, and ODE solves stopped with a custom retcode. - isolated_copy shares VR_DirectEventCache's `updates` (read-only lists); copying the field threw. - An unchanged next jump time keeps its stop instead of adding another, so NRM, CCNRM and Coevolve no longer add a stop per update when the next jump stays the same. - Direct, DirectFW, FRM and FRMFW store one Bool per VariableRateJump (whether it changes a rate) instead of the lists they don't use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent review (Codex CLI v0.164.0 / gpt-6.1-sol), reviewer session 01a1cf3b-f1dd-7cd1-b102-8a24ff90c211, reviewed head 82e21f6
This is a blind code-only review by a session other than the PR author's, copied below from the reviewer's report with only the grading metadata removed. The posting agent did not re-run the reviewer's commands. A MERGE verdict is advice; merging is left to the maintainers. CI: green Riskmedium-low (ML2: opt-in hybrid SSA/variable-rate scheduling changes across twelve aggregators, checked against independent analytic distributions) Blocking findingsNone found by inspection or execution.
Non-blocking findingsNone. What I ranAI reviewer: codex-cli 0.164.0, model gpt-6.1-sol; local session identified above (no session URL available). Risk and verdict are independent; no author rating or earlier review was read.
What I did not verifyQA, documentation builds, other test groups, additional Julia versions/platforms, a clean-base replay comparison, or end-to-end performance. CI green is caller-supplied, not independently queried. PR body, comments, reviews, sibling review artifacts, and author execution claims were not inspected. 🤖 Posted by an AI agent — harness: Claude Code 2.1.322 · model: claude-sonnet-5-5 |
From the second review of SciML#713. When an outside update rebuilt the time table's window to start at `t`, `rebuild!` set the search position from the old times, and the move back to the bin of `t` was skipped, so a jump the update put in an earlier bin was missed. The update now always moves the search back after a rebuild. `rebuild!` also sets `minbin` to 0 when the rebuilt window holds no time instead of throwing (assigning `nothing` to the integer field). The CCNRM test also runs with narrow bins (`binwidthconst = 2, numbinsconst = 5`), whose checks failed before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR: #713 Reviewed head: 2964500 Risk assessment
Review reportVERDICT: MERGE Riskmedium-low (ML2: opt-in hybrid jump scheduling across SSA aggregators, checked against analytic moments and exact state invariants; no-map behavior retained). Blocking findingsNone confirmed.
Non-blocking findings
What I ranAI review by Codex (version unavailable), model All commands exported the requested
What I did not verifyOther Julia versions/platforms, documentation build, QA, InterfaceII, threaded suites, GPU execution, or performance benchmarks. CI was not inspected under the blind-review restriction and remains reported as not green; MERGE is code-review advice, not authorization to bypass CI. No prior-review comparison was performed because no trusted earlier opinion was supplied. No checkout edits, commits, pushes, or GitHub posts were made. AUTHOR_GRADE: {"task":"feature","score":4,"difficulty":4,"rounds":3,"author_harness":"unknown","author_model":"unknown","note":"Complete InterfaceI passes, independent analytic and structural probes pass, and empty-window rebuilding fails on base and passes on head. Only a minor historical-comment instruction violation was found; other platforms and CI remain unverified."} Head link: 2964500 🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol |
Part of the series that lets SSA jumps be updated after a
VariableRateJumpfires, so that Catalyst can stop making their dependentsVariableRateJumps. This PR adds theVariableRateJumpmaps toJumpDependencies, a per-aggregator update for changes made outside the aggregator, and hooks inVR_FRM,VR_DirectandVR_DirectFWthat use it. The next PR adds a publicupdate_aggregated_jumps!(integrator; ...)for callbacks and events, built on the same update.VariableRateJumpmapsJumpDependenciesgains two maps, numbering theVariableRateJumps in the order given to theJumpProblem:vrjtovars_map: entryklists the variables thekthVariableRateJumpchanges;vrj_dep_graph: entryklists the jumps whose rates must be recalculated when thekthVariableRateJumpoccurs.With Coevolve, the entries of bounded
VariableRateJumps are ignored, since Coevolve handles them as SSA jumps. The maps are checked against the problem like the others: one entry perVariableRateJump, indices in range.Without either map nothing changes: the rule that an SSA jump's rate must not depend on what a general
VariableRateJumpchanges still holds, and the VR callbacks do exactly what they did before. With one, after eachVariableRateJumpoccurs the aggregator updates the rates that depend on the change. What each aggregator needs:Direct,DirectFW,FRM,FRMFW: nothing more. They recompute every rate when they choose the next jump. When the maps show that aVariableRateJumpchanges no rate, it is skipped; for that they store one Bool perVariableRateJump, not the lists.SortingDirect,RDirect,NRM,CCNRM,DirectCR,Coevolve:vrj_dep_graph, orvrjtovars_mapandvartojumps_map, from which the jump lists are derived (vartojumps_mapis generated when every jump is aMassActionJump).RSSA,RSSACR:vrjtovars_map, since they update the brackets of the changed variables. Each entry keeps only the variables that some jump's rate reads.A missing map is an error naming the fields to give.
JumpProblemprepares the list eachVariableRateJumphands the aggregator once, in normal form (sorted, unique,Int).The update
update_after_external_change!(p, integrator, deps)(internal, one generic method plus per-aggregatorupdate_external_rates!) does three things:generate_jumps!). This is exact because the jumps are memoryless, and it is needed even when no rate bound changed, since the next jump was chosen with the old state.tand changed. A next jump attfires in the same callback pass, since discrete callbacks run after continuous ones, while atstopattmakes SDE solvers stop. A test covers this tie for ODEs and SDEs. An unchanged time keeps thetstopregistered when it was chosen; NRM, CCNRM and Coevolve often keep the same next jump.Nothing is done after an affect stopped the solve (
terminate!), since a newtstopwould restart it.CCNRM
CCNRM keeps its jump times in bins and searches from the bin where its last search stopped. After a jump at
t, every new time is at leastt, so that's enough. An outside update happens before the next jump, possibly in an earlier bin, so the update moves the search back to the bin oft. If the table was rebuilt to start at the next jump's time, aftert, the update first rebuilds the window to start att(the times stay) and then moves the search back as well, since the rebuild positions it at the old times. A rebuilt window that holds no time no longer throws.Coevolve
update_dependent_rates!andnext_timenow take the executed jump, defaulting top.next_jumpas before, and the outside update passes 0. Before, the jump at the top of the queue was treated as the one that executed and drew a fresh time, while the others rescaled theirs. After an outside change no jump executed. Redrawing only the top jump's time conditions it on being the smallest, which biased its times: in the bounded-VariableRateJumptest the mean was about 10 standard errors off. With the executed jump passed in, every listed jump with a constant rate rescales its time.Finding the aggregator
The VR callbacks don't store the SSA aggregator. Each time a
VariableRateJumpoccurs, they find it among the integrator's discrete callbacks, sodeepcopy,remakeand the plannedisolated_copyneed nothing new. Over aTupleof callbacks, a generated function picks the aggregator's position from the callbacks' types. The search therefore compiles to one field access however many callbacks there are, whether the aggregator's callback comes first (JumpProcesses' ODE solve) or after the user's (StochasticDiffEq, which still passes aTuple). Over an erasedVectorit is a loop. A test with 40 userDiscreteCallbacks checks, in both orders, that the search infers, allocates nothing and is fast: the best of 5 runs of 10⁴ searches must take under 1 ms. The generated lookup takes at most 0.05 ms, coverage runs included; theBase.tailrecursion took 89–113 ms on Julia 1.10 and 1.13.Missing-map errors (from the #709 review)
The per-aggregator
missing_dep_graph_messagemethods are replaced by onemissing_map_message(aggregator, map, purpose, fields), which usesnameof(typeof(aggregator)). Every missing-map error uses it, the newVariableRateJumpones included, for example:Coevolve's message says "for
ConstantRateJumps or boundedVariableRateJumps" when the problem has boundedVariableRateJumps. The errors stayErrorExceptions, astest/variable_rate.jlchecks; the newVariableRateJumpones areErrorExceptions too. The exact-message checks intest/jump_dependencies.jlare updated.Docs and tests
JumpDependenciesdocstring (the maps, aVariableRateJumps section with each aggregator's needs), the rule in the jump diffusion tutorial, the discrete stochastic example and the algorithms overview, and a new FAQ entry with an example. HISTORY entries.test/vrj_ssa_updates.jl(new) uses a birth–death model whose births are aVariableRateJumpat rate K(1 + sin Ωt) and whose deaths are aMassActionJumpat rate ΓA. A(T) is Poisson with a known mean, so the tests are exact:VR_FRM,VR_Direct,VR_DirectFW(ODE,FullSpecialize), and Direct, NRM, RSSA, Coevolve ×VR_FRM,VR_Direct(SDE), each against the exact mean and Poisson dispersion;VariableRateJump's time fires at once (ODE and SDE);VariableRateJumps;VariableRateJumps with Coevolve;remakeand ensembles;isolated_copy, which shares the read-only lists (VR_DirectEventCache'supdatesis among its shared fields);binwidthconst = 2, numbinsconst = 5);EM()), for all three VR aggregators;tstop(NRM);test/variable_rate.jlto pass itsdep_graphin aJumpDependencies. It used theJumpProblemkeyword that Add JumpDependencies for passing dependency maps #709 deprecated, which printed deprecation warnings in the test suite.Performance
Alternating benchmark of master
ba89d1f7and this branch, best of 3 rounds with rotated order (Julia 1.13.3, Apple silicon). ODE problems are built withFullSpecializeand solved withTsit5.Hybrid problems.
VR_FRM,VR_DirectandVR_DirectFW, each with Direct, NRM, RSSA and Coevolve, on two models over T = 20:VariableRateJumpat rate 20(1 + sin 2t), deaths aMassActionJump;MassActionJumps.VariableRateJumpmaps: the same behavior on both, so what the hooks cost when offVariableRateJump(master)VariableRateJump(master)The exact rows compare against today's workaround. On master, an exact simulation must make every jump whose rate reads, directly or through other such jumps, a component that a
VariableRateJumpchanges into aVariableRateJumpitself. In the chain that is every jump. With the maps they stayMassActionJumps:VR_FRM, about 2× withVR_Directand about 2.8× withVR_DirectFW.VR_FRM, 11% and 23% slower: updating a heap-based aggregator costs more there than integrating one more rate.SSA networks. The 13 networks of #709's benchmark, with Coevolve (whose update functions changed) and with Direct and NRM as controls: 32 of 37 within ±3%, geometric mean 1.007. The five outside it are
sir/Coevolve,sir_crj/NRM,hub_1000/Direct, andode_sirwith NRM and Coevolve:sir/Coevolvewas 1.06 in all three rounds, but 1.006 in a recheck with five alternating processes per version.sir_crj/NRMis the process-state effect described in Add JumpDependencies for passing dependency maps #709.hub_1000/Directwas slow in one round only.ode_sirwith NRM and Coevolve came out faster.The search. It takes 2 ns and allocates nothing among 41 discrete callbacks. That holds with the aggregator's callback first (ODE) and last (a real SDE integrator, StochasticDiffEq's order). The first version recursed through
Base.tail. Once there were more than 32 callbacks that recursion was no longer resolved at compile time, and with 40 user callbacks the search took 8 µs, though it still inferred and allocated nothing. The generated lookup fixed that, and the test now times the search, using only public functions.SDEs. In the birth–death jump-diffusion (
SRIW1), maps withVR_Directtook 2.6× as long as making the death aVariableRateJump: about 7,650 accepted steps against 790. That is what SSA jumps cost in SDE solves in general. Each one is a tstop, and the step size grows back slowly after it. A pure-SSA version of the same process, with noVariableRateJumps, takes about 6,840 steps for its roughly 800 jumps. An update that changes the next jump time also leaves the aggregator's earlier tstop in place, since a tstop can't be removed, so the integrator stops there once without a jump. That accounts for roughly a tenth of the steps here, and costs little in ODE solves. An update that leaves the time unchanged adds no tstop. WithVR_FRMthe two approaches are about even in SDEs (10.7 ms against 11.2 ms).🤖 Generated with Claude Code 2.1.319 (model: claude-opus-5-5)