Skip to content

Commit 5c25416

Browse files
committed
fix: more test fixes
1 parent b8e1f63 commit 5c25416

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

src/systems/callbacks.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,11 @@ make_affect(affect::Tuple; kwargs...) = FunctionalAffect(affect...)
240240
make_affect(affect::NamedTuple; kwargs...) = FunctionalAffect(; affect...)
241241
make_affect(affect::Affect; kwargs...) = affect
242242

243-
function make_affect(affect::Vector{Equation}; iv = nothing, algeeqs = Equation[])
243+
function make_affect(affect::Vector{Equation}; iv = nothing, algeeqs::Vector{Equation} = Equation[])
244244
isempty(affect) && return nothing
245245
isempty(algeeqs) && @warn "No algebraic equations were found for the callback defined by $(join(affect, ", ")). If the system has no algebraic equations, this can be disregarded. Otherwise pass in `algeeqs` to the SymbolicContinuousCallback constructor."
246246

247247
explicit = true
248-
affect = scalarize(affect)
249248
dvs = OrderedSet()
250249
params = OrderedSet()
251250
for eq in affect
@@ -296,8 +295,9 @@ function make_affect(affect::Vector{Equation}; iv = nothing, algeeqs = Equation[
296295
for u in dvs
297296
aff_map[u] = u
298297
end
298+
@show explicit
299299

300-
return AffectSystem(affectsys, collect(dvs), params, discretes, aff_map, explicit)
300+
AffectSystem(affectsys, collect(dvs), params, discretes, aff_map, explicit)
301301
end
302302

303303
function make_affect(affect; kwargs...)
@@ -840,7 +840,10 @@ end
840840
Compile an affect defined by a set of equations. Systems with algebraic equations will solve implicit discrete problems to obtain their next state. Systems without will generate functions that perform explicit updates.
841841
"""
842842
function compile_equational_affect(aff::Union{AffectSystem, Vector{Equation}}, sys; reset_jumps = false, kwargs...)
843-
aff isa AbstractVector && (aff = make_affect(aff, iv = get_iv(sys)))
843+
if aff isa AbstractVector
844+
aff = make_affect(aff; iv = get_iv(sys))
845+
@show is_explicit(aff)
846+
end
844847
affsys = system(aff)
845848
ps_to_update = discretes(aff)
846849
dvs_to_update = setdiff(unknowns(aff), getfield.(observed(sys), :lhs))

src/systems/model_parsing.jl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function _model_macro(mod, name, expr, isconnector)
6464
push!(exprs.args, :(systems = ODESystem[]))
6565
push!(exprs.args, :(equations = Union{Equation, Vector{Equation}}[]))
6666
push!(exprs.args, :(defaults = Dict{Num, Union{Number, Symbol, Function}}()))
67+
push!(exprs.args, :(disc_events = []))
68+
push!(exprs.args, :(cont_events = []))
6769

6870
Base.remove_linenums!(expr)
6971
for arg in expr.args
@@ -105,6 +107,8 @@ function _model_macro(mod, name, expr, isconnector)
105107
push!(exprs.args, :(push!(parameters, $(ps...))))
106108
push!(exprs.args, :(push!(systems, $(comps...))))
107109
push!(exprs.args, :(push!(variables, $(vs...))))
110+
push!(exprs.args, :(push!(disc_events, $(d_evts...))))
111+
push!(exprs.args, :(push!(cont_events, $(c_evts...))))
108112

109113
gui_metadata = isassigned(icon) > 0 ? GUIMetadata(GlobalRef(mod, name), icon[]) :
110114
GUIMetadata(GlobalRef(mod, name))
@@ -115,7 +119,7 @@ function _model_macro(mod, name, expr, isconnector)
115119
Ref(dict), [:constants, :defaults, :kwargs, :structural_parameters])
116120

117121
sys = :($ODESystem($(flatten_equations)(equations), $iv, variables, parameters;
118-
name, description = $description, systems, gui_metadata = $gui_metadata, defaults))
122+
name, description = $description, systems, gui_metadata = $gui_metadata, defaults, continuous_events = cont_events, discrete_events = disc_events))
119123

120124
if length(ext) == 0
121125
push!(exprs.args, :(var"#___sys___" = $sys))
@@ -126,16 +130,6 @@ function _model_macro(mod, name, expr, isconnector)
126130
isconnector && push!(exprs.args,
127131
:($Setfield.@set!(var"#___sys___".connector_type=$connector_type(var"#___sys___"))))
128132

129-
!isempty(c_evts) && push!(exprs.args,
130-
:($Setfield.@set!(var"#___sys___".continuous_events=$SymbolicContinuousCallback.([
131-
$(c_evts...)
132-
]))))
133-
134-
!isempty(d_evts) && push!(exprs.args,
135-
:($Setfield.@set!(var"#___sys___".discrete_events=$SymbolicDiscreteCallback.([
136-
$(d_evts...)
137-
]))))
138-
139133
f = if length(where_types) == 0
140134
:($(Symbol(:__, name, :__))(; name, $(kwargs...)) = $exprs)
141135
else
@@ -1121,6 +1115,7 @@ function parse_equations!(exprs, eqs, dict, body)
11211115
end
11221116

11231117
function parse_continuous_events!(c_evts, dict, body)
1118+
@show body
11241119
dict[:continuous_events] = []
11251120
Base.remove_linenums!(body)
11261121
for arg in body.args
@@ -1130,6 +1125,7 @@ function parse_continuous_events!(c_evts, dict, body)
11301125
end
11311126

11321127
function parse_discrete_events!(d_evts, dict, body)
1128+
@show body
11331129
dict[:discrete_events] = []
11341130
Base.remove_linenums!(body)
11351131
for arg in body.args

test/discrete_system.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ end
257257
@variables x(t) y(t)
258258
k = ShiftIndex(t)
259259
@named sys = DiscreteSystem([x ~ x^2 + y^2, y ~ x(k - 1) + y(k - 1)], t)
260-
@test_throws ["algebraic equations", "ImplicitDiscreteSystem"] structural_simplify(sys)
261260

262261
@testset "Passing `nothing` to `u0`" begin
263262
@variables x(t) = 1

test/fmi/fmi.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ end
157157
@testset "v2, CS" begin
158158
fmu = loadFMU(joinpath(FMU_DIR, "SimpleAdder.fmu"); type = :CS)
159159
@named adder = MTK.FMIComponent(
160-
Val(2); fmu, type = :CS, communication_step_size = 1e-6,
161-
reinitializealg = BrownFullBasicInit())
160+
Val(2); fmu, type = :CS, communication_step_size = 1e-6)
162161
@test MTK.isinput(adder.a)
163162
@test MTK.isinput(adder.b)
164163
@test MTK.isoutput(adder.out)
@@ -210,8 +209,7 @@ end
210209
@testset "v3, CS" begin
211210
fmu = loadFMU(joinpath(FMU_DIR, "StateSpace.fmu"); type = :CS)
212211
@named sspace = MTK.FMIComponent(
213-
Val(3); fmu, communication_step_size = 1e-6, type = :CS,
214-
reinitializealg = BrownFullBasicInit())
212+
Val(3); fmu, communication_step_size = 1e-6, type = :CS)
215213
@test MTK.isinput(sspace.u)
216214
@test MTK.isoutput(sspace.y)
217215
@test !MTK.isinput(sspace.x) && !MTK.isoutput(sspace.x)

test/jumpsystem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ rng = StableRNG(12345)
1111
@constants h = 1
1212
@variables S(t) I(t) R(t)
1313
rate₁ = β * S * I * h
14-
affect₁ = [S ~ S - 1 * h, I ~ I + 1]
14+
affect₁ = [S ~ Pre(S) - 1 * h, I ~ Pre(I) + 1]
1515
rate₂ = γ * I + t
16-
affect₂ = [I ~ I - 1, R ~ R + 1]
16+
affect₂ = [I ~ Pre(I) - 1, R ~ Pre(R) + 1]
1717
j₁ = ConstantRateJump(rate₁, affect₁)
1818
j₂ = VariableRateJump(rate₂, affect₂)
1919
@named js = JumpSystem([j₁, j₂], t, [S, I, R], [β, γ])
@@ -59,7 +59,7 @@ jump2.affect!(integrator)
5959

6060
# test MT can make and solve a jump problem
6161
rate₃ = γ * I * h
62-
affect₃ = [I ~ I * h - 1, R ~ R + 1]
62+
affect₃ = [I ~ Pre(I) * h - 1, R ~ Pre(R) + 1]
6363
j₃ = ConstantRateJump(rate₃, affect₃)
6464
@named js2 = JumpSystem([j₁, j₃], t, [S, I, R], [β, γ])
6565
js2 = complete(js2)

test/model_parsing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ using ModelingToolkit: D_nounits
484484
[x ~ 1.5] => [x ~ 5, y ~ 1]
485485
end
486486
@discrete_events begin
487-
(t == 1.5) => [x ~ x + 5, z ~ 2]
487+
(t == 1.5) => [x ~ Pre(x) + 5, z ~ 2]
488488
end
489489
end
490490

0 commit comments

Comments
 (0)