Comments (2)
The problem here is that in MassSpringDamper
, there is no @parameters damping = damping
like there is for the other parameters. This is because a variable can't have a "double ParentScope
" metadata.
When @named wheel = MassSpringDamper(; mass=4*wheel_mass, gravity, damping=wheel_damping, stiffness=wheel_stiffness, initial_position=0.5)
is done, wheel_damping
gets its SymScope
metadata set to ParentScope
, indicating that it is a variable from the parent of the system it is being passed to (and thus shouldn't be namespaced). If it is aliased to a new parameter inside MassSpringDamper
via @parameters damping = damping
, then damping
doesn't have the SymScope
metadata, so when it is passed to Damper
, it gets assigned ParentScope
. Without the aliasing,ParentScope
can't be applied twice to wheel_damping
which is why Damper
thinks the variable is from MassSpringDamper
and not System
.
The long explanation is only to document the error and find a solution. It is definitely not something I'd expect a user to be concerned with, and we should either throw an error in such a scenario or handle it properly. I think DelayParentScope
should be used here.
from modelingtoolkit.jl.
Here's another example that throws the same error, but I'm not sure if the same explanation as to why applies
using ModelingToolkit
using ModelingToolkitStandardLibrary: Blocks
gravity = 9.81
gain_u1 = 0.89 / 1.4
d0 = 70
d1 = 17
n0 = 55
@named motor_dynamics = Blocks.FirstOrder(T = 0.001)
x0 = [0.85, 1, π/12, π/2]
@parameters t
@variables u(t)[1:2]=0
u = collect(u)
@variables y(t)=0.85 v(t)=1 ϕ(t)=π/12 ω(t)=π/2
D = Differential(t)
eqs = [
D(y) ~ v,
D(v) ~ -gravity + gain_u1 * cos(ϕ)*(motor_dynamics.output.u + gravity/gain_u1),
D(ϕ) ~ ω,
D(ω) ~ -d0 * ϕ - d1 * ω + n0 * u[2],
motor_dynamics.input.u ~ u[1]
]
@named model = ODESystem(eqs, t; systems=[motor_dynamics])
linearize(model, collect(u), [y, v, ϕ, ω])
julia> linearize(model, collect(u), [y, v, ϕ, ω])
ERROR: ArgumentError: v(t) is neither an observed nor an unknown variable.
Stacktrace:
[1] build_explicit_observed_function(sys::NonlinearSystem, ts::Vector{…}; inputs::Nothing, expression::Bool, output_type::Type, checkbounds::Bool, drop_expr::typeof(RuntimeGeneratedFunctions.drop_expr), ps::Vector{…}, return_inplace::Bool, op::Type, throw::Bool)
@ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/diffeqs/odesystem.jl:451
[2] build_explicit_observed_function(sys::NonlinearSystem, ts::Vector{SymbolicUtils.BasicSymbolic{Real}})
@ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/diffeqs/odesystem.jl:378
[3] observed(sys::NonlinearSystem, sym::Vector{SymbolicUtils.BasicSymbolic{Real}})
@ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/abstractsystem.jl:534
[4] _getu(sys::NonlinearSystem, ::SymbolicIndexingInterface.NotSymbolic, ::SymbolicIndexingInterface.ScalarSymbolic, sym::Vector{…})
@ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/A1VUA/src/state_indexing.jl:158
[5] getu(sys::NonlinearSystem, sym::Vector{SymbolicUtils.BasicSymbolic{Real}})
@ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/A1VUA/src/state_indexing.jl:32
[6] linearization_function(sys::ODESystem, inputs::Vector{…}, outputs::Vector{…}; simplify::Bool, initialize::Bool, op::Dict{…}, p::SciMLBase.NullParameters, zero_dummy_der::Bool, initialization_solver_alg::NonlinearSolve.GeneralizedFirstOrderAlgorithm{…}, kwargs::@Kwargs{})
@ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/abstractsystem.jl:1965
[7] linearization_function
@ ~/.julia/dev/ModelingToolkit/src/systems/abstractsystem.jl:1867 [inlined]
[8] linearize(sys::ODESystem, inputs::Vector{…}, outputs::Vector{…}; op::Dict{…}, t::Float64, allow_input_derivatives::Bool, zero_dummy_der::Bool, kwargs::@Kwargs{})
@ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/abstractsystem.jl:2325
[9] linearize(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num})
@ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/abstractsystem.jl:2321
[10] top-level scope
@ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.
from modelingtoolkit.jl.
Related Issues (20)
- Unintuitive behavior for including metadata in @parameters/@variables begin end
- Cannot initialize unknown from observed that depends on parameter
- Niche case of `plotsol; idxs = [...])` fails HOT 2
- Superfluous parameter and initial condition values can be provided to Problems HOT 1
- Latexify display does not work for `SDESystem`s HOT 1
- providing updated `op` to `linearization_function` has no effect HOT 2
- `structural_simplify` broken for some underdetermined `NonlinearSystem`s HOT 2
- Unknowns in the `initialization_eqs` should be added to the variable list HOT 7
- Initialization is incomplete without a `u0`, despite passing `guesses` HOT 5
- remake `SteadyStateProblem` gives different solution HOT 1
- Cannot initialize system with default that depends on observed variable HOT 3
- `build_explicit_observed_function` no longer handles inputs correctly HOT 2
- Cannot (re)make problems with defaults involving the independent parameter HOT 2
- Cannot provide vector parameter values to `remake` for scalarised system HOT 1
- Array variable not recognized in registered function call HOT 1
- Cannot provide default value for array parameter
- conditionally chosen array variable
- parameter default given by other parameter leads to incorrect codegen HOT 1
- Unable to simualte SDEs with static array u0/ps
- parameter splitting tries to convert to Union
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modelingtoolkit.jl.