Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

This PR implements the change requested in #464 - stopping the automatic reseeding of the RNG on every call to solve.

Problem

Previously, JumpProcesses would reseed the RNG with rand(UInt64) on every call to solve when:

  • seed === nothing (no explicit seed provided)
  • alias_jump == false (i.e., when not on the main thread, or when deepcopying the problem)

This led to non-reproducible results because it didn't respect the user's RNG choice.

Solution

  • Modified resetted_jump_problem in src/solve.jl to only reseed when an explicit seed is provided
  • Modified DiffEqBase.__init in src/SSA_stepper.jl similarly
  • Updated test/ensemble_uniqueness.jl to use prob_func with explicit seeds for each trajectory

Breaking Change

This is a breaking change as noted in #464. For EnsembleProblems that require different trajectories, users should now use prob_func to set unique seeds for each trajectory. This gives users full control over reproducibility.

Example of the new pattern for EnsembleProblems:

using JumpProcesses, StableRNGs

function make_seeded_prob_func(dprob, aggregator, jumps, base_rng)
    return function prob_func(prob, i, repeat)
        seed = rand(base_rng, UInt64)
        JumpProblem(dprob, aggregator, jumps...; rng = StableRNG(seed))
    end
end

# Create JumpProblem
jump_prob = JumpProblem(dprob, Direct(), j1, j2)

# Create EnsembleProblem with unique RNG per trajectory
ensemble_rng = StableRNG(99999)  # seeded for reproducibility
ensemble_prob = EnsembleProblem(jump_prob;
    prob_func = make_seeded_prob_func(dprob, Direct(), (j1, j2), ensemble_rng))
sol = solve(ensemble_prob, SSAStepper(), trajectories = 10)

Test plan

  • All existing tests pass (verified locally)
  • Updated test/ensemble_uniqueness.jl to demonstrate the new pattern
  • CI should pass

Fixes #464

cc @ChrisRackauckas

🤖 Generated with Claude Code

This is a breaking change that improves reproducibility for JumpProcesses.

Previously, JumpProcesses would reseed the RNG with `rand(UInt64)` on every
call to solve when `seed === nothing` and `alias_jump == false` (i.e., when
not on the main thread). This led to non-reproducible results because it
didn't respect the user's RNG choice.

Changes:
- Modified `resetted_jump_problem` in src/solve.jl to only reseed when an
  explicit seed is provided
- Modified `DiffEqBase.__init` in src/SSA_stepper.jl similarly
- Updated test/ensemble_uniqueness.jl to use `prob_func` with explicit
  seeds for each trajectory, which is the recommended pattern for
  EnsembleProblems that need different results per trajectory

For EnsembleProblems that require different trajectories, users should now
use `prob_func` to set unique seeds for each trajectory. This gives users
full control over reproducibility.

Fixes SciML#464

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.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.

stop reseeding each call to solve

2 participants