Skip to content

refactor: remove ode_order_lowering and dae_order_lowering #3644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ include("modelingtoolkitize/nonlinearproblem.jl")

include("systems/nonlinear/homotopy_continuation.jl")
include("systems/nonlinear/initializesystem.jl")
include("systems/diffeqs/first_order_transform.jl")
include("systems/diffeqs/basic_transformations.jl")

include("systems/pde/pdesystem.jl")
Expand Down Expand Up @@ -291,9 +290,8 @@ export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbanc
tunable_parameters, isirreducible, getdescription, hasdescription,
hasunit, getunit, hasconnect, getconnect,
hasmisc, getmisc, state_priority
export ode_order_lowering, dae_order_lowering, liouville_transform,
change_independent_variable, substitute_component, add_accumulations,
noise_to_brownians
export liouville_transform, change_independent_variable, substitute_component,
add_accumulations, noise_to_brownians
export PDESystem
export Differential, expand_derivatives, @derivatives
export Equation, ConstrainedEquation
Expand Down
106 changes: 0 additions & 106 deletions src/systems/diffeqs/first_order_transform.jl

This file was deleted.

76 changes: 0 additions & 76 deletions test/lowering_solving.jl

This file was deleted.

110 changes: 0 additions & 110 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,32 +153,6 @@ du = [0.0]
f(du, [1.0], [t -> t + 2], 5.0)
@test du ≈ [27561]

@testset "Issue#17: Conversion to first order ODEs" begin
D3 = D^3
D2 = D^2
@variables u(t) uˍtt(t) uˍt(t) xˍt(t)
eqs = [D3(u) ~ 2(D2(u)) + D(u) + D(x) + 1
D2(x) ~ D(x) + 2]
@named de = System(eqs, t)
de1 = ode_order_lowering(de)

@testset "Issue#219: Ordering of equations in `ode_order_lowering`" begin
lowered_eqs = [D(uˍtt) ~ 2uˍtt + uˍt + xˍt + 1
D(xˍt) ~ xˍt + 2
D(uˍt) ~ uˍtt
D(u) ~ uˍt
D(x) ~ xˍt]
@test isequal(
[ModelingToolkit.var_from_nested_derivative(eq.lhs)[1] for eq in equations(de1)],
unknowns(@named lowered = System(lowered_eqs, t)))
end

test_diffeq_inference("first-order transform", de1, t, [uˍtt, xˍt, uˍt, u, x], [])
du = zeros(5)
ODEFunction(complete(de1))(du, ones(5), nothing, 0.1)
@test du == [5.0, 3.0, 1.0, 1.0, 1.0]
end

# Internal calculations
@parameters σ
a = y - x
Expand Down Expand Up @@ -348,16 +322,6 @@ eqs = [D(x) ~ σ * (y - x),
@test issym(equations(sys)[1].rhs)
end

@testset "Issue#708" begin
@parameters a
@variables x(t) y(t) z(t)
@named sys = System([D(x) ~ y, 0 ~ x + z, 0 ~ x - y], t, [z, y, x], [])

sys2 = ode_order_lowering(sys)
M = ModelingToolkit.calculate_massmatrix(sys2)
@test M == Diagonal([1, 0, 0])
end

# issue #609
@variables x1(t) x2(t)

Expand Down Expand Up @@ -416,22 +380,6 @@ eqs = [
]
@test_throws ArgumentError ModelingToolkit.System(eqs, t, vars, pars, name = :foo)

@variables x(t)
@parameters M b k
eqs = [D(D(x)) ~ -b / M * D(x) - k / M * x]
ps = [M, b, k]
default_u0 = [D(x) => 0.0, x => 10.0]
default_p = [M => 1.0, b => 1.0, k => 1.0]
@named sys = System(eqs, t, [x], ps; defaults = [default_u0; default_p])
sys = ode_order_lowering(sys)
sys = complete(sys)
prob = ODEProblem(sys, nothing, tspan)
sol = solve(prob, Tsit5())
@test sol.t[end] == tspan[end]
@test sum(abs, sol.u[end]) < 1
prob = ODEProblem{false}(sys, nothing, tspan; u0_constructor = x -> SVector(x...))
@test prob.u0 isa SVector

# check_eqs_u0 kwarg test
@variables x1(t) x2(t)
eqs = [D(x1) ~ -x1]
Expand Down Expand Up @@ -1530,64 +1478,6 @@ end
@test osys1 !== osys2
end

@testset "dae_order_lowering basic test" begin
@parameters a
@variables x(t) y(t) z(t)
@named dae_sys = System([
D(x) ~ y,
0 ~ x + z,
0 ~ x - y + z
], t, [z, y, x], [])

lowered_dae_sys = dae_order_lowering(dae_sys)
@variables x1(t) y1(t) z1(t)
expected_eqs = [
0 ~ x + z,
0 ~ x - y + z,
Differential(t)(x) ~ y
]
lowered_eqs = equations(lowered_dae_sys)
sorted_lowered_eqs = sort(lowered_eqs, by = string)
sorted_expected_eqs = sort(expected_eqs, by = string)
@test sorted_lowered_eqs == sorted_expected_eqs

expected_vars = Set([z, y, x])
lowered_vars = Set(unknowns(lowered_dae_sys))
@test lowered_vars == expected_vars
end

@testset "dae_order_lowering test with structural_simplify" begin
@variables x(t) y(t) z(t)
@parameters M b k
eqs = [
D(D(x)) ~ -b / M * D(x) - k / M * x,
0 ~ y - D(x),
0 ~ z - x
]
ps = [M, b, k]
default_u0 = [
D(x) => 0.0, x => 10.0, y => 0.0, z => 10.0
]
default_p = [M => 1.0, b => 1.0, k => 1.0]
@named dae_sys = System(eqs, t, [x, y, z], ps; defaults = [default_u0; default_p])

simplified_dae_sys = structural_simplify(dae_sys)

lowered_dae_sys = dae_order_lowering(simplified_dae_sys)
lowered_dae_sys = complete(lowered_dae_sys)

tspan = (0.0, 10.0)
prob = ODEProblem(lowered_dae_sys, nothing, tspan)
sol = solve(prob, Tsit5())

@test sol.t[end] == tspan[end]
@test sum(abs, sol.u[end]) < 1

prob = ODEProblem{false}(
lowered_dae_sys, nothing, tspan; u0_constructor = x -> SVector(x...))
@test prob.u0 isa SVector
end

@testset "Constraint system construction" begin
@variables x(..) y(..) z(..)
@parameters a b c d e
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ end
@safetestset "Symbolic Event Test" include("symbolic_events.jl")
@safetestset "Stream Connect Test" include("stream_connectors.jl")
@safetestset "Domain Connect Test" include("domain_connectors.jl")
@safetestset "Lowering Integration Test" include("lowering_solving.jl")
@safetestset "Dependency Graph Test" include("dep_graphs.jl")
@safetestset "Function Registration Test" include("function_registration.jl")
@safetestset "Precompiled Modules Test" include("precompile_test.jl")
Expand Down
1 change: 0 additions & 1 deletion test/state_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ end
@test_skip let pss = partial_state_selection(sys)
@test length(equations(pss)) == 1
@test length(unknowns(pss)) == 2
@test length(equations(ode_order_lowering(pss))) == 2
end

@parameters σ ρ β
Expand Down
Loading
Loading