Skip to content

Commit e9617e5

Browse files
authored
Revert "Throw an error if structural simplification is applied twice"
1 parent be151e3 commit e9617e5

File tree

12 files changed

+35
-66
lines changed

12 files changed

+35
-66
lines changed

.github/workflows/Tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ jobs:
2828
group:
2929
- InterfaceI
3030
- InterfaceII
31-
- SymbolicIndexingInterface
32-
- Extended
3331
- Extensions
3432
- Downstream
3533
- RegressionI

src/systems/systems.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ function System(eqs::AbstractVector{<:Equation}, iv, args...; name = nothing,
33
ODESystem(eqs, iv, args...; name, kw..., checks = false)
44
end
55

6-
const REPEATED_SIMPLIFICATION_MESSAGE = "Structural simplification cannot be applied to a completed system. Double simplification is not allowed."
7-
8-
struct RepeatedStructuralSimplificationError <: Exception end
9-
10-
function Base.showerror(io::IO, e::RepeatedStructuralSimplificationError)
11-
print(io, REPEATED_SIMPLIFICATION_MESSAGE)
12-
end
13-
146
"""
157
$(SIGNATURES)
168
@@ -29,7 +21,6 @@ function structural_simplify(
2921
sys::AbstractSystem, io = nothing; simplify = false, split = true,
3022
allow_symbolic = false, allow_parameter = true, conservative = false, fully_determined = true,
3123
kwargs...)
32-
iscomplete(sys) && throw(RepeatedStructuralSimplificationError())
3324
newsys′ = __structural_simplify(sys, io; simplify,
3425
allow_symbolic, allow_parameter, conservative, fully_determined,
3526
kwargs...)

test/downstream/linearize.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ matrices = linfun([1.0], Dict(p => 3.0), 1.0)
312312
@parameters p
313313
eqs = [0 ~ x * log(y) - p]
314314
@named sys = ODESystem(eqs, t; defaults = [p => 1.0])
315+
sys = complete(sys)
315316
@test_nowarn linearize(
316317
sys, [x], []; op = Dict(x => 1.0), allow_input_derivatives = true)
317318
end

test/initial_values.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ end
116116
@variables x(t)
117117
@parameters p
118118
@mtkbuild sys = ODESystem([D(x) ~ p], t; defaults = [x => t, p => 2t])
119-
prob = ODEProblem(sys, [], (1.0, 2.0), [])
119+
prob = ODEProblem(structural_simplify(sys), [], (1.0, 2.0), [])
120120
@test prob[x] == 1.0
121121
@test prob.ps[p] == 2.0

test/input_output_handling.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ disturbed_input = ins[1]
362362
dist_integ,
363363
ins)
364364

365-
getter_sys = complete(augmented_sys)
365+
augmented_sys = complete(augmented_sys)
366366
matrices, ssys = linearize(augmented_sys,
367367
[
368-
getter_sys.u,
369-
getter_sys.input.u[2],
370-
getter_sys.d
368+
augmented_sys.u,
369+
augmented_sys.input.u[2],
370+
augmented_sys.d
371371
], outs)
372372
@test matrices.A [A [1; 0]; zeros(1, 2) -0.001]
373373
@test matrices.B == I

test/mtkparameters.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ function level1()
144144
eqs = [D(x) ~ p1 * x - p2 * x * y
145145
D(y) ~ -p3 * y + p4 * x * y]
146146

147-
sys = structural_simplify(ODESystem(
148-
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4]))
147+
sys = structural_simplify(complete(ODESystem(
148+
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4])))
149149
prob = ODEProblem{true, SciMLBase.FullSpecialize}(sys)
150150
end
151151

@@ -158,8 +158,8 @@ function level2()
158158
eqs = [D(x) ~ p1 * x - p23[1] * x * y
159159
D(y) ~ -p23[2] * y + p4 * x * y]
160160

161-
sys = structural_simplify(ODESystem(
162-
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4]))
161+
sys = structural_simplify(complete(ODESystem(
162+
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4])))
163163
prob = ODEProblem{true, SciMLBase.FullSpecialize}(sys)
164164
end
165165

@@ -172,8 +172,8 @@ function level3()
172172
eqs = [D(x) ~ p1 * x - p23[1] * x * y
173173
D(y) ~ -p23[2] * y + p4 * x * y]
174174

175-
sys = structural_simplify(ODESystem(
176-
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4]))
175+
sys = structural_simplify(complete(ODESystem(
176+
eqs, t, tspan = (0, 3.0), name = :sys, parameter_dependencies = [y0 => 2p4])))
177177
prob = ODEProblem{true, SciMLBase.FullSpecialize}(sys)
178178
end
179179

test/nonlinearsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ end
251251
0 ~ z - cos(x),
252252
0 ~ x * y]
253253
@named ns = NonlinearSystem(eqs, [x, y, z], [])
254+
ns = complete(ns)
254255
vs = [unknowns(ns); parameters(ns)]
255256
ss_mtk = structural_simplify(ns)
256257
prob = NonlinearProblem(ss_mtk, vs .=> 1.0)

test/reduction.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ __x = x
7575
# Reduced Flattened System
7676

7777
reduced_system = structural_simplify(connected)
78+
reduced_system2 = structural_simplify(tearing_substitution(structural_simplify(tearing_substitution(structural_simplify(connected)))))
79+
80+
@test isempty(setdiff(unknowns(reduced_system), unknowns(reduced_system2)))
81+
@test isequal(equations(tearing_substitution(reduced_system)), equations(reduced_system2))
82+
@test isequal(observed(reduced_system), observed(reduced_system2))
7883
@test setdiff(unknowns(reduced_system),
7984
[s
8085
a

test/runtests.jl

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,57 @@ end
3232
@safetestset "Dynamic Quantities Test" include("dq_units.jl")
3333
@safetestset "Unitful Quantities Test" include("units.jl")
3434
@safetestset "Mass Matrix Test" include("mass_matrix.jl")
35+
@safetestset "SteadyStateSystem Test" include("steadystatesystems.jl")
36+
@safetestset "SDESystem Test" include("sdesystem.jl")
37+
@safetestset "DDESystem Test" include("dde.jl")
38+
@safetestset "NonlinearSystem Test" include("nonlinearsystem.jl")
3539
@safetestset "InitializationSystem Test" include("initializationsystem.jl")
3640
@safetestset "Guess Propagation" include("guess_propagation.jl")
3741
@safetestset "Hierarchical Initialization Equations" include("hierarchical_initialization_eqs.jl")
42+
@safetestset "PDE Construction Test" include("pde.jl")
43+
@safetestset "JumpSystem Test" include("jumpsystem.jl")
44+
@safetestset "Constraints Test" include("constraints.jl")
3845
@safetestset "Reduction Test" include("reduction.jl")
3946
@safetestset "Split Parameters Test" include("split_parameters.jl")
4047
@safetestset "StaticArrays Test" include("static_arrays.jl")
4148
@safetestset "Components Test" include("components.jl")
4249
@safetestset "Model Parsing Test" include("model_parsing.jl")
50+
@safetestset "print_tree" include("print_tree.jl")
4351
@safetestset "Error Handling" include("error_handling.jl")
4452
@safetestset "StructuralTransformations" include("structural_transformation/runtests.jl")
4553
@safetestset "State Selection Test" include("state_selection.jl")
4654
@safetestset "Symbolic Event Test" include("symbolic_events.jl")
4755
@safetestset "Stream Connect Test" include("stream_connectors.jl")
4856
@safetestset "Domain Connect Test" include("domain_connectors.jl")
4957
@safetestset "Lowering Integration Test" include("lowering_solving.jl")
58+
@safetestset "Test Big System Usage" include("bigsystem.jl")
5059
@safetestset "Dependency Graph Test" include("dep_graphs.jl")
5160
@safetestset "Function Registration Test" include("function_registration.jl")
5261
@safetestset "Precompiled Modules Test" include("precompile_test.jl")
62+
@safetestset "Variable Utils Test" include("variable_utils.jl")
63+
@safetestset "Variable Metadata Test" include("test_variable_metadata.jl")
5364
@safetestset "DAE Jacobians Test" include("dae_jacobian.jl")
5465
@safetestset "Jacobian Sparsity" include("jacobiansparsity.jl")
5566
@safetestset "Modelingtoolkitize Test" include("modelingtoolkitize.jl")
67+
@safetestset "OptimizationSystem Test" include("optimizationsystem.jl")
5668
@safetestset "FuncAffect Test" include("funcaffect.jl")
5769
@safetestset "Constants Test" include("constants.jl")
5870
@safetestset "Parameter Dependency Test" include("parameter_dependencies.jl")
5971
@safetestset "Generate Custom Function Test" include("generate_custom_function.jl")
6072
@safetestset "Initial Values Test" include("initial_values.jl")
73+
@safetestset "Discrete System" include("discrete_system.jl")
6174
@safetestset "Equation Type Accessors Test" include("equation_type_accessors.jl")
6275
@safetestset "Equations with complex values" include("complex.jl")
6376
end
6477
end
6578

66-
if GROUP == "All" || GROUP == "InterfaceII"
67-
@testset "InterfaceII" begin
68-
@safetestset "Variable Utils Test" include("variable_utils.jl")
69-
@safetestset "Variable Metadata Test" include("test_variable_metadata.jl")
70-
@safetestset "OptimizationSystem Test" include("optimizationsystem.jl")
71-
@safetestset "Discrete System" include("discrete_system.jl")
72-
@safetestset "SteadyStateSystem Test" include("steadystatesystems.jl")
73-
@safetestset "SDESystem Test" include("sdesystem.jl")
74-
@safetestset "DDESystem Test" include("dde.jl")
75-
@safetestset "NonlinearSystem Test" include("nonlinearsystem.jl")
76-
@safetestset "PDE Construction Test" include("pde.jl")
77-
@safetestset "JumpSystem Test" include("jumpsystem.jl")
78-
@safetestset "print_tree" include("print_tree.jl")
79-
@safetestset "Constraints Test" include("constraints.jl")
80-
end
81-
end
82-
83-
if GROUP == "All" || GROUP == "SymbolicIndexingInterface"
79+
if GROUP == "All" || GROUP == "InterfaceI" || GROUP == "SymbolicIndexingInterface"
8480
@safetestset "SymbolicIndexingInterface test" include("symbolic_indexing_interface.jl")
8581
@safetestset "SciML Problem Input Test" include("sciml_problem_inputs.jl")
8682
@safetestset "MTKParameters Test" include("mtkparameters.jl")
8783
end
8884

89-
if GROUP == "All" || GROUP == "Extended"
90-
@safetestset "Test Big System Usage" include("bigsystem.jl")
85+
if GROUP == "All" || GROUP == "InterfaceII"
9186
println("C compilation test requires gcc available in the path!")
9287
@safetestset "C Compilation Test" include("ccompile.jl")
9388
@testset "Distributed Test" include("distributed.jl")

test/structural_transformation/errors.jl

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)