-
-
Notifications
You must be signed in to change notification settings - Fork 59
Add Symbolics v7 and ModelingToolkit v11 compatibility #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Symbolics v7 and ModelingToolkit v11 compatibility #571
Conversation
Fixes SciML#563 ## Summary - Add local `Difference` operator since it was removed from Symbolics v7 - Update type annotations from `SymbolicUtils.Symbolic` to `SymbolicUtils.BasicSymbolic` - Update Project.toml compat to support Symbolics v7 and ModelingToolkit v11 ## Changes - `src/difference.jl` (new): Local implementation of the Difference operator that was removed from Symbolics v7, with proper `nameof` method - `src/DataDrivenDiffEq.jl`: Include and export the local Difference operator - `src/basis/utils.jl`: Update type annotations for SymbolicUtils v4 compatibility - `lib/DataDrivenSR/src/DataDrivenSR.jl`: Import Difference from DataDrivenDiffEq - `Project.toml`: Add Symbolics v7 and ModelingToolkit v11 to compat ## Notes There are some test failures unrelated to issue SciML#563 that are due to other API changes in ModelingToolkit v11. These should be addressed separately. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove backwards compatibility with older versions since the local Difference operator is designed for the new API. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit fixes multiple API changes introduced in Symbolics v7 and SymbolicUtils v4: 1. SymbolicUtils.Symbolic → SymbolicUtils.BasicSymbolic 2. Handle Const type in count_operation (constants are now wrapped in Const) 3. Fix remove_constant_factor to use isconst() instead of isa(x, Number) 4. Fix is_dependent to use get_variables() instead of removed occursin() 5. Fix __assert_linearity to handle get_variables returning Set instead of Vector 6. Fix get_parameter_values/get_parameter_map for Symbolics v7 metadata changes 7. Update test files to handle API changes: - Use collect(reduce(union, ...)) for get_variables Sets - Replace @mtkmodel with manual System definition to avoid SafeTestsets issues - Update expected output order in linear_independent basis test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update: Additional fixes for Symbolics v7 / SymbolicUtils v4 compatibilityThis commit fixes multiple API changes introduced in Symbolics v7 and SymbolicUtils v4. All 260 tests now pass. Changes made:
Key API changes handled:
|
| """ | ||
| Difference(t; dt, update=false) | ||
|
|
||
| Represents a difference operator for discrete-time systems. | ||
|
|
||
| # Fields | ||
|
|
||
| - `t`: The independent variable | ||
| - `dt`: The time step | ||
| - `update`: If true, represents a shift/update operator | ||
|
|
||
| # Examples | ||
|
|
||
| ```julia | ||
| @variables t | ||
| d = Difference(t; dt = 0.01) | ||
| ``` | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AayushSabharwal is this the right approach here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Difference was MTK's old way of handling discrete systems. That doesn't work anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisRackauckas have you already released this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It doesn't work anymore for MTK but this package needs a representation of it in order to not break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it not use the new MTK discrete system interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't even use MTK at all, why would it start?
Summary
Changes
src/difference.jl(new): Local implementation of theDifferenceoperator that was removed from Symbolics v7. Includes propernameofmethod to fix the display error.src/DataDrivenDiffEq.jl: Include and export the localDifferenceoperatorsrc/basis/utils.jl: Update type annotations fromSymbolicUtils.SymbolictoSymbolicUtils.BasicSymbolicfor SymbolicUtils v4 compatibilitylib/DataDrivenSR/src/DataDrivenSR.jl: ImportDifferencefrom DataDrivenDiffEqProject.toml: Add Symbolics v7 and ModelingToolkit v11 to compatBackground
The
Differenceoperator was removed from Symbolics.jl in v7.0.0 (commit cdbae19352). This caused issue #563 where displayingBasisobjects containingDifferenceoperators (as produced by DMD algorithms) would fail withMethodError: no method matching nameof(::Difference).Rather than using type piracy by extending
Base.nameoffor a type from another package, this PR defines a localDifferenceoperator in DataDrivenDiffEq with the proper methods.Test plan
🤖 Generated with Claude Code