Skip to content

Fix PDIRK threading option checks - #4745

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:pdirk-threading-predicate
Oct 17, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:pdirk-threading-predicate

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

alg_cache now uses OrdinaryDiffEqCore’s public isthreaded predicate, matching the threading checks already used by both PDIRK perform_step! methods. The regression test constructs and solves with false, true, Sequential(), BaseThreads(), and PolyesterThreads(), and asserts identical final results; Polyester is declared as a test extra so its extension loads during the test.

The regression fails on the unfixed code: Sequential() throws TypeError: non-boolean (OrdinaryDiffEqCore.Sequential) used in boolean context from pdirk_caches.jl. After the fix, the test file passes 13/13 assertions on Julia 1.12.4 with both default threading and JULIA_NUM_THREADS=4; the package test suite also passes on Julia 1.10.12.

Pinned @benchmark minima (5 samples, 1 eval/sample; taskset -c 24 for one Julia thread and taskset -c 24-27 for four), comparing the existing threading=true path with the newly enabled PolyesterThreads() path:

Workload Julia threads true / BaseThreads PolyesterThreads()
LIN1000 1 0.02168 s 0.02116 s
VdP 1 0.3833 s 0.1672 s
LIN1000 4 0.02368 s 0.01226 s
VdP 4 8.645 s 0.2034 s

The benchmark minima varied with shared-host load; use the four-thread VdP result as indicative rather than a stable speedup estimate. step! allocations (same order) were LIN1000 12,440→9,928 bytes and VdP 3,872→1,360 bytes at one thread; LIN1000 18,952→12,072 bytes and VdP 8,720→3,184 bytes at four threads.

Validation tails:

  • Pkg.test() on Julia 1.12.4: SciMLBase reexport 2/2; Convergence Tests 4/4; nlsolve! Arguments 13/13; Core Interface Tests 3/3; Allocation Tests 1 existing broken check; JET Tests 1/1; Aqua 21/21; package tests passed.
  • JULIA_NUM_THREADS=4 GROUP=Core julia --project=lib/OrdinaryDiffEqPDIRK -e 'using Pkg; Pkg.test()': package tests passed, including nlsolve! Arguments 13/13.
  • Julia 1.10.12, fresh scratch test environment: package tests passed, including nlsolve! Arguments 13/13.
  • julia --project=@runic -m Runic --inplace lib/OrdinaryDiffEqPDIRK/src/pdirk_caches.jl lib/OrdinaryDiffEqPDIRK/test/nlsolve_argument_tests.jl and typos on all three changed files: exit 0.

Not verified: downstream packages. The performance samples ran on a shared host and were not benchmarked under controlled isolation. Polyester’s upstream MIT license is compatible with this package’s license.

Please push back on whether Polyester belongs in this sublibrary’s test extras and on the interpretation of the shared-host benchmark spread.

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

  • Risk: low
  • Blast radius: PDIRK44 cache construction and stage threading choices; no public API changes.
  • Evidence: regression fails before and passes after; package tests and QA pass; pinned benchmark minima and step allocations are listed above.
  • Independent review: pending
  • Merge: needs human review while independent review is pending and benchmark variability is high.

🤖 Generated with Codex CLI codex-cli 0.160.0 (model: gpt-6-luna), transcript on a fleet worker host; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Risk assessment

  • Risk: low

  • Blast radius: Only PDIRK44 cache construction in lib/OrdinaryDiffEqPDIRK. threading = true/false behave as before, since isthreaded(::Bool) returns the Bool unchanged. Sequential(), BaseThreads() and PolyesterThreads() used to throw a TypeError in alg_cache; they now work and pick the same branch that perform_step! already took. This is a fix that adds working inputs, so SemVer patch is fine. Polyester becomes a test-only extra (compat = "0.7", MIT), with no new runtime dependency. isthreaded was already imported, and isthreaded, Sequential, BaseThreads and PolyesterThreads are all declared public in OrdinaryDiffEqCore, so no non-public internals are used. No tests were weakened: the existing loop gains three threading options and an exact-equality check across all five.

  • Evidence: Four checks fail on head fa9a8de. All four also fail on the merge base 217e0ad and on every recent master commit that ran them (75bc9df, e70688, bd6cfb3, 4a5c0e7; GPU didn't report on bd6cfb3), so all are pre-existing:

    • SciMLSensitivity.jl/Core1 downstream: Mooncake Error During Test at concrete_solve_derivatives.jl:451.
    • downgrade-sublibraries lib/DiffEqBase and lib/OrdinaryDiffEqDifferentiation: fail during downgrade resolution.
    • tests / GPU (Julia 1): 3 failed, 170 passed.

    None of the failure logs involve PDIRK. Every PDIRK-specific check passes: sublibrary-ci Core on Julia 1, lts and pre; QA on Julia 1; and downgrade lib/OrdinaryDiffEqPDIRK. Runic, Typos, Documentation and the other ~120 checks pass too. The PR has no review comments. Not disclosed in the description:

    • The four pre-existing red checks.
    • The PDIRK44 docstring still documents threading as Bool-only. It doesn't mention the Sequential()/BaseThreads()/PolyesterThreads() options this PR makes work.
    • Neither docstring nor description mentions that PolyesterThreads() needs Polyester to be loaded.
  • Independent review: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence: a two-line swap to OrdinaryDiffEqCore's public isthreaded, consistent with the existing perform_step! checks, with a stronger regression test and no regressions against master.

  • Merge: auto-merge candidate. It meets the no-regression bar, but the PR is still a draft and its description says to wait for review by @ChrisRackauckas. It needs to be marked ready and that hold lifted first. A docstring update for the non-Bool threading options would be worth a follow-up.


🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Devin CLI 3000.11.3 fleet-master caretaker, model Fusion (claude-opus-5-5 medium + swe-2 medium)
Conversation: local session speckle-whale (no session URL)

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Risk assessment (independent review, Codex gpt-6.1-sol, head 7055eba)

  • Verdict: MERGE
  • Risk: medium-low (ML8: changes threading-dependent nonlinear-solver cache selection; the regression catches the initialization failure and existing results are unchanged). L2 and L6 also match; ML8 is the highest matched criterion.
  • Blast radius: PDIRK44 initialization, both in-place and out-of-place, for Sequential(), BaseThreads(), and PolyesterThreads(). This is a peripheral solver, not OrdinaryDiffEq's main lanes. Existing false/true calls retain their cache selection and results. No new public names, signatures, defaults, or breaking behavior; isthreaded is public and documented. Polyester is an MIT-licensed test extra, with no new runtime dependency. No tests are skipped, removed, or loosened by the diff.
  • Evidence: Read pr.txt, the complete risk policy, and git diff origin/HEAD...HEAD; inspected the cache constructors, both stage implementations, threading dispatch/extension, documentation, and package test wiring. git diff --check origin/HEAD...HEAD passes. All Julia checks used Julia 1.13.2, JULIA_NUM_THREADS=4, JULIA_NUM_PRECOMPILE_TASKS=4, the requested depot overlay, --startup-file=no --compiled-modules=existing, and timeout 3600, serially in scratch snapshots. bash scratch/run-checks.sh records every command and exit status in scratch/results.txt:
    • julia --project=scratch/env-head scratch/run-functional.jl scratch/head: includes the package's official test/runtests.jl with GROUP=Core, exercising every functional testset and excluding QA; 36/36 pass, including 13/13 in the changed test file (scratch/head-functional.log).
    • julia --project=scratch/env-base scratch/run-regression.jl scratch/head/lib/OrdinaryDiffEqPDIRK/test/nlsolve_argument_tests.jl: runs the exact head regression against default-branch source at 0139bdc23709266d93ebadf377d63484886d1478; exits 1, with four passing assertions followed by TypeError: non-boolean (Sequential) used in boolean context at pdirk_caches.jl:108 (scratch/base-regression.log).
    • julia --project=scratch/env-base scratch/run-functional.jl scratch/base: unmodified default-branch functional suite 29/29 pass (scratch/base-functional.log).
    • julia --project=scratch/env-head scratch/accuracy.jl: 114/114 pass. All five threading options, in-place and out-of-place, converge against the independently derived solution exp(-t)/(1 + 0.1*(1-exp(-t))); measured orders are 3.9226–3.9455, with final error about 3.49e-9 at dt=0.025. Additional tests verify distinct nonlinear-solver objects and mutable buffers for threaded caches, and repeat coupled-vector solves against a matrix exponential five times per option (scratch/head-accuracy.log).
    • julia --project=scratch/env-{head,base} scratch/bool-results.jl, run separately: both exit 0. cmp scratch/head-bool.log scratch/base-bool.log exits 0: all saved solution values match exactly for both Boolean options and both problem forms.
    • G1 pass: independent analytic convergence and matrix-exponential accuracy evidence, in addition to the existing convergence suite; no formula or step-control changes.
    • G2 not applicable: no changed GPU kernels, AD rules, Reactant tracing, or MPI paths. Both CPU threading backends are exercised, including the loaded Polyester extension.
    • G3 pass: the committed test fails on the invalid threading/cache selection before the fix and passes afterward; supplemental cache-isolation and repeated threaded-solve assertions also pass with four threads.
  • Merge: merge (no actionable findings; medium-low review-count and harness requirements still apply).

🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Risk assessment (independent review, Claude Opus 5.5 (claude-opus-5-5), head 7055eba)

  • Verdict: MERGE
  • Risk: medium-low (ML8: the change picks between shared and per-stage nonlinear-solver caches based on the threading option. A test catches the failure, and results are unchanged. L6 and L2 also match, but ML8 is the highest.)
  • Blast radius: Only PDIRK44 cache construction (in-place and out-of-place) in lib/OrdinaryDiffEqPDIRK. This is a peripheral solver, not a main lane. isthreaded(::Bool) returns the Bool unchanged, so true/false callers are unaffected. The three non-Bool options used to error and now run. There are no public signature changes and no new public names. isthreaded was already imported from OrdinaryDiffEqCore, and the test imports Sequential/BaseThreads/PolyesterThreads from OrdinaryDiffEqPDIRK, which declares them public (src/OrdinaryDiffEqPDIRK.jl:48). Polyester (MIT) is added as a test extra only, with no new runtime dependency. A patch-level SemVer bump is appropriate.
  • Evidence: Scratch environments developed the local DiffEqBase, OrdinaryDiffEqCore, OrdinaryDiffEqDifferentiation, OrdinaryDiffEqNonlinearSolve and OrdinaryDiffEqPDIRK, for the head and for the merge base 59ba40e4b (git archive). I used Julia 1.12, JULIA_NUM_THREADS=4 and timeout 3600.
    • Head test/nlsolve_argument_tests.jl on head sources: exit 0, 11/11 + 2/2 pass.
    • The same head test file on base sources: exit 1, 4 passed and 1 errored with TypeError: non-boolean (Sequential) used in boolean context. It fails before and passes after.
    • GROUP=Core head test/runtests.jl: exit 0. SciMLBase reexport 2/2, Convergence 4/4, nlsolve! Arguments 13/13, Core Interface 3/3, Resize Cache 14/14.
    • scratch/extra.jl, a check of my own with values the code did not produce: for each of false, true, Sequential(), BaseThreads() and PolyesterThreads(), the error against the analytic solution exp(-t)/(1+0.1(1-exp(-t))) at dt = 0.1/0.05/0.025 is identical across options (8.16e-7, 5.38e-8, 3.49e-9). The observed orders are 3.92 and 3.95. A 4×4 linear system was solved 5 times per option and matched exp(A)*u0 to within 1e-7. For the threaded options, cache.nlsolver[1] !== cache.nlsolver[2] and their tmp buffers are distinct. All 36 assertions pass.
    • G1 pass: analytic-solution convergence and matrix-exponential accuracy, independent of the code, for all options. No formula or step-control change.
    • G2 not applicable: no GPU, AD, Reactant or MPI path is touched. Both CPU threading backends ran, with the Polyester extension loaded.
    • G3 pass: the committed test fails on the wrong threading/cache selection before the fix and checks bitwise-equal results across all five options. My extra run, with 4 threads, confirmed that threaded runs get separate nlsolver objects and buffers, and that repeated threaded solves stay accurate.
    • Failing CI check (SciMLSensitivity Core4 downstream): not verified against master, because GitHub calls were disallowed. In the local SciMLSensitivity 7.118.1 source, Core4 (distributed, ensembles, layers, SDE/DDE) never references PDIRK or threading. PDIRK appears only in Core2 (stiff_adjoints.jl), so this PR is very unlikely to be the cause.
  • Merge: merge, provided the Core4 downstream failure is confirmed to be pre-existing on master (findings 2 and 3 do not block).

🤖 Posted by an AI agent — harness: Claude Code · model: claude-opus-5-5
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Risk assessment (independent review, Devin CLI 3000.11.92 / fusion-claude-opus-5-5-high-sidekick-swe-2-medium, head 7055eba)

  • Verdict: MERGE
  • Risk: medium-low (ML8: the change decides which threaded cache layout, one shared nlsolver or two independent ones, each threading option gets. Results are unchanged, and the committed test would catch the risky failure: a cache/branch mismatch, which shows up as a BoundsError or wrong results. L6 and L2 also match, but ML8 is the highest.)
  • Blast radius: Only PDIRK44 cache construction (lib/OrdinaryDiffEqPDIRK), in-place and out-of-place. PDIRK44 is a peripheral, non-adaptive solver, not an OrdinaryDiffEq main lane. threading = true/false: isthreaded(::Bool) is the identity, so these go through the same code as before, and I confirmed the results are bitwise equal to base. The three AbstractThreadingOption values used to throw at init; now they work. That is SemVer patch: no input that used to work is rejected. Polyester is added only as a test extra (compat = "0.7", MIT); there is no new runtime dependency. isthreaded, Sequential, BaseThreads and PolyesterThreads are all public in OrdinaryDiffEqCore, PDIRK already imported them at base, and they exist well below the OrdinaryDiffEqCore = "4.13" floor (isthreaded(::Sequential) goes back to 4fc9a86, 2024-08-05). No tests are skipped, removed or loosened.
  • Evidence: Scratch snapshots of HEAD and origin/HEAD (98fa051) are under scratch/{head,base}; between the merge base and origin/HEAD no PDIRK/Core/NonlinearSolve/Differentiation src file changes. Each snapshot got its own environment, with the local DiffEqBase, OrdinaryDiffEqCore, OrdinaryDiffEqDifferentiation, OrdinaryDiffEqNonlinearSolve and OrdinaryDiffEqPDIRK developed, plus Polyester 0.7.19 and SciMLBase 3.58.0. Everything ran on Julia 1.13.2 with JULIA_NUM_THREADS=4.
    • The head's test/nlsolve_argument_tests.jl run against base source exits 1: 4 pass, then TypeError: non-boolean (Sequential) used in boolean context at pdirk_caches.jl:108 (scratch/base-regression.log). The same file on head exits 0: 11/11 + 2/2 (scratch/head-regression.log).
    • scratch/stress.jl on head exits 0, all testsets pass (scratch/head-stress.log). It checks three things for all five threading options, in-place and out-of-place:
      • (a) A 20-dim tridiagonal linear system against exp(A*T)*u0: error 1.11e-7 at dt=0.025, observed order 3.82, identical for every option.
      • (b) A 200-dim nonlinear problem u' = B*u - u.^3 solved 30 times per option at 4 threads: 0 mismatches, bitwise, against the Sequential() result.
      • (c) init(...).cache.nlsolver has 2 distinct nlsolvers (distinct tmp and cache) for the threaded options and 1 otherwise. The Polyester extension was confirmed loaded.
    • scratch/boolcmp.jl ran on base and on head (6 solutions: three problems × false/true). The deserialised outputs are bitwise equal (a == b → true).
    • CI at 7055eba: all PDIRK jobs pass (sublibrary Core on Julia 1/lts/pre, PDIRK QA, downgrade lib/OrdinaryDiffEqPDIRK). The only red check is SciMLSensitivity.jl/Core4 (https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38862093679/job/116846462520): AssertionError: mi2 !== nothing in Core4/ensembles.jl:19 under EnsembleThreads(), "15 passed, 0 failed, 1 errored, 2 broken". I compared it against master: the identical error and summary appear on master 8d8191b (job 117424176936) and 0139bdc (job 117316399249), and Core4 also fails on master 22da966, d727918 and 53e7d1d. So it predates this PR and has nothing to do with PDIRK.
    • G1 pass: independent matrix-exponential reference, fourth-order convergence, and Bool results bitwise unchanged against base.
    • G2 not applicable: no GPU, AD-rule, Reactant or MPI code changed. Both CPU threading backends (Base and Polyester) were exercised at 4 threads.
    • G3 pass: the risk is a mismatch between the cache layout and the perform_step! branch, and the committed test catches it deterministically at any thread count (it errors before the fix). The test also asserts exact equality across all five options. My 4-thread repeated-solve check found no shared-buffer race.
  • Independent review: Devin CLI 3000.11.92 / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it medium-low (ML8) at head 7055eba, high confidence: a two-line switch to the public isthreaded predicate, which makes the cache layout agree with the existing perform_step! branch. It fails before and passes after, Bool paths are bitwise unchanged, and the only red CI check also fails on master.
  • Merge: merge. The PR is still a draft carrying the standard "please ignore until reviewed" banner. Medium-low needs two smart reviews, on harnesses different from each other and from the author. The author's harness is Codex CLI, so the earlier Codex gpt-6.1-sol review may not count toward that.

🤖 Posted by an AI agent — harness: Devin CLI 3000.11.92 · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local headless Devin review run (no public session URL); transcript kept by the fleet master.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI codex-cli 0.160.0
Agent-Model: gpt-6-luna
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-pdirk-threading/log.txt on amdci2
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration)
Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_OrdinaryDiffEq.jl-4745/log.txt
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Merged the default branch into this PR (clean merge, no conflicts; head 491d6c4) so CI runs on current master. Its earlier failures in SciMLSensitivity Core1 and the downgrade jobs were fixed on master after this PR's last CI run.


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

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