Skip to content

Commit 9dcc6b9

Browse files
committed
test fixes
1 parent f388613 commit 9dcc6b9

File tree

7 files changed

+26
-27
lines changed

7 files changed

+26
-27
lines changed

src/inputoutput.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function add_input_disturbance(sys, dist::DisturbanceModel, inputs = nothing; kw
430430
augmented_sys = ODESystem(eqs, t, systems = [dsys], name = gensym(:outer))
431431
augmented_sys = extend(augmented_sys, sys)
432432

433-
(f_oop, f_ip), dvs, p, io_sys = generate_control_function(augmented_sys, all_inputs,
433+
f, dvs, p, io_sys = generate_control_function(augmented_sys, all_inputs,
434434
[d]; kwargs...)
435-
(f_oop, f_ip), augmented_sys, dvs, p, io_sys
435+
f, augmented_sys, dvs, p, io_sys
436436
end

src/structural_transformation/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function check_consistency(state::TransformationState, orig_inputs; nothrow = fa
9696
fullvars = get_fullvars(state)
9797
neqs = n_concrete_eqs(state)
9898
@unpack graph, var_to_diff = state.structure
99+
@show equations(state.sys)
99100
highest_vars = computed_highest_diff_variables(complete!(state.structure))
100101
n_highest_vars = 0
101102
for (v, h) in enumerate(highest_vars)

src/systems/diffeqs/odesystem.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,7 @@ function validate_vars_and_find_ps!(auxvars, auxps, sysvars, iv)
803803

804804
for var in auxvars
805805
if !iscall(var)
806-
occursin(iv, var) && (var sts ||
807-
throw(ArgumentError("Time-dependent variable $var is not an unknown of the system.")))
806+
var sts || throw(ArgumentError("Time-independent variable $var is not an unknown of the system."))
808807
elseif length(arguments(var)) > 1
809808
throw(ArgumentError("Too many arguments for variable $var."))
810809
elseif length(arguments(var)) == 1

test/downstream/test_disturbance_model.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ sol = solve(prob, Tsit5())
149149
## Generate function for an augmented Unscented Kalman Filter =====================
150150
# temp = open_loop(model_with_disturbance, :d)
151151
outputs = [P.inertia1.phi, P.inertia2.phi, P.inertia1.w, P.inertia2.w]
152-
(f_oop1, f_ip), x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function(
152+
f, x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function(
153153
model_with_disturbance, [:u], [:d1, :d2, :dy], split = false)
154154

155-
(f_oop2, f_ip2), x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function(
155+
f, x_sym, p_sym, io_sys = ModelingToolkit.generate_control_function(
156156
model_with_disturbance, [:u], [:d1, :d2, :dy],
157157
disturbance_argument = true, split = false)
158158

@@ -168,22 +168,22 @@ x0, p = ModelingToolkit.get_u0_p(io_sys, op, op)
168168
x = zeros(5)
169169
u = zeros(1)
170170
d = zeros(3)
171-
@test f_oop2(x, u, p, t, d) == zeros(5)
171+
@test f(x, u, p, t, d) == zeros(5)
172172
@test measurement(x, u, p, 0.0) == [0, 0, 0, 0]
173173
@test measurement2(x, u, p, 0.0, d) == [0]
174174

175175
# Add to the integrating disturbance input
176176
d = [1, 0, 0]
177-
@test sort(f_oop2(x, u, p, 0.0, d)) == [0, 0, 0, 1, 1] # Affects disturbance state and one velocity
177+
@test sort(f(x, u, p, 0.0, d)) == [0, 0, 0, 1, 1] # Affects disturbance state and one velocity
178178
@test measurement2(x, u, p, 0.0, d) == [0]
179179

180180
d = [0, 1, 0]
181-
@test sort(f_oop2(x, u, p, 0.0, d)) == [0, 0, 0, 0, 1] # Affects one velocity
181+
@test sort(f(x, u, p, 0.0, d)) == [0, 0, 0, 0, 1] # Affects one velocity
182182
@test measurement(x, u, p, 0.0) == [0, 0, 0, 0]
183183
@test measurement2(x, u, p, 0.0, d) == [0]
184184

185185
d = [0, 0, 1]
186-
@test sort(f_oop2(x, u, p, 0.0, d)) == [0, 0, 0, 0, 0] # Affects nothing
186+
@test sort(f(x, u, p, 0.0, d)) == [0, 0, 0, 0, 0] # Affects nothing
187187
@test measurement(x, u, p, 0.0) == [0, 0, 0, 0]
188188
@test measurement2(x, u, p, 0.0, d) == [1] # We have now disturbed the output
189189

test/extensions/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
99
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1010
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
1111
NonlinearSolveHomotopyContinuation = "2ac3b008-d579-4536-8c91-a1a5998c2f8b"
12+
OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8"
1213
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
1314
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
1415
SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226"

test/input_output_handling.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ end
173173
p = [rand()]
174174
x = [rand()]
175175
u = [rand()]
176-
@test f[1](x, u, p, 1) -x + u
176+
@test f(x, u, p, 1) -x + u
177177

178178
# With disturbance inputs
179179
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
@@ -191,7 +191,7 @@ end
191191
p = [rand()]
192192
x = [rand()]
193193
u = [rand()]
194-
@test f[1](x, u, p, 1) -x + u
194+
@test f(x, u, p, 1) -x + u
195195

196196
## With added d argument
197197
@variables x(t)=0 u(t)=0 [input = true] d(t)=0
@@ -210,7 +210,7 @@ end
210210
x = [rand()]
211211
u = [rand()]
212212
d = [rand()]
213-
@test f[1](x, u, p, t, d) -x + u + [d[]^2]
213+
@test f(x, u, p, t, d) -x + u + [d[]^2]
214214
end
215215
end
216216

@@ -273,7 +273,7 @@ x = ModelingToolkit.varmap_to_vars(
273273
merge(ModelingToolkit.defaults(model),
274274
Dict(D.(unknowns(model)) .=> 0.0)), dvs)
275275
u = [rand()]
276-
out = f[1](x, u, p, 1)
276+
out = f(x, u, p, 1)
277277
i = findfirst(isequal(u[1]), out)
278278
@test i isa Int
279279
@test iszero(out[[1:(i - 1); (i + 1):end]])
@@ -333,7 +333,7 @@ model_outputs = [model.inertia1.w, model.inertia2.w, model.inertia1.phi, model.i
333333
@named dmodel = Blocks.StateSpace([0.0], [1.0], [1.0], [0.0]) # An integrating disturbance
334334

335335
@named dist = ModelingToolkit.DisturbanceModel(model.torque.tau.u, dmodel)
336-
(f_oop, f_ip), outersys, dvs, p, io_sys = ModelingToolkit.add_input_disturbance(model, dist)
336+
f, outersys, dvs, p, io_sys = ModelingToolkit.add_input_disturbance(model, dist)
337337

338338
@unpack u, d = outersys
339339
matrices, ssys = linearize(outersys, [u, d], model_outputs)
@@ -348,8 +348,8 @@ x0 = randn(5)
348348
x1 = copy(x0) + x_add # add disturbance state perturbation
349349
u = randn(1)
350350
pn = MTKParameters(io_sys, [])
351-
xp0 = f_oop(x0, u, pn, 0)
352-
xp1 = f_oop(x1, u, pn, 0)
351+
xp0 = f(x0, u, pn, 0)
352+
xp1 = f(x1, u, pn, 0)
353353

354354
@test xp0 matrices.A * x0 + matrices.B * [u; 0]
355355
@test xp1 matrices.A * x1 + matrices.B * [u; 0]
@@ -402,7 +402,7 @@ outs = collect(complete(model).output.u)
402402
disturbed_input = ins[1]
403403
@named dist_integ = DisturbanceModel(disturbed_input, integrator)
404404

405-
(f_oop, f_ip), augmented_sys, dvs, p = ModelingToolkit.add_input_disturbance(model,
405+
f, augmented_sys, dvs, p = ModelingToolkit.add_input_disturbance(model,
406406
dist_integ,
407407
ins)
408408

@@ -447,7 +447,7 @@ end
447447
@named sys = ODESystem(eqs, t, [x], [])
448448

449449
f, dvs, ps, io_sys = ModelingToolkit.generate_control_function(sys, simplify = true)
450-
@test f[1]([0.5], nothing, MTKParameters(io_sys, []), 0.0) [1.0]
450+
@test f([0.5], nothing, MTKParameters(io_sys, []), 0.0) [1.0]
451451
end
452452

453453
@testset "With callable symbolic" begin
@@ -459,5 +459,5 @@ end
459459
p = MTKParameters(io_sys, [])
460460
u = [1.0]
461461
x = [1.0]
462-
@test_nowarn f[1](x, u, p, 0.0)
462+
@test_nowarn f(x, u, p, 0.0)
463463
end

test/odesystem.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,12 @@ sys = complete(sys)
472472

473473
# check inputs
474474
let
475-
@parameters f k d
476-
@variables x(t) (t)
477-
δ = D
475+
@parameters k d
476+
@variables x(t) (t) f(t) [input = true]
478477

479-
eqs = [δ(x) ~ ẋ, δ(ẋ) ~ f - k * x - d * ẋ]
480-
@named sys = ODESystem(eqs, t, [x, ẋ], [f, d, k]; controls = [f])
481-
482-
calculate_control_jacobian(sys)
478+
eqs = [D(x) ~ ẋ, D(ẋ) ~ f - k * x - d * ẋ]
479+
@named sys = ODESystem(eqs, t, [x, ẋ], [d, k])
480+
sys, _ = structural_simplify(sys, ([f], []))
483481

484482
@test isequal(calculate_control_jacobian(sys),
485483
reshape(Num[0, 1], 2, 1))

0 commit comments

Comments
 (0)