Repository navigation
Fix construction of state-machine query operator terms in ModelingToolkitTearing - #171
Open
baggepinnen wants to merge 2 commits into
Open
baggepinnen wants to merge 2 commits into
baggepinnen wants to merge 2 commits into
Conversation
The methods of `timeInState`, `ticksInState`, `entry` and `activeState` called the unqualified function `wrap`, which is not defined in ModelingToolkitTearing, so every method threw an `UndefVarError`. The terms are now constructed with `Symbolics.wrap` and with an explicit `type` and scalar `shape`. Without these keywords the zero-argument methods produce a term of symtype `Any`, and all methods produce a term of unknown shape. The unused variable `seed` is removed. Fixes #170 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S12pk8C416QqoxphWRcPz8
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S12pk8C416QqoxphWRcPz8
baggepinnen
marked this pull request as ready for review
October 20, 2026 05:53
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.
Fixes #170
Problem
The methods of the state-machine query operators
timeInState,ticksInState,entryandactiveStateinlib/ModelingToolkitTearing/src/clock_inference/state_machines.jlcalled the unqualified functionwrap, which is not defined in ModelingToolkitTearing (Symbolics 7 does not export it). Every method, with a state argument and without arguments, therefore threwFix
The terms are now constructed with
Symbolics.wrap(term(f, x; type = T, shape = SU.ShapeVecT())), and correspondingly for the zero-argument methods. The explicit keywords are required:type, the zero-argument methods produce a term of symtypeAny, since thepromote_symtypemethod of each operator only applies to calls with one argument.Symbolics.wrapthen returns the unwrapped term instead of aNum.shape, all methods produce a term of unknown shape (SU.Unknown(-1)) instead of a scalar.The symtypes are those already declared in the loop (
RealfortimeInState,IntegerforticksInState,BoolforentryandactiveState). Thepromote_symtypemethods are retained, since they determine the symtype when a term is reconstructed. The unused variableseed = hash(s)is removed. The patch version of ModelingToolkitTearing is bumped to 1.20.8.Test
A testset
State machine query operators construct symbolic termsis added tolib/ModelingToolkitTearing/test/runtests.jl. For each operator it constructs the term with aSystemargument and, except foractiveState, without arguments, and checks the operation, the arguments, the symtype and the scalar shape. It also checks thatactiveState()throws aMethodError.The test file was run with Julia 1.13.1 in an environment in which StateSelection and ModelingToolkitTearing from this branch are developed, together with ModelingToolkit v11.45.5, ModelingToolkitBase v1.77.5, Symbolics v7.46.0 and SymbolicUtils v4.52.0:
All 35 top-level testsets passed, with no failures or errors. The new testset reports:
Host: demeter2 · Session: https://claude.ai/code/session_01S12pk8C416QqoxphWRcPz8 · Working directory: /tmp/claude-7594982/-home-baggepinnen--julia-dev-SynchToolkit/8ad5329e-3919-479c-b607-9b3da2c93519/scratchpad/StateSelection-fix170
🤖 Generated with Claude Code