Hi everyone,
I am building a composite model in order to test my binary valve model and I am running into an error, which I do not understand. This is the code for building up the system and running it. I can also provide simplified version of the submodels to complete the example code if needed.
# Build a composite model with callback
@mtkmodel TestSys begin
@components begin
reservoir = Reservoir(p_set = 2.0, V = 1.0)
pressure_source = PressureSource(p_set = 1.0)
binary_valve = BinaryValve(S = false)
end
@equations begin
connect(reservoir.port, binary_valve.port_in)
connect(binary_valve.port_out, pressure_source.port)
end
@discrete_events begin
[0.5] => [binary_valve.S ~ true]
end
end
# Build an run the system
@mtkbuild sys = TestSys()
prob = ODEProblem(sys, [], (0.0, 1.0))
sol = solve(prob)
Now, if I try to run this I get an error:
ERROR: MethodError: reeval_internals_due_to_modification!(::OrdinaryDiffEqCore.ODEIntegrator{CompositeAlgorithm{1, Tuple{Tsit5{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}, Vern7{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}, Rosenbrock23{1, false, Nothing, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!)}, Rodas5P{1, false, Nothing, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!)}, FBDF{5, 1, false, Nothing, NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, Nothing, Nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!)}, FBDF{5, 1, false, KrylovJL{typeof(Krylov.gmres!), Int64, Nothing, Tuple{}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}}, NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, Nothing, Nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!)}}, OrdinaryDiffEqCore.AutoSwitchCache{Tuple{Tsit5{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}, Vern7{typeof(OrdinaryDiffEqCore.trivial_limiter!), ...
Possible fix, define
reeval_internals_due_to_modification!(::OrdinaryDiffEqCore.ODEIntegrator, ::Bool)
Stacktrace:
[1] apply_discrete_callback!
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\callbacks.jl:627 [inlined]
[2] apply_discrete_callback!
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\callbacks.jl:641 [inlined]
[3] handle_callbacks!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
@ OrdinaryDiffEqCore C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqCore\YWZVL\src\integrators\integrator_utils.jl:355
[4] _loopfooter!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
@ OrdinaryDiffEqCore C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqCore\YWZVL\src\integrators\integrator_utils.jl:243
[5] loopfooter!
@ C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqCore\YWZVL\src\integrators\integrator_utils.jl:207 [inlined]
[6] solve!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
@ OrdinaryDiffEqCore C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqCore\YWZVL\src\solve.jl:552
[7] __solve(::ODEProblem{…}, ::CompositeAlgorithm{…}; kwargs::@Kwargs{…})
@ OrdinaryDiffEqCore C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqCore\YWZVL\src\solve.jl:7
[8] __solve
@ C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqCore\YWZVL\src\solve.jl:1 [inlined]
[9] solve_call(_prob::ODEProblem{…}, args::CompositeAlgorithm{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…})
@ DiffEqBase C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:612
[10] solve_call
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:569 [inlined]
[11] solve_up(prob::ODEProblem{…}, sensealg::Nothing, u0::Vector{…}, p::MTKParameters{…}, args::CompositeAlgorithm{…}; kwargs::@Kwargs{…})
@ DiffEqBase C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1092
[12] solve_up
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1078 [inlined]
[13] #solve#51
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1015 [inlined]
[14] solve
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1005 [inlined]
[15] #__solve#3
@ C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqDefault\2qVWT\src\default_alg.jl:46 [inlined]
[16] __solve
@ C:\Users\Jonathan\.julia\packages\OrdinaryDiffEqDefault\2qVWT\src\default_alg.jl:45 [inlined]
[17] #__solve#72
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1408 [inlined]
[18] __solve
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1399 [inlined]
[19] solve_call(::ODEProblem{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{})
@ DiffEqBase C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:612
[20] solve_call
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:569 [inlined]
[21] #solve_up#53
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1084 [inlined]
[22] solve_up
@ C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1078 [inlined]
[23] solve(::ODEProblem{…}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{…}, kwargs::@Kwargs{})
@ DiffEqBase C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1015
[24] solve(::ODEProblem{…})
@ DiffEqBase C:\Users\Jonathan\.julia\packages\DiffEqBase\ODi5x\src\solve.jl:1005
[25] top-level scope
@ c:\Users\Jonathan\.julia\dev\MTKWaterRunModels\test\open_issues\binary_valve_MWE.jl:93
Some type information was truncated. Use `show(err)` to see complete types.
...
I also tried this reeval_internals_due_to_modification!
suggestion but it did not work for me. I am a bit lost. Is this a bug? Does someone know this issue?