Repository navigation
Conversation
SymbolicUtils represents a range slice of an array variable, e.g. `u(t)[1:3]`, as an ArrayOp with `expr = getindex(u(t), _1)` and `term = getindex(u(t), 1:3)`. A broadcast over a slice contains `getindex(slice, _1)`, which `namespace_expr` treats as a variable and passes to `renamespace`. Its getindex branch then calls `renamespace` on the ArrayOp slice, which had no match arm and failed with "matching non-exhaustive". Any system with slice-form array equations therefore failed `mtkcompile` once used as a subsystem. Add an ArrayOp arm that renamespaces `expr` and `term` and rebuilds the ArrayOp. `renamespace` only receives variable-like expressions; for a variable slice both fields are getindex Terms handled by the existing arm, so no general expression traversal is needed. Arithmetic ArrayOps are not variables and still go through `namespace_expr`. Tests cover the direct `renamespace` call on a slice and compile and solve a slice-form system as a subsystem, checking it against the flat system's solution. Agent-Harness: Claude Code 2.1.303 Agent-Model: claude-opus-5-5 Agent-Session: fe6e5fd4-da2b-43af-8f0d-e3c4ab662c0d Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
renamespace(sys, x)had@matcharms only forSymandTerm, so a range slice of an array variable, which SymbolicUtils represents as anArrayOp, failed withmatching non-exhaustive. This adds anArrayOparm that renamespaces the slice'sexprandterm.Why it matters
A broadcast over a slice, e.g.
2 .* u[1:3], lowers to anArrayOpwhoseexprcontainsgetindex(u(t)[1:3], _1).namespace_exprtreats thatgetindexas a variable and passes it torenamespace, whosegetindexbranch recurses into theArrayOpslice and errors. Any system with slice-form array equations therefore failsmtkcompileonce it is used as a subsystem. Flat systems are unaffected.MethodOfLines emits slice-form equations since SciML/MethodOfLines.jl#701, so every MethodOfLines-discretized system currently fails when nested in another system. This blocks composing a discretized PDE with lumped components (SciML/MethodOfLines.jl#726).
Relation to #5133
#5133 fixes the same
mtkcompilefailure on the caller side:namespace_exprstops renamespacing thegetindexcall. Both fix the nested-system case. This PR additionally makes a directrenamespace(sys, u[2:3])work, which still errors under #5133. The two changes are independent and compatible; this one is offered as a complement, and can be closed if #5133 is preferred alone.Tests
New
Array slicestestset inlib/ModelingToolkitBase/test/namespacing.jl: a directrenamespaceof a slice, and a nested slice-form system that compiles and solves, matching the flat solution. Before the fix both error withmatching non-exhaustive.Run against this branch (rebased on master 9cde066) in an environment that develops the local ModelingToolkitBase, including each file directly:
namespacing.jlvariable_scope.jlabstractsystem_interface.jlThe full test suite was not run locally. Runic
--checkpasses on both changed files.🤖 Posted by an AI agent · harness: Claude Code 2.1.305 · model: claude-opus-5-5
Review: unreviewed
Session: fe6e5fd4-da2b-43af-8f0d-e3c4ab662c0d