Skip to content

Commit

Permalink
Merge pull request #2689 from SciML/fb/parse_order
Browse files Browse the repository at this point in the history
preserve argument order for structural parameters
  • Loading branch information
baggepinnen authored May 2, 2024
2 parents 90a6ff4 + 2e23c80 commit 1aec75d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Expand Down Expand Up @@ -89,6 +90,7 @@ Libdl = "1"
LinearAlgebra = "1"
MLStyle = "0.4.17"
NaNMath = "0.3, 1"
OrderedCollections = "1"
OrdinaryDiffEq = "6.73.0"
PrecompileTools = "1"
RecursiveArrayTools = "2.3, 3"
Expand Down
1 change: 1 addition & 0 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using PrecompileTools, Reexport
import FunctionWrappersWrappers
using URIs: URI
using SciMLStructures
import OrderedCollections

using RecursiveArrayTools

Expand Down
2 changes: 1 addition & 1 deletion src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function _model_macro(mod, name, expr, isconnector)
ps, sps, vs, = [], [], []
c_evts = []
d_evts = []
kwargs = Set()
kwargs = OrderedCollections.OrderedSet()
where_types = Expr[]

push!(exprs.args, :(variables = []))
Expand Down
24 changes: 24 additions & 0 deletions test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,27 @@ end
@test typeof(l_guess) == Num
@test readable_code(l_guess) == "k(t)"
end

@testset "Argument order" begin
@mtkmodel OrderModel begin
@structural_parameters begin
b = 1 # reverse alphabetical order to test that the order is preserved
a = b
end
@parameters begin
c = a
d = b
end
end
@named ordermodel = OrderModel()
ordermodel = complete(ordermodel)
defs = ModelingToolkit.defaults(ordermodel)
@test defs[ordermodel.c] == 1
@test defs[ordermodel.d] == 1

@test_nowarn @named ordermodel = OrderModel(a = 2)
ordermodel = complete(ordermodel)
defs = ModelingToolkit.defaults(ordermodel)
@test defs[ordermodel.c] == 2
@test defs[ordermodel.d] == 1
end

0 comments on commit 1aec75d

Please sign in to comment.