Skip to content

Commit 6a1f2f1

Browse files
committed
fix: require simplification again
1 parent ea461ba commit 6a1f2f1

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/linearization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function linearization_function(sys::AbstractSystem, inputs = inputs(sys),
4646
warn_empty_op = true,
4747
kwargs...)
4848
if !iscomplete(sys)
49-
sys = structural_simplify(sys; inputs, outputs)
49+
error("A simplified `ODESystem` is required. Call `structural_simplify` on the system with the inputs and outputs before creating the linearization function.")
5050
end
5151
op = Dict(op)
5252
if isempty(op) && warn_empty_op

src/systems/analysis_points.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,7 @@ function open_loop(sys, ap::Union{Symbol, AnalysisPoint}; system_modifier = iden
928928
return system_modifier(sys), vars
929929
end
930930

931-
function linearization_function(sys::AbstractSystem,
932-
inputs::Union{Symbol, Vector{Symbol}, AnalysisPoint, Vector{AnalysisPoint}},
931+
function ap_preprocessing(sys::AbstractSystem, inputs::Union{Symbol, Vector{Symbol}, AnalysisPoint, Vector{AnalysisPoint}},
933932
outputs; loop_openings = [], system_modifier = identity, kwargs...)
934933
loop_openings = Set(map(nameof, canonicalize_ap(sys, loop_openings)))
935934
inputs = canonicalize_ap(sys, inputs)
@@ -958,7 +957,13 @@ function linearization_function(sys::AbstractSystem,
958957
end
959958

960959
sys = handle_loop_openings(sys, map(AnalysisPoint, collect(loop_openings)))
960+
sys, input_vars, output_vars
961+
end
961962

963+
function linearization_function(sys::AbstractSystem,
964+
inputs::Union{Symbol, Vector{Symbol}, AnalysisPoint, Vector{AnalysisPoint}},
965+
outputs; loop_openings = [], system_modifier = identity, kwargs...)
966+
sys, inputs, outputs = ap_preprocessing(sys; inputs, outputs, loop_openings, system_modifier, kwargs...)
962967
return linearization_function(system_modifier(sys), input_vars, output_vars; kwargs...)
963968
end
964969

src/systems/systems.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function structural_simplify(
3232
disturbance_inputs = Any[],
3333
kwargs...)
3434
isscheduled(sys) && throw(RepeatedStructuralSimplificationError())
35+
if inputs isa Union{Symbol, Vector{Symbol}, AnalysisPoint, Vector{AnalysisPoint}}
36+
sys, inputs, outputs = ap_preprocessing(sys, inputs, outputs, kwargs...)
37+
end
38+
3539
newsys′ = __structural_simplification(sys; simplify,
3640
allow_symbolic, allow_parameter, conservative, fully_determined,
3741
inputs, outputs, disturbance_inputs,

test/downstream/linearize.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ lsys = linearize(sys2)
3333
@test lsys.C[] == 0
3434
@test lsys.D[] == 1
3535

36-
lsys = linearize(sys, r, r) # Test allow scalars
36+
lsys = linearize(sys2, r, r) # Test allow scalars
3737

3838
@test lsys.A[] == -2
3939
@test lsys.B[] == 1
@@ -269,7 +269,8 @@ closed_loop = ODESystem(connections, t, systems = [model, pid, filt, sensor, r,
269269
filt.xd => 0.0
270270
])
271271

272-
@test_nowarn linearize(closed_loop, :r, :y; warn_empty_op = false)
272+
closed_loop = structural_simplify(closed_loop, inputs = :r, outputs = :y)
273+
linearize(closed_loop; warn_empty_op = false)
273274

274275
# https://discourse.julialang.org/t/mtk-change-in-linearize/115760/3
275276
@mtkmodel Tank_noi begin
@@ -299,6 +300,7 @@ end
299300

300301
@named tank_noi = Tank_noi()
301302
@unpack md_i, h, m = tank_noi
303+
tank_noi = structural_simplify(tank_noi, inputs = [md_i], outputs = [h])
302304
m_ss = 2.4000000003229878
303305
@test_nowarn linearize(tank_noi, [md_i], [h]; op = Dict(m => m_ss, md_i => 2))
304306

@@ -307,6 +309,7 @@ m_ss = 2.4000000003229878
307309
@parameters p = 1.0
308310
eqs = [D(x) ~ p * u, x ~ y]
309311
@named sys = ODESystem(eqs, t)
312+
sys = structural_simplify(sys, inputs = [u])
310313

311314
matrices1 = linearize(sys, [u], []; op = Dict(x => 2.0))
312315
matrices2 = linearize(sys, [u], []; op = Dict(y => 2.0))

0 commit comments

Comments
 (0)