Repository navigation
Do not distribute shifts into operator terms other than Shift and Differential - #5226
Merged
Merged
Conversation
…Differential` `distribute_shift` distributed a shift into every operator term except `Sample` and `Hold`. An operator term such as a clock change defined by another package denotes the value of its signal at the current tick and is a symbol of its own; distributing the back-shift of the discrete reassembly into it produced a reference to a nonexistent history variable. The default for operators is now `false`, with `Shift` and `Differential` as the exceptions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QBgBrXDidWG1G2KF64gAte
Contributor
Benchmark Results (Julia vlts)Time benchmarks
Memory benchmarks
|
Contributor
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
AayushSabharwal
approved these changes
Sep 29, 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.
Split out of #5173.
Summary
distribute_shiftdistributed a shift into every operator term exceptSampleandHold. An operator term such as a clock change defined by another package (SynchToolkit.Latest(x, init)) denotes the value of the signal at the current tick of the receiving clock and is a symbol of its own, so distributing the back-shift that the discrete reassembly of ModelingToolkitTearing performs into it produces a reference to a nonexistentxₜ₋₁. The default forOperatorsubtypes is nowfalse;ShiftandDifferentialkeep distributing, as before.Behaviour change
Only operators defined outside ModelingToolkitBase are affected:
Sample,Hold,PreandInitialwere already excluded. A package whose operator term must be entered by shifts can definedistribute_shift_into_operator(::MyOperator) = true.Tests
A regression test with an operator defined in the test file checks that the shift of a sum is distributed to the variable but not into the operator term, and that
Sample,Hold,ShiftandDifferentialbehave as before.🤖 Generated with Claude Code
https://claude.ai/code/session_01QBgBrXDidWG1G2KF64gAte