Skip to content

Commit f43fa1c

Browse files
committed
test: test updates
1 parent fc1fc7f commit f43fa1c

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

src/systems/systems.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ $(SIGNATURES)
1717
Structurally simplify algebraic equations in a system and compute the
1818
topological sort of the observed equations in `sys`.
1919
20-
### Optional Arguments:
21-
+ optional argument `io` may take a tuple `(inputs, outputs)`. This will convert all `inputs` to parameters and allow them to be unconnected, i.e., simplification will allow models where `n_unknowns = n_equations - n_inputs`.
22-
2320
### Optional Keyword Arguments:
2421
+ When `simplify=true`, the `simplify` function will be applied during the tearing process.
2522
+ `allow_symbolic=false`, `allow_parameter=true`, and `conservative=false` limit the coefficient types during tearing. In particular, `conservative=true` limits tearing to only solve for trivial linear systems where the coefficient has the absolute value of ``1``.
2623
+ `fully_determined=true` controls whether or not an error will be thrown if the number of equations don't match the number of inputs, outputs, and equations.
24+
+ `inputs`, `outputs` and `disturbance_inputs` are passed as keyword arguments.` All inputs` get converted to parameters and are allowed to be unconnected, allowing models where `n_unknowns = n_equations - n_inputs`.
2725
"""
2826
function structural_simplify(
2927
sys::AbstractSystem; additional_passes = [], simplify = false, split = true,

test/clock.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ By inference:
6565
ci, varmap = infer_clocks(sys)
6666
eqmap = ci.eq_domain
6767
tss, inputs, continuous_id = ModelingToolkit.split_system(deepcopy(ci))
68-
sss, = ModelingToolkit._structural_simplify!(
69-
deepcopy(tss[continuous_id]), (inputs[continuous_id], ()))
68+
sss = ModelingToolkit._structural_simplify!(deepcopy(tss[continuous_id]), inputs = inputs[continuous_id], outputs = [])
7069
@test equations(sss) == [D(x) ~ u - x]
71-
sss, = ModelingToolkit._structural_simplify!(deepcopy(tss[1]), (inputs[1], ()))
70+
sss = ModelingToolkit._structural_simplify!(deepcopy(tss[1]), inputs = inputs[1], outputs = [])
7271
@test isempty(equations(sss))
7372
d = Clock(dt)
7473
k = ShiftIndex(d)

test/code_generation.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ end
7070
@parameters p[1:2] (f::Function)(..)
7171
@named sys = ODESystem(
7272
[D(x[0]) ~ p[1] * x[0] + x[2], D(x[1]) ~ p[2] * f(x) + x[2]], t)
73-
sys, = structural_simplify(sys, ([x[2]], []))
73+
sys, = structural_simplify(sys, inputs = [x[2]], outputs = [])
7474
@test is_parameter(sys, x[2])
7575
prob = ODEProblem(sys, [x[0] => 1.0, x[1] => 1.0], (0.0, 1.0),
7676
[p => ones(2), f => sum, x[2] => 2.0])

test/input_output_handling.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
@test !is_bound(sys31, sys1.v[2])
5151

5252
# simplification turns input variables into parameters
53-
ssys, _ = structural_simplify(sys, ([u], []))
53+
ssys = structural_simplify(sys, inputs = [u], outputs = [])
5454
@test ModelingToolkit.isparameter(unbound_inputs(ssys)[])
5555
@test !is_bound(ssys, u)
5656
@test u Set(unbound_inputs(ssys))
@@ -281,7 +281,7 @@ i = findfirst(isequal(u[1]), out)
281281
@variables x(t) u(t) [input = true]
282282
eqs = [D(x) ~ u]
283283
@named sys = ODESystem(eqs, t)
284-
@test_nowarn structural_simplify(sys, ([u], []))
284+
@test_nowarn structural_simplify(sys, inputs = [u], outputs = [])
285285

286286
#=
287287
## Disturbance input handling
@@ -366,9 +366,9 @@ eqs = [D(y₁) ~ -k₁ * y₁ + k₃ * y₂ * y₃ + u1
366366
@named sys = ODESystem(eqs, t)
367367
m_inputs = [u[1], u[2]]
368368
m_outputs = [y₂]
369-
sys_simp, input_idxs = structural_simplify(sys, (; inputs = m_inputs, outputs = m_outputs))
369+
sys_simp = structural_simplify(sys, inputs = m_inputs, outputs = m_outputs)
370370
@test isequal(unknowns(sys_simp), collect(x[1:2]))
371-
@test length(input_idxs) == 2
371+
@test length(inputs(sys_simp)) == 2
372372

373373
# https://github.com/SciML/ModelingToolkit.jl/issues/1577
374374
@named c = Constant(; k = 2)

test/odesystem.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1285,11 +1285,11 @@ end
12851285
@named sys = ODESystem(
12861286
[D(u) ~ (sum(u) + sum(x) + sum(p) + sum(o)) * x, o ~ prod(u) * x],
12871287
t, [u..., x..., o...], [p...])
1288-
sys1, = structural_simplify(sys, ([x...], []))
1288+
sys1 = structural_simplify(sys, inputs = [x...], outputs = [])
12891289
fn1, = ModelingToolkit.generate_function(sys1; expression = Val{false})
12901290
ps = MTKParameters(sys1, [x => 2ones(2), p => 3ones(2, 2)])
12911291
@test_nowarn fn1(ones(4), ps, 4.0)
1292-
sys2, = structural_simplify(sys, ([x...], []); split = false)
1292+
sys2 = structural_simplify(sys, inputs = [x...], outputs = [], split = false)
12931293
fn2, = ModelingToolkit.generate_function(sys2; expression = Val{false})
12941294
ps = zeros(8)
12951295
setp(sys2, x)(ps, 2ones(2))
@@ -1398,7 +1398,7 @@ end
13981398
o[2] ~ sum(p) * sum(x)]
13991399

14001400
@named sys = ODESystem(eqs, t, [u..., x..., o], [p...])
1401-
sys1, = structural_simplify(sys, ([x...], [o...]), split = false)
1401+
sys1 = structural_simplify(sys, inputs = [x...], outputs = [o...], split = false)
14021402

14031403
@test_nowarn ModelingToolkit.build_explicit_observed_function(sys1, u; inputs = [x...])
14041404

test/reduction.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ eqs = [D(x) ~ σ * (y - x)
233233
u ~ z + a]
234234

235235
lorenz1 = ODESystem(eqs, t, name = :lorenz1)
236-
lorenz1_reduced, _ = structural_simplify(lorenz1, ([z], []))
236+
lorenz1_reduced, _ = structural_simplify(lorenz1, inputs = [z], outputs = [])
237237
@test z in Set(parameters(lorenz1_reduced))
238238

239239
# #2064

0 commit comments

Comments
 (0)