Skip to content

Avoid an inference hang in reduce_ode_mod_p on Julia 1.14.0-beta1 - #587

Merged
pogudingleb merged 1 commit into
SciML:masterfrom
isaacsas:fix-reduce-ode-mod-p-hang
Nov 19, 2026
Merged

pogudingleb merged 1 commit into
SciML:masterfrom
isaacsas:fix-reduce-ode-mod-p-hang

Conversation

@isaacsas

@isaacsas isaacsas commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

On Julia 1.14.0-beta1 (and current Julia master), compiling assess_identifiability never finishes: type inference loops while inferring reduce_ode_mod_p. This showed up as the Structural Identifiability tests in Catalyst's Extensions (pre) CI running into the 6-hour timeout, and it reproduces with SI alone (checked with v0.5.36; the code is unchanged on master):

using StructuralIdentifiability, Logging
ode = @ODEmodel(
    M'(t) = pₘ / (1 + P(t)) - dₘ * M(t),
    E'(t) = -dₑ * E(t) + pₑ * M(t),
    P'(t) = -dₚ * P(t) + pₚ * E(t),
    y1(t) = M(t)
)
assess_identifiability(ode; loglevel = Logging.Error)  # ~30 s on 1.13.3 and 1.14.0-alpha2; never returns on 1.14.0-beta1

Cause. In reduce_ode_mod_p, new_type = typeof(new_vars[1]) is not inferable, so new_x_eqs and new_y_eqs infer as Dict{_A, Union{FracFieldElem{_A1}, _A1}} where {_A, _A1}. The loop then builds Dict(ode.x_equations => new_x_eqs, ode.y_equations => new_y_eqs), a Dict whose value type is that UnionAll, only to iterate over the two (old, new) pairs. On 1.14.0-beta1, inferring that Dict's internals (rehash!, copy(::Memory), unsafe_copyto!) builds ever larger Memory{Union{FracFieldElem{_A}, FracFieldElem{_A1}, ...}} types, and subtyping on them blows up. The underlying Julia regression is reported in JuliaLang/julia#65046.

Fix. Iterate over a tuple of the two pairs instead. The loop body is unchanged; this also avoids the two pairs collapsing into one entry if x_equations == y_equations.

Testing (macOS aarch64):

  • test/reduce_ode_mod_p.jl and test/identifiability.jl pass on Julia 1.13.3 and 1.14.0-beta1.
  • The SI-only example above takes 30 s on 1.14.0-beta1 with this change.
  • With the same change applied to v0.5.36, Catalyst's test/extensions/structural_identifiability.jl passes on 1.14.0-beta1 (64/64 in about a minute) instead of never finishing.

Catalyst's extension tests currently use SI 0.5.x, so a 0.5.x patch release with this change would also help, if that is possible.

🤖 Generated with Claude Code 2.1.326 (model: claude-opus-5-5)

`new_type` is not inferable here, so the reduced equation dicts infer as
`Dict{_A, Union{FracFieldElem{_A1}, _A1}} where {_A, _A1}`. Building a `Dict`
whose values are those dicts, only to iterate over the two (old, new) pairs,
sends type inference on Julia 1.14.0-beta1 (and master) into a loop of ever
larger `Memory{Union{FracFieldElem{_A}, FracFieldElem{_A1}, ...}}` types, so
compiling `assess_identifiability` never finishes. Iterate over a tuple of the
pairs instead; this also avoids the two pairs colliding as keys when
`x_equations == y_equations`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pogudingleb

Copy link
Copy Markdown
Collaborator

Thanks a lot for reporting the issue and for proposing the fix !
I will look into making a patch on Thursday

@pogudingleb
pogudingleb merged commit 40573d7 into SciML:master Nov 19, 2026
12 of 14 checks passed
@pogudingleb

Copy link
Copy Markdown
Collaborator

@isaacsas
Thanks again for the PR !

I have created a 0.5.x version with the fix, this is 0.5.37. Let me know if this is what you wanted.
Version 0.6.1 with this fix will also appear shortly.

@isaacsas

Copy link
Copy Markdown
Member Author

Either is fine, thanks! (I believe we now support both .5 and .6 in Catalyst.)

I'll give Catalyst CI a test and see if this fixes the hanging pre test.

@isaacsas
isaacsas deleted the fix-reduce-ode-mod-p-hang branch November 20, 2026 13:31
isaacsas added a commit to SciML/Catalyst.jl that referenced this pull request Nov 20, 2026
…0.6.1

Checks whether Extensions Tests (pre) finishes now that
StructuralIdentifiability 0.6.1 avoids the Julia 1.14 inference hang
(SciML/StructuralIdentifiability.jl#587).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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