-
-
Notifications
You must be signed in to change notification settings - Fork 234
fix: fix array discrete parameters #4002
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
Merged
Merged
+111
−6
Conversation
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
|
The fix works well when the parameter is a vector, but I still get an error with MRE: using Pkg;
Pkg.activate(temp = true)
Pkg.add(url="https://github.com/AayushSabharwal/ModelingToolkit.jl", rev="as/event-bugs")
Pkg.add("OrdinaryDiffEqTsit5")
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEqTsit5
N = 2
@parameters s(t)::Float64
@parameters v(t)[1:N]::Float64
@parameters M(t)[1:N, 1:N]::Float64
@variables x(t)::Float64
Mini = rand(N, N) ./ (N^2)
vini = vec(sum(Mini, dims = 1))
sMini = sum(Mini)
s_eq = [D(x) ~ x * s]
v_eq = [D(x) ~ x * Symbolics.scalarize(sum(v))]
M_eq = [D(x) ~ x * Symbolics.scalarize(sum(M))]
s_event = ModelingToolkit.SymbolicDiscreteCallback(
1.0,
[s ~ -Pre(s)],
discrete_parameters = [s],
)
v_event = ModelingToolkit.SymbolicDiscreteCallback(
1.0,
[v ~ -Pre(v)],
discrete_parameters = [v], # replacing with collect(v) works
)
M_event = ModelingToolkit.SymbolicDiscreteCallback(
1.0,
[M ~ -Pre(M)],
discrete_parameters = [M], # replacing with collect(M) still errors
)
@mtkcompile s_sys = System(s_eq, t; discrete_events = s_event)
@mtkcompile v_sys = System(v_eq, t; discrete_events = v_event)
@mtkcompile M_sys = System(M_eq, t; discrete_events = M_event)
u0p0_map = Dict(x => 1.0, M => Mini, s => sMini, v => vini)
s_prob = ODEProblem(s_sys, u0p0_map, (0.0, 2.5))
v_prob = ODEProblem(v_sys, u0p0_map, (0.0, 2.5))
M_prob = ODEProblem(M_sys, u0p0_map, (0.0, 2.5))
s_sol = solve(s_prob, Tsit5()) #, tstops = 1.0) # perfect
v_sol = solve(v_prob, Tsit5()) #, tstops = 1.0) # perfect
M_sol = solve(M_prob, Tsit5()) #, tstops = 1.0) # fails
perfect
# using Plots
# plot(s_sol, label = "s event")
# plot!(v_sol, label = "v event")
# plot!(M_sol, label = "M event")with julia> show(err)
1-element ExceptionStack:
LoadError: MethodError: Cannot `convert` an object of type
ModelingToolkit.NestedGetIndex{Tuple{Array{Matrix{Float64},1}}} to an object of type
ModelingToolkit.NestedGetIndex{Tuple{Array{Base.ReshapedArray{Float64, 2, SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, Tuple{}},1}}}
The function `convert` exists, but no method is defined for this combination of argument types.
Closest candidates are:
(::Type{ModelingToolkit.NestedGetIndex{T}} where T)(::Any)
@ ModelingToolkit /cyfast/lsablon/.julia/packages/ModelingToolkit/75pJw/src/systems/parameter_buffer.jl:801
convert(::Type{T}, ::T) where T
@ Base Base_compiler.jl:133 |
Member
Author
|
Amazing, thanks for trying it out and for the MWE. I'll patch it. |
83ca47d to
9f92008
Compare
9f92008 to
8192e9e
Compare
Member
Author
|
InterfaceII is fixed in another PR |
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.
Close #3990