Skip to content

Commit

Permalink
Merge pull request #232 from SciML/submodel_ordering
Browse files Browse the repository at this point in the history
keeping the variable ordering when computing submodels
  • Loading branch information
pogudingleb authored Nov 6, 2023
2 parents d1c2260 + c5491bf commit da358b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
11 changes: 10 additions & 1 deletion src/submodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ function ode_aux(ode::ODE{P}, submodel::Set{fmpq_mpoly}) where {P <: MPolyElem}
dict_type(parent_ring_change(y, S) => parent_ring_change(f, S) for (y, f) in new_y)
fin_u = [parent_ring_change(u, S) for u in new_u]

return ODE{fmpq_mpoly}(fin_x, fin_y, fin_u)
new_x_vars = [
parent_ring_change(x, S) for
x in ode.x_vars if var_to_str(x) in map(var_to_str, collect(keys(fin_x)))
]
new_y_vars = [
parent_ring_change(y, S) for
y in ode.y_vars if var_to_str(y) in map(var_to_str, collect(keys(fin_y)))
]

return ODE{fmpq_mpoly}(new_x_vars, new_y_vars, fin_x, fin_y, fin_u)
end

# ------------------------------------------------------------------------------
Expand Down
44 changes: 22 additions & 22 deletions test/submodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
y1(t) = x1(t),
y2(t) = x2(t)
),
:submodels => Set([(Set(["x1"]), Set(["y1"]), Set{String}())]),
:submodels => Set([(["x1"], ["y1"], Vector{String}())]),
),
Dict(
:ode => @ODEmodel(
Expand All @@ -17,7 +17,7 @@
y2(t) = x1(t)^2,
y3(t) = x2(t)
),
:submodels => Set([(Set(["x1"]), Set(["y1", "y2"]), Set{String}())]),
:submodels => Set([(["x1"], ["y1", "y2"], Vector{String}())]),
),
Dict(
:ode => @ODEmodel(
Expand All @@ -29,9 +29,9 @@
y3(t) = x1(t) + x3(t)
),
:submodels => Set([
(Set(["x1", "x2"]), Set(["y1"]), Set{String}()),
(Set(["x2", "x3"]), Set(["y2"]), Set{String}()),
(Set(["x1", "x3"]), Set(["y3"]), Set{String}()),
(["x1", "x2"], ["y1"], Vector{String}()),
(["x2", "x3"], ["y2"], Vector{String}()),
(["x1", "x3"], ["y3"], Vector{String}()),
]),
),
Dict(
Expand All @@ -41,7 +41,7 @@
y1(t) = x1(t),
y2(t) = x2(t)
),
:submodels => Set([(Set(["x1"]), Set(["y1"]), Set{String}())]),
:submodels => Set([(["x1"], ["y1"], Vector{String}())]),
),
Dict(
:ode => @ODEmodel(
Expand All @@ -51,7 +51,7 @@
y1(t) = d(t) * x1(t),
y2(t) = x3(t)
),
:submodels => Set([(Set(["x1", "x2"]), Set(["y1"]), Set(["a", "b", "d"]))]),
:submodels => Set([(["x1", "x2"], ["y1"], ["a", "b", "d"])]),
),
Dict(
:ode => @ODEmodel(
Expand All @@ -63,8 +63,8 @@
y3(t) = x3(t)
),
:submodels => Set([
(Set(["x1", "x2"]), Set(["y1", "y2"]), Set(["a", "d"])),
(Set(["x1"]), Set(["y1"]), Set{String}()),
(["x1", "x2"], ["y1", "y2"], ["a", "d"]),
(["x1"], ["y1"], Vector{String}()),
]),
),
Dict(
Expand Down Expand Up @@ -94,27 +94,27 @@
),
:submodels => Set([
(
Set(["x0", "x1", "x2", "x3", "x02", "x12", "x22", "x32", "o1", "o12"]),
Set(["y0", "y1", "y2", "y3"]),
Set(),
["o1", "x0", "x1", "x2", "x3", "o12", "x02", "x12", "x22", "x32"],
["y0", "y1", "y2", "y3"],
Vector{String}(),
),
(
Set([
[
"o1",
"x0",
"x1",
"x2",
"x3",
"x4",
"x42",
"o12",
"x02",
"x12",
"x22",
"x32",
"o1",
"o12",
]),
Set(["y0", "y1", "y2", "y3", "y5"]),
Set(),
"x42",
],
["y0", "y1", "y2", "y3", "y5"],
Vector{String}(),
),
]),
),
Expand All @@ -124,9 +124,9 @@
submodels = find_submodels(c[:ode])
submodels = Set([
(
Set(map(var_to_str, ode.x_vars)),
Set(map(var_to_str, ode.y_vars)),
Set(map(var_to_str, ode.u_vars)),
collect(map(var_to_str, ode.x_vars)),
collect(map(var_to_str, ode.y_vars)),
collect(map(var_to_str, ode.u_vars)),
) for ode in submodels
])
@test submodels == c[:submodels]
Expand Down

0 comments on commit da358b4

Please sign in to comment.