Skip to content

Make mass-matrix identity/zero/diagonal checks GPU-safe (fix Julia 1.13 GPU DAE scalar-indexing regression) - #4502

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/gpu-diag-mass-scalar-indexing
Sep 11, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/gpu-diag-mass-scalar-indexing

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the Julia-1.13 regression that broke every mass = diag case in test/gpu/dae_tests.jl (136 failures, all solvers × all three Jacobian variants) with Scalar indexing is disallowed.

Root cause. Julia 1.13 changed ==(A::AbstractMatrix, J::UniformScaling) to read first(A) before dispatching to iszero(A)/isone(A) reductions (LinearAlgebra/src/uniformscaling.jl). On Julia ≤ 1.12 the same comparison called isone(D::Diagonal)/iszero, which reduce over D.diag as GPU kernels. So f.mass_matrix != I in OrdinaryDiffEqCore._ode_init — and every other by-value mass-matrix/identity comparison — now scalar-indexes Diagonal{T, <:CuVector} and throws. The upstream change is JuliaLang/LinearAlgebra.jl#1369 ("Check for elementwise equality when comparing with UniformScaling", commit 3537c3ae), first released in Julia 1.13. This is a Julia-version regression, not an OrdinaryDiffEq commit: none of the recent mass-matrix/W-construction commits (386f6c5, c241543, 01e4cc6, 4b1c5c4) are implicated.

Fix. New GPU-safe helpers on OrdinaryDiffEqCore's public solver-author surface (next to find_algebraic_vars_eqs):

  • _is_identity_massmatrix(mm) — mm == I without scalar indexing (isone(λ) for UniformScaling, all(isone, mm.diag) for Diagonal, direct == for fast-scalar-indexing matrices, host Matrix copy fallback otherwise)
  • _is_zero_massmatrix(mm) — replaces all(isequal(0), mm) (same iteration problem)
  • _diff_alg_vars(mm, n) — differential/algebraic index split replacing findall(i -> mm[i,i] != 0, 1:n) loops in HybridExplicitImplicitRK/Tsit5DA cache and step code

applied at every mass_matrix != I/== I site: _ode_init (isdae and the mass-matrix-alg guard), ode_determine_initdt, OrdinaryDiffEqDefault autoswitch, StochasticDiffEqCore validation, and OrdinaryDiffEqFIRK perform-step. Diagonal-based dispatch serves Diagonal{T, <:CuVector} on CUDA identically.

Regression test

test/InterfaceV/gpu_dae_mass_matrix_tests.jl (registered in the InterfaceV group): solves the gpu/dae_tests.jl DAE with Diagonal{Int64, JLArray{Int64,1}} mass matrix + BrownFullBasicInit under 11 stiff solvers (Rosenbrock23, ROS2, Rodas5P, SDIRK2, Cash4, Hairer4, ABDF2, QNDF2, QBDF2, FBDF, ImplicitEuler), comparing against the CPU reference. JLArray enforces GPUArrays' no-scalar-indexing rules on CPU. The test also emulates CUDA.jl's to_index(::CuArray, ::AbstractArray{Bool}) = findall(I) rule (JLArrays lacks it) so the view(u, bool_mask) calls in BrownFullBasicInit behave as on CUDA.

Test plan / verification

Local env has no CUDA GPU, so verification uses JLArray (GPUArrays' CPU reference backend, same scalar-indexing rules).

Before (master @ 0f08fbd, Julia 1.13.0-rc4) — new test file:

GPU-emulated (JLArray) diagonal-mass-matrix DAE: Error During Test
  Got exception outside of a @test
  Scalar indexing is disallowed.
  Invocation of getindex resulted in scalar indexing of a GPU array.
  ...
    [10] ==(A::Diagonal{Int64, JLArray{Int64, 1}}, J::UniformScaling{Bool})
       @ LinearAlgebra .../stdlib/v1.13/LinearAlgebra/src/uniformscaling.jl:354
    [12] _ode_init(...) @ OrdinaryDiffEqCore .../OrdinaryDiffEqCore/src/solve.jl:288

After (this branch, Julia 1.13.0-rc4) — same file:

Test Summary:                                   | Pass  Total     Time
GPU-emulated (JLArray) diagonal-mass-matrix DAE |   22     22  4m03.9s

Same script on Julia 1.10 (lts): all 11 solvers Success on JLArray, max |u_end - cpu| ≤ 1.2e-4 (Rosenbrock23: 5.7e-6).

Caveats: GPU (test/gpu/dae_tests.jl) and docs builds cannot run locally (no GPU; docs env not instantiated). The JLSparseMatrixCSC/CSR prototypes hit a JLArrays-only CanonicalIndexError in GPUSparseDeviceMatrix*, so the regression test covers jac = none; the CSC/CSR fixes go through the same helpers. Runic --check passes on all touched files; typos clean; ExplicitImports clean on OrdinaryDiffEqDefault/FIRK/StochasticDiffEqCore (OrdinaryDiffEqCore flags only its documented ignore-list names; the pre-existing "public API is rendered in docs" QA failure on master is unrelated).

🤖 Generated with Devin (harness: Devin CLI 3000.10.21, model: SWE-2 High). Session: local Devin CLI session (no shareable URL); session db at /home/crackauc/.local/share/devin/cli/sessions.db.

On Julia 1.13, `==(A::AbstractMatrix, ::UniformScaling)` reads `first(A)`
before falling back to `iszero`/`isone` reductions, so `f.mass_matrix != I`
in `_ode_init` (and in `ode_determine_initdt`) scalar-indexes GPU-backed
mass matrices such as `Diagonal{T, <:CuVector}`, failing with "Scalar
indexing is disallowed". On Julia 1.12 and earlier, `==` dispatched to
`isone(A)`/`iszero(A)`, which reduce via GPU kernels, so the GPU DAE suite
worked; this is why every `mass = diag` case in test/gpu/dae_tests.jl
started failing on Julia 1.13.

Add GPU-safe helpers to OrdinaryDiffEqCore's public solver-author surface
(alongside `find_algebraic_vars_eqs`):

- `_is_identity_massmatrix(mm)`: `mm == I` without scalar indexing
- `_is_zero_massmatrix(mm)`: all-zero check without scalar indexing
- `_diff_alg_vars(mm, n)`: differential/algebraic index split without
  `mm[i, i]` loops

and use them at every site that compared the mass matrix to `I` by value
(OrdinaryDiffEqCore solve/initdt guards, OrdinaryDiffEqDefault autoswitch,
StochasticDiffEqCore validation, OrdinaryDiffEqFIRK perform-step) or
scanned its diagonal elementwise (HybridExplicitImplicitRK/Tsit5DA cache
build and step).

Regression test: test/InterfaceV/gpu_dae_mass_matrix_tests.jl solves the
gpu/dae_tests.jl problem with a `Diagonal{T, <:JLArray}` mass matrix under
BrownFullBasicInit and 11 stiff solvers. JLArray enforces GPUArrays'
no-scalar-indexing rules on CPU, so it fails on master with "Scalar
indexing is disallowed" and passes on this branch. `Diagonal` is
dispatched to `all(isone, mm.diag)`-style reductions, so the same code
path serves `Diagonal{T, <:CuVector}` on CUDA.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 High
Agent-Session: local Devin CLI session (no shareable URL); session db at /home/crackauc/.local/share/devin/cli/sessions.db
@ChrisRackauckas
ChrisRackauckas merged commit c44595d into SciML:master Sep 11, 2026
251 of 268 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



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]>
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



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]>
ChrisRackauckas referenced this pull request Sep 12, 2026
- Add serial SDC solver family (OrdinaryDiffEqSDC) (#4208)
- Give each threaded complex stage its own JVP operator (#4430)
- Fix the adaptive error estimates of MRIGARKERK22a and MIS (#4232)
- Skip sparsity prep for matrix-free jac_prototype operators (#4445)
- Format differentiation tests (#4446)
- Fix SciMLBase reexport QA on Julia LTS (#4450)
- Preserve conditioning in OOP no-init solves (#4438)
- Read the test group from GROUP like the CI passes it (#4447)
- Raise root GPU test timeout (#4449)
- Fix default SDE dt vector lengths (#4454)



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]>
ChrisRackauckas added a commit that referenced this pull request Sep 12, 2026
- Release OrdinaryDiffEqBDF 2.4.7 (#4490)
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)



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]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/DiffEqGPU.jl that referenced this pull request Sep 12, 2026
OrdinaryDiffEqDefault 2.6.1 calls OrdinaryDiffEqCore._is_identity_massmatrix
(added in Core 4.17.1, SciML/OrdinaryDiffEq.jl#4502) but bounds Core at
"4.11", so a minimum-bounds resolve picks Core 4.16.1 and OrdinaryDiffEq
fails to precompile. Reported upstream as SciML/OrdinaryDiffEq.jl#4522.
Flooring Core in the test project keeps the downgrade lane green; this
is a test-env bound only, not a package compat change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_e9ba8699c66b48e4.md
ChrisRackauckas added a commit that referenced this pull request Sep 12, 2026
…4525)

#4502 added `_is_identity_massmatrix`, `_is_zero_massmatrix` and
`_diff_alg_vars` to OrdinaryDiffEqCore's internal surface and started using
them from four sublibraries. Those sublibraries were released without raising
their OrdinaryDiffEqCore floor, so a resolver is free to pair them with an
older Core that lacks the symbols:

    WARNING: Imported binding OrdinaryDiffEqCore._is_identity_massmatrix was
    undeclared at import time during import to OrdinaryDiffEqDefault.
    ERROR: LoadError: UndefVarError: `_is_identity_massmatrix` not defined in
    `OrdinaryDiffEqDefault`

The symbols first exist in OrdinaryDiffEqCore 4.17.1.

| package | released | old floor | uses |
|---|---|---|---|
| OrdinaryDiffEqDefault | 2.6.1 | 4.11 | _is_identity_massmatrix |
| OrdinaryDiffEqFIRK | 2.8.5 | 4.15.1 | _is_identity_massmatrix |
| OrdinaryDiffEqRosenbrock | 2.7.2 | 4.11 | _diff_alg_vars |
| StochasticDiffEqCore | 2.2.2 | 4 | _is_identity_massmatrix |

All four now require OrdinaryDiffEqCore 4.17.1 and get a patch bump. Raising a
compat floor is non-breaking.

The already-published versions in the table stay broken for anyone who
resolves them; those need a retroactive Compat.toml fix in the General
registry, which is a separate pull request there.



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]>
ChrisRackauckas added a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Sep 12, 2026
lib/OrdinaryDiffEqDefault/Project.toml has no [sources] block, unlike 44 of
the 59 sublibraries. Its CI therefore resolves OrdinaryDiffEqCore and the
other lib/ dependencies from the registry rather than from the checkout, so a
change to local Core is never exercised against Default before merge.

That is how SciML#4502 shipped broken: it added _is_identity_massmatrix to Core and
used it from Default in one commit, and the lane that should have caught it
was testing Default against an already-released Core.

The entries cover every dependency that lives in lib/: the six runtime deps
plus the DiffEqDevTools test extra, matching the pattern the sibling
sublibraries use.

The load failure itself is already fixed: Core 4.17.1 is registered with the
new helpers and SciML#4525 raised the four consumers' floors to it. This change is
only about closing the CI gap that let it through.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R
ChrisRackauckas added a commit that referenced this pull request Sep 12, 2026
`_is_identity_massmatrix` is imported from OrdinaryDiffEqCore but was only
added there in 4.17.1 (#4502). The declared bound of "4.11" lets the resolver
pick an older Core, and the package then fails to precompile with
`UndefVarError: _is_identity_massmatrix`. In-repo CI never sees this because
`[sources]` supplies the local Core.



Claude-Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn

Co-authored-by: Chris Rackauckas <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 12, 2026
lib/OrdinaryDiffEqDefault/Project.toml has no [sources] block, unlike 44 of
the 59 sublibraries. Its CI therefore resolves OrdinaryDiffEqCore and the
other lib/ dependencies from the registry rather than from the checkout, so a
change to local Core is never exercised against Default before merge.

That is how #4502 shipped broken: it added _is_identity_massmatrix to Core and
used it from Default in one commit, and the lane that should have caught it
was testing Default against an already-released Core.

The entries cover every dependency that lives in lib/: the six runtime deps
plus the DiffEqDevTools test extra, matching the pattern the sibling
sublibraries use.

The load failure itself is already fixed: Core 4.17.1 is registered with the
new helpers and #4525 raised the four consumers' floors to it. This change is
only about closing the CI gap that let it through.



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

Co-authored-by: ChrisRackauckas <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



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