Skip to content

Commit 0dc716a

Browse files
committed
fix after rebase
1 parent fe76e38 commit 0dc716a

File tree

8 files changed

+49
-30
lines changed

8 files changed

+49
-30
lines changed

src/inputoutput.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,6 @@ function inputs_to_parameters!(state::TransformationState, inputsyms)
317317
@set! sys.unknowns = setdiff(unknowns(sys), keys(input_to_parameters))
318318
ps = parameters(sys)
319319

320-
if inputsyms !== nothing
321-
# Change order of new parameters to correspond to user-provided order in argument `inputs`
322-
d = Dict{Any, Int}()
323-
for (i, inp) in enumerate(new_parameters)
324-
d[inp] = i
325-
end
326-
permutation = [d[i] for i in inputsyms]
327-
new_parameters = new_parameters[permutation]
328-
end
329-
330320
@set! sys.ps = [ps; new_parameters]
331321
@set! state.sys = sys
332322
@set! state.fullvars = new_fullvars
@@ -429,7 +419,7 @@ function add_input_disturbance(sys, dist::DisturbanceModel, inputs = Any[]; kwar
429419
augmented_sys = extend(augmented_sys, sys)
430420
ssys = structural_simplify(augmented_sys, inputs = all_inputs, disturbance_inputs = [d])
431421

432-
(f_oop, f_ip), dvs, p, io_sys = generate_control_function(ssys, all_inputs,
422+
f, dvs, p, io_sys = generate_control_function(ssys, all_inputs,
433423
[d]; kwargs...)
434-
(f_oop, f_ip), augmented_sys, dvs, p, io_sys
424+
f, augmented_sys, dvs, p, io_sys
435425
end

src/linearization.jl

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,6 @@ function eq_idxs(sys::AbstractSystem)
143143
diff_idxs, alge_idxs
144144
end
145145

146-
"""
147-
Return the set of indexes of differential equations and algebraic equations in the simplified system.
148-
"""
149-
function eq_idxs(sys::AbstractSystem)
150-
eqs = equations(sys)
151-
alge_idxs = findall(!isdiffeq, eqs)
152-
diff_idxs = setdiff(1:length(eqs), alge_idxs)
153-
154-
diff_idxs, alge_idxs
155-
end
156-
157146
"""
158147
$(TYPEDEF)
159148
@@ -618,7 +607,7 @@ function markio!(state, orig_inputs, inputs, outputs, disturbances; check = true
618607
end
619608
(all(values(outputset)) || error(
620609
"Some specified outputs were not found in system. The following Dict indicates the found variables ",
621-
outputset))
610+
outputset))
622611
end
623612
state, orig_inputs
624613
end

src/systems/imperative_affect.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,20 @@ function Base.hash(a::ImperativeAffect, s::UInt)
9999
hash(a.ctx, s)
100100
end
101101

102-
function namespace_affects(affect::ImperativeAffect, s)
102+
namespace_affects(af::ImperativeAffect, s) = namespace_affect(af, s)
103+
function namespace_affect(affect::ImperativeAffect, s)
104+
rmn = []
105+
for modded in modified(affect)
106+
if symbolic_type(modded) == NotSymbolic() && modded isa AbstractArray
107+
res = []
108+
for m in modded
109+
push!(res, renamespace(s, m))
110+
end
111+
push!(rmn, res)
112+
else
113+
push!(rmn, renamespace(s, modded))
114+
end
115+
end
103116
ImperativeAffect(func(affect),
104117
namespace_expr.(observed(affect), (s,)),
105118
observed_syms(affect),

src/systems/systemstructure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ function structural_simplify!(state::TearingState; simplify = false,
688688
continue
689689
end
690690
disc_inputs = [inputs; clocked_inputs[i]]
691-
ss, = _structural_simplification!(state; simplify, check_consistency,
691+
ss, = _structural_simplify!(state; simplify, check_consistency,
692692
inputs = disc_inputs, outputs, disturbance_inputs,
693693
fully_determined, kwargs...)
694694
append!(appended_parameters, inputs[i], unknowns(ss))

test/extensions/test_infiniteopt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ model = structural_simplify(model; inputs, outputs)
2828
f, dvs, psym, io_sys = ModelingToolkit.generate_control_function(
2929
model, split = false)
3030

31-
f_obs = ModelingToolkit.build_explicit_observed_function(io_sys, [model.y]; inputs)
31+
f_obs = ModelingToolkit.build_explicit_observed_function(io_sys, outputs; inputs)
3232

3333
expected_state_order = [model.θ, model.ω]
3434
permutation = [findfirst(isequal(x), expected_state_order) for x in dvs] # This maps our expected state order to the actual state order

test/input_output_handling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ end
450450
@mtkbuild sys = ODESystem(eqs, t, [x], [])
451451

452452
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(sys)
453-
@test f[1]([0.5], nothing, MTKParameters(io_sys, []), 0.0) [1.0]
453+
@test f([0.5], nothing, MTKParameters(io_sys, []), 0.0) [1.0]
454454
end
455455

456456
@testset "With callable symbolic" begin

test/jumpsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ let
391391
j1 = ConstantRateJump(p1, [x1 ~ Pre(x1) + 1])
392392
j2 = MassActionJump(p2, [x2 => 1], [x3 => -1])
393393
j3 = VariableRateJump(p3, [x3 ~ Pre(x3) + 1, x4 ~ Pre(x4) + 1])
394-
j4 = MassActionJump(p4 * p5, [x1 => 1, x5 => 1], [x1 => -1, x5 => -1, x2 => 1])
395-
@named js = JumpSystem([j1, j2, j3, j4], t, [x1, x2, x3, x4, x5], [p1, p2, p3, p4, p5])
394+
j4 = MassActionJump(p4 * p4, [x1 => 1, x4 => 1], [x1 => -1, x4 => -1, x2 => 1])
395+
@named js = JumpSystem([j1, j2, j3, j4], t, [x1, x2, x3, x4], [p1, p2, p3, p4])
396396

397397
us = Set()
398398
ps = Set()

test/symbolic_events.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,3 +1305,30 @@ end
13051305
sol = solve(prob, FBDF())
13061306
@test prob.ps[g] == sol.ps[g]
13071307
end
1308+
1309+
@testset "Array parameter updates of parent components in ImperativeEffect" begin
1310+
function child(vals; name, max_time = 0.1)
1311+
vars = @variables begin
1312+
x(t) = 0.0
1313+
end
1314+
eqs = reduce(vcat, Symbolics.scalarize.([
1315+
D(x) ~ 1.0
1316+
]))
1317+
reset = ModelingToolkit.ImperativeAffect(
1318+
modified = (; vals = Symbolics.scalarize(ParentScope.(vals)), x)) do m, o, _, i
1319+
@set! m.vals = m.vals .+ 1
1320+
@set! m.x = 0.0
1321+
return m
1322+
end
1323+
return ODESystem(eqs, t, vars, []; name = name,
1324+
continuous_events = [[x ~ max_time] => reset])
1325+
end
1326+
shared_pars = @parameters begin
1327+
vals(t)[1:2] = 0.0
1328+
end
1329+
1330+
@named sys = ODESystem(Equation[], t, [], Symbolics.scalarize(vals);
1331+
systems = [child(vals; name = :child)])
1332+
sys = structural_simplify(sys)
1333+
sol = solve(ODEProblem(sys, [], (0.0, 1.0)), Tsit5())
1334+
end

0 commit comments

Comments
 (0)