Skip to content

SimpleExplicitTauLeaping solver#513

Merged
isaacsas merged 101 commits intoSciML:masterfrom
sivasathyaseeelan:adaptive-implicit
Feb 14, 2026
Merged

SimpleExplicitTauLeaping solver#513
isaacsas merged 101 commits intoSciML:masterfrom
sivasathyaseeelan:adaptive-implicit

Conversation

@sivasathyaseeelan
Copy link
Copy Markdown
Contributor

@sivasathyaseeelan sivasathyaseeelan commented Aug 9, 2025

using JumpProcesses, DiffEqBase
using Test, LinearAlgebra, Statistics
using StableRNGs, Plots
rng = StableRNG(12345)

Nsims = 10

β = 0.1 / 1000.0
ν = 0.01
influx_rate = 1.0
p = (β, ν, influx_rate)

u0 = [999.0, 10.0, 0.0]  # S, I, R
tspan = (0.0, 250.0)

prob_disc = DiscreteProblem(u0, tspan, p)

# MassActionJump formulation for SimpleExplicitTauLeaping
reactant_stoich = [[1=>1, 2=>1], [2=>1], Pair{Int,Int}[]]
net_stoich = [[1=>-1, 2=>1], [2=>-1, 3=>1], [1=>1]]
param_idxs = [1, 2, 3]
maj = MassActionJump(reactant_stoich, net_stoich; param_idxs=param_idxs)
jump_prob_maj = JumpProblem(prob_disc, PureLeaping(), maj; rng=rng)

# Solve with SimpleExplicitTauLeaping
sol = solve(EnsembleProblem(jump_prob_maj), SimpleExplicitTauLeaping(), EnsembleSerial(); trajectories=Nsims)

plot(sol)

SimpleExplicitTauLeaping Plot:

Screenshot from 2025-08-10 05-23-26

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

Comment thread Project.toml Outdated
@ChrisRackauckas
Copy link
Copy Markdown
Member

Rebase onto master

@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan can you make the correctness test more strict. Compare against Direct, which will probably require a smaller timestep for the leaping methods, and calculate the maximum error over time (say every second) instead of just at the final time.

I’m reading through the references to refresh my memory on how the adaptive stepping works, and will try to finish that tomorrow and give you some more feedback afterwards.

Copy link
Copy Markdown
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sivasathyaseeelan, to speed up review I suggest splitting this into separate PRs for explicit vs. implicit. Let's get explicit merged and then we can work on implicit.

@ChrisRackauckas I think there are some design decisions to be made here for getting at the individual rate functions and stochiometry vectors. So it is just a question if you want to work on that as part of these or as a followup -- I'd defer to what you want, but I don't think these should be advertised until we get that settled and have more extensive testing.

Comment thread Project.toml Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
@sivasathyaseeelan sivasathyaseeelan changed the title SimpleAdaptiveTauLeaping and SimpleImplicitTauLeaping SimpleAdaptiveTauLeaping solver Aug 12, 2025
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl
Copy link
Copy Markdown
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comments:

  1. Please add comments citing the formulas you are using from the original paper for the leap selection.
  2. Please revise with an eye towards making this non-allocating during the solution timestepping, see the examples I've highlighted but keep in mind they are not all the cases of extraneous allocations.

Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread test/regular_jumps.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl Outdated
@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan this PR needs to be updated for the changes I just merged to master.

Comment thread src/simple_regular_solve.jl Outdated
@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan thanks for coming back to this! Let me know when you are done updating.

@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan if tests pass now I'll merge. Thanks again for all your efforts on this one!

Let me know if you return to the implicit one and I can review it once you feel you are done when I have a chance.

@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan seems like the tau-leaping tests are stalling out on 1.10. Have you tested their locally?

@sivasathyaseeelan
Copy link
Copy Markdown
Contributor Author

@sivasathyaseeelan seems like the tau-leaping tests are stalling out on 1.10. Have you tested their locally?

Yes I did, all tests were passing in my local machine

@isaacsas
Copy link
Copy Markdown
Member

And was that in Julia 1.10?

@isaacsas
Copy link
Copy Markdown
Member

isaacsas commented Jan 26, 2026

(i.e. not 1.11 or 1.12)

@isaacsas isaacsas closed this Jan 26, 2026
@isaacsas isaacsas reopened this Jan 26, 2026
@isaacsas
Copy link
Copy Markdown
Member

Let's see if restarting CI fixes it.

@sivasathyaseeelan
Copy link
Copy Markdown
Contributor Author

@isaacsas I think the CI takes too much time to run, https://github.com/SciML/JumpProcesses.jl/actions/runs/21111444469/job/60710583077 here it took more than 5 hrs

@isaacsas
Copy link
Copy Markdown
Member

Right, but that seems to only be an issue in this PR from what I can see. For other PRs it is much less time.

That suggests there is an issue in this PR or the tests when applied to the new code on 1.10.

@sivasathyaseeelan
Copy link
Copy Markdown
Contributor Author

Right, but that seems to only be an issue in this PR from what I can see. For other PRs it is much less time.

That suggests there is an issue in this PR or the tests when applied to the new code on 1.10.

How can I fix this

@isaacsas
Copy link
Copy Markdown
Member

Fixing this requires some debugging work to see why it is occurring, which means figuring out in that test file what is taking so long on 1.10 vs. 1.11. The first step would be trying to run those tests line by line on Julia 1.10 and 1.11 to see if there is somewhere it hangs / takes forever (or use something like Claude Code to investigate the issue after explaining what is wrong).

@isaacsas
Copy link
Copy Markdown
Member

If you aren't able to investigate this I can look into it when I have some time, but probably won't be till later in the week as I am busy with teaching and meetings the next three days.

@sivasathyaseeelan
Copy link
Copy Markdown
Contributor Author

sivasathyaseeelan commented Jan 26, 2026

Thank you @isaacsas. I don't have Claude, But I will try looking into this. If I can't able to debug I will let you know

@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan seems there is a bug in the step rejection logic. See the summary below

Issue: Tau-Leaping Tests Taking 5+ Hours on CI

Problem

The "Tau Leaping Tests" are taking 267 minutes (4h 27m) on CI (Julia 1.10 LTS) but only ~4 seconds locally. This is causing CI failures.

Root Cause

There is a bug in the negative population handling logic in simple_explicit_tau_leaping_loop! at lines 244-248:

if any(<(0), u_new)
    # Halve tau to avoid negative populations, as per Cao et al. (2006), Section 3.3
    tau /= 2
    continue
end

Two Issues:

  1. Halving is ineffective: When continue executes, control returns to line 217 where tau = compute_tau(...) recomputes tau from scratch, overwriting the halved value. The halving has no effect.

  2. No iteration: According to Cao et al. (2005), when negative populations occur, the leap should be rejected and tau halved repeatedly in a loop until either:

    • No negative populations occur, OR
    • tau falls below dtmin

The current implementation relies on getting lucky with different Poisson samples on each retry (since tau is recomputed to the same value). In CI environments, this can cause many ineffective retries.

@isaacsas
Copy link
Copy Markdown
Member

It looks like tests are now passing, which is great! But there is still an issue with the lts tests taking 330m. I'll dig into it when I have a chance, but please feel free to keep looking at it yourself. I don't think we can merge this until we get that straightened out -- that will be too much of a drain on CI time.

@sivasathyaseeelan
Copy link
Copy Markdown
Contributor Author

sivasathyaseeelan commented Feb 3, 2026

It looks like tests are now passing, which is great! But there is still an issue with the lts tests taking 330m. I'll dig into it when I have a chance, but please feel free to keep looking at it yourself. I don't think we can merge this until we get that straightened out -- that will be too much of a drain on CI time.

@isaacsas I fixed the bug. The tests were not properly written and optimized, which was loading the system. Now Tau Leaping Tests are running below 50 sec!

@isaacsas
Copy link
Copy Markdown
Member

@sivasathyaseeelan I'm going to merge this and start a new PR to improve the tests.

I know this was a long haul, thanks for your efforts on it!

@isaacsas isaacsas merged commit 55ee633 into SciML:master Feb 14, 2026
11 checks passed
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.

3 participants