-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow getu
to be used directly on the state vector?
#35
Comments
Sorry, to be clear: above I mean to allow the function generated by |
wait a moment, maybe https://docs.sciml.ai/SymbolicIndexingInterface/stable/api/#SymbolicIndexingInterface.observed is what I need. I will test this now! |
Hm,
where
|
|
That said, I think it's a nice idea to allow the function returned by It would look something like getter = getu(sys, sym)
# assume sym is the second variable
getter([1.5, 2.5, 3.5]) # returns 2.5 And the best part is I think all we will need is julia> using SymbolicIndexingInterface
julia> SymbolicIndexingInterface.state_values(arr::AbstractArray) = arr
julia> sc = SymbolCache([:x, :y])
SymbolCache{Vector{Symbol}, Nothing, Nothing}([:x, :y], nothing, nothing)
julia> getter = getu(sc, :x)
(::SymbolicIndexingInterface.var"#getter#8") (generic function with 1 method)
julia> getter([1.5, 2.5])
1.5
julia> getter = getu(sc, :y)
(::SymbolicIndexingInterface.var"#getter#8") (generic function with 1 method)
julia> getter([1.5, 2.5])
2.5 |
thanks, yeah that would be very nice to have! |
This will be supported once #33 is merged and tagged |
@AayushSabharwal I have checked out your PR in my local code, where I am working in integrating DynamicalSystems.jl with ModelingToolkit.jl. It works wonderfully! It does exactly what I wanted, and it significantly simplifies my code as well! Coincidentally, it turns out I wanted the same thing for parameters as well, for |
@AayushSabharwal I am having some difficulty using the PR that I cannot create a MWE for (because I have not understood why the problem exists at all). It appears that for some
Above you said that |
A!!!! I Was able to reproduce the problem!!! The syntax doesn't work for observed variables! @parameters σ=28.0 ρ=10.0 β=8/3
@variables t x(t)=5.0 y(t)=0.0 z(t)=0.0 w(t)
D = Differential(t)
eqs = [D(x) ~ σ * (y - x),
D(y) ~ x * (ρ - z) - y,
D(z) ~ w - β * z,
w ~ x*y]
@named lorenz = ODESystem(eqs)
sys = structural_simplify(lorenz)
julia> SymbolicIndexingInterface.getu(sys, sys.x)
(::SymbolicIndexingInterface.var"#getter#24"{SymbolicIndexingInterface.var"#_getter#23"{Int64}}) (generic function with 2 methods)
julia> SymbolicIndexingInterface.getu(sys, sys.w)
ERROR: MethodError: no method matching symbolic_container(::ODESystem)
Stacktrace:
[1] observed(sys::ODESystem, sym::Num)
@ SymbolicIndexingInterface C:\Users\gd419\.julia\packages\SymbolicIndexingInterface\rvbno\src\interface.jl:100
[2] _getu(sys::ODESystem, ::SymbolicIndexingInterface.ScalarSymbolic, ::SymbolicIndexingInterface.ScalarSymbolic, sym::Num)
@ SymbolicIndexingInterface C:\Users\gd419\.julia\packages\SymbolicIndexingInterface\rvbno\src\state_indexing.jl:149
[3] getu(sys::ODESystem, sym::Num)
@ SymbolicIndexingInterface C:\Users\gd419\.julia\packages\SymbolicIndexingInterface\rvbno\src\state_indexing.jl:113
[4] top-level scope The above works fine if I give the ODE problem as the first input, and not the system. so in the end, |
It works for sys, just not for observed variables. It's a bit of a weird thing to document, since |
Is your feature request related to a problem? Please describe.
I am creating a dynamical system that iterates a vector of vectors, that is, many different states in parallel. I do this because it is important that the states are iterated at exactly the same time. The system is in essence using an MTK model and gets the function
f
and uses it in afor
loop to create a newnewf
that is the ODE rule for the system with the parallel states.I would like to access "observed" variables within the MTK definition and symbolic indexing.
Describe the solution you’d like
getu
would allow this, if it could be applied directly on the state instead of an ODEproblem/sol/integ. Because the ODEInteg of the parallel system is not created from an MTK system, I can't pass it togetu
.Describe alternatives you’ve considered
I am welcoming alternative ways to achieve that.
The text was updated successfully, but these errors were encountered: