Skip to content

SimpleImplicitTauLeaping solver - #500

Closed
sivasathyaseeelan wants to merge 1 commit into
SciML:masterfrom
sivasathyaseeelan:kernel-implicit-tau
Closed

sivasathyaseeelan wants to merge 1 commit into
SciML:masterfrom
sivasathyaseeelan:kernel-implicit-tau

Conversation

@sivasathyaseeelan

@sivasathyaseeelan sivasathyaseeelan commented Jul 23, 2025 •

Copy link
Copy Markdown
Contributor

Adds SimpleImplicitTauLeaping, an implicit tau-leaping method for stiff pure-jump problems.

Explicit tau-leaping is limited by the fastest reaction in the system, so a stiff model forces a step size far below the timescale of interest. Each step here instead solves a nonlinear equation for the state at the end of the step, following Rathinam et al. (2003) and Cao et al. (2004), and the leap is then sampled from the propensities at that predicted state.

using JumpProcesses

# stiff reversible isomerization A <-> B
maj = MassActionJump([100.0, 100.0], [[1 => 1], [2 => 1]],
                     [[1 => -1, 2 => 1], [1 => 1, 2 => -1]])
prob = DiscreteProblem([100.0, 100.0], (0.0, 1.0))
jprob = JumpProblem(prob, PureLeaping(), maj)

sol = solve(jprob, SimpleImplicitTauLeaping())                                  # fully implicit
sol = solve(jprob, SimpleImplicitTauLeaping(solver = TrapezoidalImplicitSolver()))

Two formulations are selected with the solver keyword. NewtonImplicitSolver takes the step in its fully implicit form, while TrapezoidalImplicitSolver averages the propensities at the current and new states, which damps the excessive stiffness of the fully implicit step.

Notes on this revision

This has been rebased onto current master, which in the meantime merged SimpleExplicitTauLeaping. The step-size selection (compute_hor, compute_gi, compute_tau), the mass action rate construction and the saveat handling are now shared with it rather than redefined, and validate_pure_leaping_inputs is widened to cover both algorithms instead of gaining a second identical method.

Two problems from the earlier revision are fixed:

  • A non-convergent step could spin forever. The retry path halved tau and then continued, but tau is recomputed from compute_tau at the top of each iteration, so the halved value was discarded. The explicit loop survives the same shape because its retries redraw the Poisson counts, but the implicit solve is deterministic in (u_current, tau) and would fail identically on every pass. The bound is now carried across iterations, and once tau reaches dtmin a non-convergent step is reported as an error rather than silently accepted.
  • Setfield was declared as a dependency but never used, which Aqua's stale-dependency check flags.

The algorithm type is also now fully parameterized (SimpleImplicitTauLeaping{T, S}) rather than holding an abstractly-typed solver field, and the residual evaluation reuses preallocated propensity caches instead of allocating on each call.

Testing

The existing SIR and SEIR mean-trajectory comparisons in test/regular_jumps.jl are extended to both implicit formulations, checked against the exact SSA solution at every saved timepoint.

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

Comment thread ext/implicit_tau.jl Outdated
@sivasathyaseeelan sivasathyaseeelan changed the title Kernels for ImplicitTauLeaping ImplicitTauLeaping solver and Kernels Jul 24, 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 ext/implicit_tau.jl Outdated
@sivasathyaseeelan sivasathyaseeelan changed the title ImplicitTauLeaping solver and Kernels ImplicitTauLeaping solver Aug 9, 2025
@sivasathyaseeelan sivasathyaseeelan changed the title ImplicitTauLeaping solver SimpleAdaptiveTauLeaping and SimpleImplicitTauLeaping Aug 9, 2025
@sivasathyaseeelan sivasathyaseeelan changed the title SimpleAdaptiveTauLeaping and SimpleImplicitTauLeaping SimpleImplicitTauLeaping solver Aug 14, 2025
@sivasathyaseeelan sivasathyaseeelan changed the title SimpleImplicitTauLeaping solver Draft: SimpleImplicitTauLeaping solver Aug 14, 2025
Comment thread Project.toml Outdated
Comment thread src/simple_regular_solve.jl Outdated
Comment thread src/simple_regular_solve.jl
@sivasathyaseeelan sivasathyaseeelan changed the title Draft: SimpleImplicitTauLeaping solver SimpleImplicitTauLeaping solver Sep 5, 2025
@sivasathyaseeelan
sivasathyaseeelan force-pushed the kernel-implicit-tau branch 4 times, most recently from 6d16ed3 to 5459dd9 Compare February 14, 2026 19:36
Explicit tau-leaping is restricted by the fastest reaction in the system, so a
stiff model forces a step size far below the timescale of interest. This adds an
implicit method that instead solves a nonlinear equation for the state at the end
of each step, following Rathinam et al. (2003) and Cao et al. (2004), and then
samples the leap from the propensities at that predicted state.

Two formulations are available, selected with the `solver` keyword:
`NewtonImplicitSolver` takes the step in its fully implicit form, while
`TrapezoidalImplicitSolver` averages the propensities at the current and new
states, which damps the excessive stiffness of the fully implicit step.

The step-size selection, mass action rate construction and `saveat` handling are
shared with `SimpleExplicitTauLeaping` rather than duplicated, and the existing
`validate_pure_leaping_inputs` method is widened to cover both algorithms.

A step is rejected and `tau` halved when the nonlinear solve fails to converge.
The bound is carried across loop iterations: unlike the explicit loop, whose
retries redraw the Poisson counts, the implicit solve is deterministic in
`(u_current, tau)`, so retrying at an unchanged `tau` would fail identically and
spin forever. Once `tau` reaches `dtmin` a non-convergent step is reported as an
error instead of being silently accepted.

Tests extend the existing SIR and SEIR mean-trajectory comparisons to both
implicit formulations, checking them against the exact SSA solution.

"""
$(TYPEDEF)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is weird, just make it SimpleImplicitTauLeaping and SimpleTrapezoidalLeaping

@ChrisRackauckas

Copy link
Copy Markdown
Member

Pretty much done, I've got it from here.

@ChrisRackauckas

Copy link
Copy Markdown
Member

I took the commit from here and finished it in #643

@ChrisRackauckas

Copy link
Copy Markdown
Member

Thanks! Your commit is credited with your authorship for doing like 99% of the work.

@sivasathyaseeelan

Copy link
Copy Markdown
Contributor Author

Thanks Chris, and thanks for finishing it in #643.

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