Skip to content

Fix JET typo-mode findings in ModelingToolkitBase - #5065

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/mtkbase-jet-typo-findings
Sep 5, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/mtkbase-jet-typo-findings

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

This PR should be ignored until reviewed by @ChrisRackauckas.

What changed and why

JET.report_package(ModelingToolkitBase; target_modules = (ModelingToolkitBase,), mode = :typo) (the check run_qa runs in the ModelingToolkitBase QA group, red on master since #4832 — see #5063) reports 263 problems. 234 of them are spurious may be undefined reports on Moshi @match temporaries (tracked in the issue; fix is upstream in Moshi). This PR fixes the other 29, which are genuine:

  • Shift(steps) called new from an outer constructor (UndefVarError for Shift(2)).
  • _all_ts_idxs!(…, sym::Symbol) used s instead of sym (unreachable branch, no test).
  • BandedAMatrixWrapper(::Expr, nr, bands) used sz instead of nr.
  • compile_functional_affect's duplicate-alias @warn interpolated expr instead of exp; search_variables!(vars, ::ImperativeAffect) recursed on v instead of var.
  • define_params fallback threw the undefined ModelingtoolkitizeParametersNotSupportedError; the type is now defined with a showerror.
  • extend on systems of different types called the removed convert_system; it now throws an ArgumentError.
  • The Substituter method for AffectSystem used the removed parameter_dependencies/defaults fields; it now substitutes eqs, observed (where the compiled affect equations live), bindings, initial_conditions, guesses, unknowns, ps.
  • throw_invalid_operator left optext undefined for non-Differential operators; fractional_to_ordinary left coeff undefined for α == 1 (now an ArgumentError; previously an InexactError from floor(Int, -Inf) further down).
  • Locals bound only on some branches (ic, subidx, source_visitor, source_info, mass_matrix) and locals captured by closures after reassignment (dsti, buffer, newbuf — these were Core.Boxed) are restructured so they are defined on every path. No behaviour change.

Verification

JET on this branch, Julia 1.12.7 / JET 0.12.1 / Moshi 0.3.12, same call as run_qa:

The QA group itself therefore still fails on this PR until Moshi is fixed; I am not changing the test.

New tests (test/discrete_system.jl, test/code_generation.jl, test/modelingtoolkitize.jl, test/abstractsystem.jl, test/basic_transformations.jl, test/symbolic_events.jl), run as one script against master and against this branch:

master:      Some tests did not pass: 0 passed, 4 failed, 6 errored, 0 broken.
this branch: new regression tests | 14 passed, 14 total

Test groups run locally with GROUP=<group> julia +1.12 --project=. -e 'using Pkg; Pkg.test()' in lib/ModelingToolkitBase:

group this branch master CI (run 33444273161)
InterfaceI 1610 passed, 5 broken, 44m55s 1601 passed, 5 broken
InterfaceII all 26 files pass; Optimal Control + Constraints Tests 31 passed, 2 broken (same as master) same
SymbolicIndexingInterface 64 + 1824 + 118 + 53 passed same

(The 9 extra InterfaceI passes are the new tests; the broken counts are pre-existing @test_brokens.)

Runic (julia -m Runic --check --diff on the changed files) reports only a pre-existing hunk in src/systems/parameter_buffer.jl:120 that is identical on master; typos on the diff is clean.

Not verified

  • Other test groups (Initialization, Extended, Regression*, Downstream, the root ModelingToolkit groups) and Julia 1.10.
  • The !ArrayInterface.ismutable(oldbuf) path in remake_buffer (restore_static_buffers) is a pure extraction of the existing closures; I did not find a test that exercises it.

Things to push back on

  • extend with mismatched system types now throws ArgumentError rather than trying (and failing) to convert.
  • fractional_to_ordinary with α == 1 now throws ArgumentError up front.

🤖 Generated with Claude Code 2.1.259 (model: claude-fable-5-1)
Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn

`JET.report_package(ModelingToolkitBase; mode = :typo)` flags a number of
genuine problems in hand-written code (the rest of its reports come from
Moshi's `@match` codegen and are addressed upstream):

- `Shift(steps)` called `new` from an outer constructor.
- `_all_ts_idxs!(…, sym::Symbol)` referenced `s` instead of `sym`.
- `BandedAMatrixWrapper(::Expr, nr, bands)` referenced `sz` instead of `nr`.
- `compile_functional_affect`'s duplicate-alias warning interpolated `expr`
  instead of `exp`, and `search_variables!(vars, ::ImperativeAffect)`
  recursed on `v` instead of `var`.
- `define_params` threw an undefined `ModelingtoolkitizeParametersNotSupportedError`;
  define it.
- `extend` on systems of different types called the removed `convert_system`;
  throw an `ArgumentError` instead.
- The `Substituter` method for `AffectSystem` still used the removed
  `parameter_dependencies`/`defaults` fields; substitute the current fields
  (including `observed`, where the compiled affect equations live).
- `throw_invalid_operator` left `optext` undefined for non-`Differential`
  operators, and `fractional_to_ordinary` left `coeff` undefined for α == 1.
- Locals bound only on some branches (`ic`, `subidx`, `source_visitor`,
  `source_info`, `mass_matrix`) and locals captured by closures after being
  reassigned (`dsti`, `buffer`, `newbuf`) are restructured so they are
  defined on every path.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Agent-Harness: Claude Code 2.1.259
Agent-Model: claude-fable-5-1
Agent-Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn
The two testsets added for the JET fixes call `unwrap` unqualified.
Symbolics 7.37.0, the compat floor used by the downgrade lanes, does
not export `unwrap` (7.39.0 does), so those lanes errored with
`UndefVarError: unwrap not defined`.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Agent-Harness: Claude Code 2.1.259
Agent-Model: claude-fable-5-1
Agent-Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

CI triage for the red checks on this PR

Only the two downgrade InterfaceI lanes were broken by this PR. Everything else is red on master at the same base commit or is a known flaky test. Fixed in 823fc60 (one-line test import).

Failing job Failure Classification Evidence
Downgrade / InterfaceI UndefVarError: unwrap not defined in the two new testsets symbolic_events.jl:1989 / :2001 (1494 pass, 2 errored) (a) caused by this PR The new tests call unwrap unqualified. Symbolics 7.37.0 (the compat floor the downgrade lanes resolve to) does not export unwrap; 7.39.0 does, which is why the Julia 1/pre InterfaceI lanes passed. Same lane is green on master.
downgrade-mtkbase (InterfaceI) same two UndefVarError: unwrap errors (1606 pass, 2 errored) (a) caused by this PR as above
downgrade-mtkbase (QA) Aqua Stale dependencies + Persistent tasks (17 pass, 2 fail) (b) pre-existing on master Identical 2 failures on master run 33444272942; the lane has been red on the last 3 master pushes. See #5063.
sublibrary-ci MTKBase QA (Julia 1) JET.report_package(..., mode=:typo) test fails: 234 findings (b) pre-existing on master Master fails the same single assertion with 263 findings (job 99660311927); this PR removes exactly the 29 it claims. The remaining 234 are Moshi-generated local variable ##And#...#f#1 may be undefined reports in default_toterm etc., not code in this repo. See #5063.
sublibrary-ci MTKBase Optimization (Julia 1), (Julia pre), tests/Optimization (Julia 1), (Julia pre) MethodError: no method matching create_array(::Type{CasADi.MX}, ::Nothing, ::Val{1}, ::Val{(2,)}, ::CasADi.MX, ::CasADi.MX) in 9 dynamic_optimization.jl testsets (b) pre-existing on master Same 9 create_array MethodErrors on master job 99664470470 and job 99660312390 (both Julia 1 and pre). Not touched by this PR.
sublibrary-ci MTKBase InterfaceII (Julia 1) poissonians.jl:843 "SIR model: compare symbolic @poissonians to direct JumpProcesses" mean-comparison fails (122 pass, 1 fail) (c) flaky Does not reproduce: poissonians.jl passes 123/123 locally on Julia 1.12.7 with the PR source and with master source, using the exact CI dependency versions (JumpProcesses 9.32.0, StochasticDiffEq 7.1.5, OrdinaryDiffEq 7.8.1, Symbolics 7.39.0, SymbolicUtils 4.46.1). The same assertion also failed on an unrelated PR, #5008 (job 99367530970). This PR does not touch jump/poissonian code.

What changed

lib/ModelingToolkitBase/test/symbolic_events.jl: added using Symbolics: unwrap (the two new testsets were the only unqualified unwrap users in that file).

Verification

Julia 1.10.11 with Symbolics pinned to 7.37.0 (the downgrade condition), running test/symbolic_events.jl:

# before (as pushed in 4bae51a)
`search_variables!` descends into non-symbolic entries: Error During Test at .../test/_se_unfixed.jl:1989
  UndefVarError: `unwrap` not defined
`Substituter` on an `AffectSystem`: Error During Test at .../test/_se_unfixed.jl:2001
  UndefVarError: `unwrap` not defined
symbolic_events (Symbolics 7.37, unfixed)  |  369      2       2    373  6m42.7s

# after (823fc60)
symbolic_events (Symbolics 7.37, fixed)    |  373              2    375  6m51.9s

Julia 1.12.7, latest deps, same file with the fix:

symbolic_events (PR fixed, Julia 1.12)     |  373              2    375  12m16.2s

julia -m Runic --check (Runic 1.10.0) and typos are clean on every file this PR touches.

Not run locally: the full GROUP=InterfaceI sweep under the downgrade resolver (only symbolic_events.jl was run under Symbolics 7.37, since it is the only file this PR adds tests to), and the Optimization/QA lanes, which fail identically on master.

🤖 Generated with Claude Code (model: claude-fable-5-1)
https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 5, 2026 10:26
@ChrisRackauckas
ChrisRackauckas merged commit e76112c into SciML:master Sep 5, 2026
101 of 109 checks passed
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The current base reproduces this failure independently of the copied-binding change in #5073. Full native QA on clean source e76112c gives the same 234 Moshi-generated-local reports on Julia 1.12.7 / JET 0.12.1.

I then ran the same native QA command on a separate checkout of that base with the existing Moshi fix ChrisRackauckas-Claude/Moshi.jl@7b5ef92. It passes. No ModelingToolkit source or test changes, JET suppression, or mode changes were made.

Both runs used this command from lib/ModelingToolkitBase, with TMPDIR set to a directory inside the validation checkout:

TMPDIR="$PWD/../../.validation/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 GROUP=QA timeout 14400 /home/crackauc/.juliaup/bin/julia +1.12.7 --startup-file=no --project=. -e 'import Pkg; Pkg.test(;coverage=true, julia_args=["--check-bounds=auto", "--compiled-modules=yes", "--depwarn=yes"], force_latest_compatible_version=false, allow_reresolve=true)' > ../../.validation/qa-native.log 2>&1

Baseline terminal output, exit 1:

JET Tests     |   54     54  1m43.8s
Expression: (JET.report_package)(ModelingToolkitBase; toplevel_logger = nothing, target_modules = (ModelingToolkitBase,), mode = typo)
═════ 234 possible errors found ═════
Aqua Tests    |   20     1     21  17m51.2s

With the existing Moshi fix, exit 0:

Test Summary: | Pass  Total     Time
JET Tests     |   54     54  1m41.0s
Test Summary: | Pass  Total     Time
Aqua Tests    |   21     21  7m26.2s
     Testing ModelingToolkitBase tests passed

The package, QA, and actual Pkg.test sandbox manifests were preserved. Comparing them before/after confirmed identical versions and source tree hashes for all other dependencies: 172 package-environment names, 184 QA-environment names, and 311 test-sandbox names. Both graphs use SciMLTesting 2.13.0, Symbolics 7.39.0, and SymbolicUtils 4.46.1. Only Moshi 0.3.12 was replaced by the existing fix checkout (plus the local ModelingToolkitBase checkout path).

This validates the existing investigation and fix; it does not submit or publish the Moshi change upstream. No new bisect or duplicate fix was created. This run covered native ModelingToolkitBase QA, not its other groups or the Moshi test suite.

AI involvement: Codex CLI 0.153.4; model: gpt-6-astra; local session ID: 01a071a0-abb2-7eb2-8e39-9cab28110384 (parent local session: 01a0598f-11b9-72d1-91d9-b2fbb186557d).

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