Skip to content

Commit 38392d1

Browse files
Merge pull request #3031 from SciML/labelledarrays
Move labelledarrays to extension testing
2 parents 36bc96f + 7f4a488 commit 38392d1

File tree

5 files changed

+52
-60
lines changed

5 files changed

+52
-60
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
135135
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
136136
Ipopt_jll = "9cc047cb-c261-5740-88fc-0cf96f7bdcc7"
137137
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
138-
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
139138
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
140139
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
141140
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
@@ -155,4 +154,4 @@ Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
155154
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
156155

157156
[targets]
158-
test = ["AmplNLWriter", "BenchmarkTools", "ControlSystemsBase", "DelayDiffEq", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "OrdinaryDiffEq", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq", "Pkg", "JET", "LabelledArrays"]
157+
test = ["AmplNLWriter", "BenchmarkTools", "ControlSystemsBase", "DelayDiffEq", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "OrdinaryDiffEq", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq", "Pkg", "JET"]

test/extensions/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
33
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
4+
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
45
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
56
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
67
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"

test/labelledarrays.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,51 @@ d = LVector(x = 1.0, y = 2.0, z = 3.0)
4141
@test ff.jac(d, p, ForwardDiff.Dual(0.0, 1.0)) isa Array
4242
@inferred ff.jac(d, p, ForwardDiff.Dual(0.0, 1.0))
4343
@test eltype(ff.jac(d, p, ForwardDiff.Dual(0.0, 1.0))) <: ForwardDiff.Dual
44+
45+
## https://github.com/SciML/ModelingToolkit.jl/issues/1054
46+
using LabelledArrays
47+
using ModelingToolkit
48+
49+
# ODE model: simple SIR model with seasonally forced contact rate
50+
function SIR!(du, u, p, t)
51+
52+
# Unknowns
53+
(S, I, R) = u[1:3]
54+
N = S + I + R
55+
56+
# params
57+
β = p.β
58+
η = p.η
59+
φ = p.φ
60+
ω = 1.0 / p.ω
61+
μ = p.μ
62+
σ = p.σ
63+
64+
# FOI
65+
βeff = β * (1.0 + η * cos(2.0 * π * (t - φ) / 365.0))
66+
λ = βeff * I / N
67+
68+
# change in unknowns
69+
du[1] =* N - λ * S - μ * S + ω * R)
70+
du[2] =* S - σ * I - μ * I)
71+
du[3] =* I - μ * R - ω * R)
72+
du[4] =* I) # cumulative incidence
73+
end
74+
75+
# Solver settings
76+
tmin = 0.0
77+
tmax = 10.0 * 365.0
78+
tspan = (tmin, tmax)
79+
80+
# Initiate ODE problem
81+
theta_fix = [1.0 / (80 * 365)]
82+
theta_est = [0.28, 0.07, 1.0 / 365.0, 1.0, 1.0 / 5.0]
83+
p = @LArray [theta_est; theta_fix] (, , , , , )
84+
u0 = @LArray [9998.0, 1.0, 1.0, 1.0] (:S, :I, :R, :C)
85+
86+
# Initiate ODE problem
87+
problem = ODEProblem(SIR!, u0, tspan, p)
88+
sys = complete(modelingtoolkitize(problem))
89+
90+
@test all(isequal.(parameters(sys), getproperty.(@variables(β, η, ω, φ, σ, μ), :val)))
91+
@test all(isequal.(Symbol.(unknowns(sys)), Symbol.(@variables(S(t), I(t), R(t), C(t)))))

test/modelingtoolkitize.jl

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using OrdinaryDiffEq, ModelingToolkit, DataStructures, Test
22
using Optimization, RecursiveArrayTools, OptimizationOptimJL
3-
using LabelledArrays, SymbolicIndexingInterface
3+
using SymbolicIndexingInterface
44
using ModelingToolkit: t_nounits as t, D_nounits as D
55
using SciMLBase: parameterless_type
66

@@ -210,54 +210,6 @@ tspan = (0.0, 1.0)
210210
prob = ODEProblem(k, x0, tspan)
211211
sys = modelingtoolkitize(prob)
212212

213-
## https://github.com/SciML/ModelingToolkit.jl/issues/1054
214-
using LabelledArrays
215-
using ModelingToolkit
216-
217-
# ODE model: simple SIR model with seasonally forced contact rate
218-
function SIR!(du, u, p, t)
219-
220-
# Unknowns
221-
(S, I, R) = u[1:3]
222-
N = S + I + R
223-
224-
# params
225-
β = p.β
226-
η = p.η
227-
φ = p.φ
228-
ω = 1.0 / p.ω
229-
μ = p.μ
230-
σ = p.σ
231-
232-
# FOI
233-
βeff = β * (1.0 + η * cos(2.0 * π * (t - φ) / 365.0))
234-
λ = βeff * I / N
235-
236-
# change in unknowns
237-
du[1] =* N - λ * S - μ * S + ω * R)
238-
du[2] =* S - σ * I - μ * I)
239-
du[3] =* I - μ * R - ω * R)
240-
du[4] =* I) # cumulative incidence
241-
end
242-
243-
# Solver settings
244-
tmin = 0.0
245-
tmax = 10.0 * 365.0
246-
tspan = (tmin, tmax)
247-
248-
# Initiate ODE problem
249-
theta_fix = [1.0 / (80 * 365)]
250-
theta_est = [0.28, 0.07, 1.0 / 365.0, 1.0, 1.0 / 5.0]
251-
p = @LArray [theta_est; theta_fix] (, , , , , )
252-
u0 = @LArray [9998.0, 1.0, 1.0, 1.0] (:S, :I, :R, :C)
253-
254-
# Initiate ODE problem
255-
problem = ODEProblem(SIR!, u0, tspan, p)
256-
sys = complete(modelingtoolkitize(problem))
257-
258-
@test all(isequal.(parameters(sys), getproperty.(@variables(β, η, ω, φ, σ, μ), :val)))
259-
@test all(isequal.(Symbol.(unknowns(sys)), Symbol.(@variables(S(t), I(t), R(t), C(t)))))
260-
261213
# https://github.com/SciML/ModelingToolkit.jl/issues/1158
262214

263215
function ode_prob(du, u, p::NamedTuple, t)
@@ -361,10 +313,6 @@ sys = modelingtoolkitize(prob)
361313
(1.0, [:p]),
362314
(1.0, Dict(1 => :p)),
363315
(Dict(:a => 2, :b => 4), Dict(:a => :p, :b => :q)),
364-
(LVector(a = 1, b = 2), [:p, :q]),
365-
(SLVector(a = 1, b = 2), [:p, :q]),
366-
(LVector(a = 1, b = 2), Dict(1 => :p, 2 => :q)),
367-
(SLVector(a = 1, b = 2), Dict(1 => :p, 2 => :q)),
368316
((a = 1, b = 2), (a = :p, b = :q)),
369317
((a = 1, b = 2), Dict(:a => :p, :b => :q))
370318
]
@@ -390,10 +338,6 @@ sys = modelingtoolkitize(prob)
390338
(1.0, [:p, :q]),
391339
(1.0, Dict(1 => :p, 2 => :q)),
392340
(Dict(:a => 2, :b => 4), Dict(:a => :p, :b => :q, :c => :r)),
393-
(LVector(a = 1, b = 2), [:p, :q, :r]),
394-
(SLVector(a = 1, b = 2), [:p, :q, :r]),
395-
(LVector(a = 1, b = 2), Dict(1 => :p, 2 => :q, 3 => :r)),
396-
(SLVector(a = 1, b = 2), Dict(1 => :p, 2 => :q, 3 => :r)),
397341
((a = 1, b = 2), (a = :p, b = :q, c = :r)),
398342
((a = 1, b = 2), Dict(:a => :p, :b => :q, :c => :r))
399343
]

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ end
3131
@safetestset "ODESystem Test" include("odesystem.jl")
3232
@safetestset "Dynamic Quantities Test" include("dq_units.jl")
3333
@safetestset "Unitful Quantities Test" include("units.jl")
34-
@safetestset "LabelledArrays Test" include("labelledarrays.jl")
3534
@safetestset "Mass Matrix Test" include("mass_matrix.jl")
3635
@safetestset "InitializationSystem Test" include("initializationsystem.jl")
3736
@safetestset "Guess Propagation" include("guess_propagation.jl")
@@ -110,5 +109,6 @@ end
110109
activate_extensions_env()
111110
@safetestset "BifurcationKit Extension Test" include("extensions/bifurcationkit.jl")
112111
@safetestset "Auto Differentiation Test" include("extensions/ad.jl")
112+
@safetestset "LabelledArrays Test" include("labelledarrays.jl")
113113
end
114114
end

0 commit comments

Comments
 (0)