Repository navigation
Test namespace nesting on segments, not raw string prefixes - #5089
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
ChrisRackauckas-Claude wants to merge 1 commit into
Conversation
`same_or_inner_namespace` and `inner_namespace` decided whether one namespace is nested inside another with `startswith` on the raw namespace strings, so `"force₊flange"` was treated as nested inside `"force₊f"`. Whether an input is reported as bound therefore depended on whether a sibling subsystem's name happened to begin with the input connector's name. Nesting is now tested on separator-delimited segments. The added tests pin the invariant: two systems that differ only in the spelling of those names must be classified the same way. This makes the classification consistent, but on its own it does not make `unbound_inputs` useful for finding external inputs — see the PR description. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam
This was referenced Sep 7, 2026
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.
What changed and why
same_or_inner_namespaceandinner_namespacedecided whether one namespace is nestedinside another with
startswithon the raw namespace strings:so
"force₊flange"was treated as nested inside"force₊f". Whether an input got reportedas bound therefore depended on whether a sibling subsystem's name happened to begin with the
input connector's name. Nesting is now tested on separator-delimited segments.
Two systems with identical structure, differing only in those names:
unbound_inputsbeforefflange[f₊u(t)][]Vport[][]This is not sufficient, and I would like your read on the rest — @AayushSabharwal
The consistency is real but it goes the unhelpful way. Measured on two standard-library
models, each leaving the driving component's
RealInputunconnected:unbound_inputsbeforeForce[force₊f₊u(t)][]Voltage[][]The
Forcecase worked only because"force₊flange"collided with"force₊f". With thataccident removed,
unbound_inputsreturns nothing for either — consistent, but no longerable to answer "which input does the user still have to supply?".
The reason is upstream of the string handling.
is_boundcounts a variable as bound when it"appears in an equation together with variables from other subsystems", and every library
source component has exactly such an equation as its own definition —
v ~ V.uforVoltage,flange.f ~ -f.uforForce. Under a faithful reading of that rule, anunconnected library component's input is always bound, so the namespace heuristic can only
ever get the useful answer by accident.
The question: should discovery be based on the connection structure instead — an input
being external iff its connector participates in no
connect— rather than on whichvariables share an equation?
get_eqson an uncompiled hierarchy does still carry theconnectnodes, so the information is there before flattening; I stopped short of buildingon it because which primitive MTK wants here is your call, not mine. If there is already a
right way to ask this that I have missed, I am happy to redo it that way.
Filed first as #5088, closed in favour of this PR.
Verification
New tests in
lib/ModelingToolkitBase/test/input_output_handling.jl(InterfaceI group):the two structurally identical systems must be classified identically, plus unit tests for
the segment predicate.
Before the change the first two lines differ (
[f₊u(t)]vs[]), so the invariant testfails on master and passes here.
Runic
--checkandtyposclean on both files touched.Not verified
I could not run the MTKBase test suite against this checkout:
ModelingToolkitBaseon masterrequires
ImplicitDiscreteSolve2.3.0, which is not registered yet, so the environment doesnot resolve. The measurements above were taken by applying the identical patch to the
released
ModelingToolkitBaseand exercising it against ModelingToolkitStandardLibrary. CIshould be treated as the real check here.
Related
#5087 documents
mtkcompile(sys; inputs)asthe interface for streaming external inputs. Naming the input explicitly is unaffected by any
of this and always works. A follow-up documenting
unbound_inputsas the discovery fallbackis written but deliberately not opened until this question is settled — as it stands, the
docs would be pointing at something that returns nothing for the models they describe.
This PR should be ignored until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code
https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam