Skip to content

Fix threaded stochastic work-precision race - #4462

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/diffeqdevtools-threaded-sde-workprecision
Sep 7, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/diffeqdevtools-threaded-sde-workprecision

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Ignore until reviewed by @ChrisRackauckas.

What changed and why

WorkPrecisionSet(...; parallel_type = :threads) expanded @error_calculation directly inside a threaded loop. The macro-created locals were captured by the enclosing function, so concurrent stochastic error calculations could replace one another's tolerance and timestep bindings. In mixed adaptive/fixed-step setups, an RKMil solve could therefore receive the adaptive setup's zero/absent timestep and fail nondeterministically.

Move one error calculation into the private module-level _calculate_error! function so every threaded call owns its bindings. Add a regression using an analyticless SDE with adaptive SRIW1 and fixed-step RKMil setups across at least 32 threaded error samples. The same helper also replaces the duplicate macro expansion in get_sample_errors.

No public API or dependency changed.

Failing before the fix

On DiffEqDevTools v3.6.2 (cd5ccd7f8e) with the regression test applied but the implementation reverted:

$ timeout 3600 julia +1.11.9 --startup-file=no --threads=auto --project=.validation/test-env -e 'include("lib/DiffEqDevTools/test/analyticless_stochastic_wp.jl")'
ERROR: TaskFailedException
    nested task error: ArgumentError: Fixed timestep methods require a choice of dt or an algorithm with an automatic dt choice.
    ...
    dt::Nothing
Process exited with status 1
Elapsed: 1:08.77

The clean standalone reproducer passed with one Julia thread and failed with 128 threads. A diagnostic assertion also observed the shared _dts binding change between evaluating a condition and capturing its value.

Passing after the fix

The exact official test file passes with 128 threads:

$ timeout 3600 julia +1.11.9 --startup-file=no --threads=auto --project=.validation/test-env -e 'include("lib/DiffEqDevTools/test/analyticless_stochastic_wp.jl")'
Test Summary:              | Pass  Total     Time
Analyticless Stochastic WP |    4      4  6m18.9s
Process exited with status 0

An independent clean worktree repeated that test successfully in 6m40s. A 10-trial standalone threaded reproducer also completed all trials successfully in 46.95s; an independent clean worktree repeated it in 57.54s.

The SciMLBenchmarks page that originally exposed the race completed against this local source:

$ timeout 7200 julia +1.11.9 --startup-file=no --threads=auto --project=.validation/root-env -e 'using SciMLBenchmarks; SciMLBenchmarks.weave_file("benchmarks/NonStiffSDE", "LotkaVolterraSDE.jmd", (:script, :github))'
Process exited with status 0
Elapsed: 38:25.48
Maximum resident set size: 133256684 kbytes

The generated Markdown referenced four valid 576×384 PNGs. Inspection found all strong-error, weak-error, and sample-error curves populated and no runtime error markers.

Local verification

$ GROUP=QA timeout 3600 julia +1.11.9 --startup-file=no --threads=auto --project=lib/DiffEqDevTools -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total  Time
QA            |   15     15  36.1s
Testing DiffEqDevTools tests passed
Process exited with status 0 (elapsed 1:47)

$ GROUP=Core timeout 7200 julia +1.11.9 --threads=auto --project=lib/DiffEqDevTools -e 'using Pkg; Pkg.test()'
Test Summary:              | Pass  Total     Time
Analyticless Stochastic WP |    4      4  7m20.0s
...
Test Summary: | Pass  Total  Time
Timeout       |    7      7  4.2s
Testing DiffEqDevTools tests passed
Process exited with status 0 (elapsed 19:36.78; max RSS 7519644 kbytes)

$ julia +1.11.9 --project=/home/crackauc/.julia/environments/runic -e 'using Runic; exit(Runic.main(["--check", "lib/DiffEqDevTools/src/DiffEqDevTools.jl", "lib/DiffEqDevTools/src/benchmark.jl", "lib/DiffEqDevTools/test/analyticless_stochastic_wp.jl"]))'
$ typos lib/DiffEqDevTools/src/DiffEqDevTools.jl lib/DiffEqDevTools/src/benchmark.jl lib/DiffEqDevTools/test/analyticless_stochastic_wp.jl
$ git diff --check

All three final checks exited 0 with no output.

Not verified

No GPU or downstream test groups were run. Documentation was not built because this changes no public API, docstring, or documentation source.

🤖 Generated with Claude Code
https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 7, 2026 06:19
@ChrisRackauckas
ChrisRackauckas merged commit 73c7203 into SciML:master Sep 7, 2026
132 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- DiffEqBase: wrap mass-matrix problems on the finite-difference promote_f path (#4459)
- Preserve the DAE step start during callback interpolation (#4466)
- Release DiffEqBase 7.20.1 (#4474)
- Release OrdinaryDiffEqCore 4.16.1 (#4475)
- Release OrdinaryDiffEqNonlinearSolve 2.9.5 (#4476)
- Run IDSolve's nonlinear solve at the integrator's tolerances (#4468)
- Build W through the allocating path for a sparse GPU Jacobian with a scalar mass matrix (#4452)
- Fix threaded stochastic work-precision isolation (#4462)
- Differentiate wrapped DAEFunctions with chunk size 1, like ODEFunctions (#4464)
- Rebuild MethodOfSteps W after history updates (#4396)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[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.

2 participants