Skip to content

Commit 32c419a

Browse files
authored
Merge pull request #400 from SciML/vectorMTK
Scalarizing MTK parameters
2 parents 9c2aefe + 02d63ea commit 32c419a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

ext/ModelingToolkitSIExt.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ function clean_calls(funcs)
172172
return res
173173
end
174174

175+
#------------------------------------------------------------------------------
176+
177+
function scalarize(arr)
178+
result = []
179+
for a in arr
180+
if typeof(a) <: SymbolicUtils.BasicSymbolic{<:Vector}
181+
append!(result, collect(a))
182+
else
183+
push!(result, a)
184+
end
185+
end
186+
return result
187+
end
188+
175189
#------------------------------------------------------------------------------
176190
"""
177191
function __mtk_to_si(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{Tuple{String, SymbolicUtils.BasicSymbolic}})
@@ -209,7 +223,7 @@ function __mtk_to_si(
209223
filter(s -> !ModelingToolkit.isoutput(s), clean_calls(map(e -> e.lhs, diff_eqs)))
210224
all_funcs = collect(Set(clean_calls(ModelingToolkit.unknowns(de))))
211225
inputs = filter(s -> !ModelingToolkit.isoutput(s), setdiff(all_funcs, state_vars))
212-
params = ModelingToolkit.parameters(de)
226+
params = scalarize(ModelingToolkit.parameters(de))
213227
t = ModelingToolkit.arguments(clean_calls([diff_eqs[1].lhs])[1])[1]
214228
# very long if in order to avoid duplication
215229
params_from_measured_quantities = union(

test/extensions/modelingtoolkit.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,25 @@ if GROUP == "All" || GROUP == "ModelingToolkitSIExt"
427427
@test assess_local_identifiability(sys, measured_quantities = [x[1], x[2]]) ==
428428
correct
429429

430+
# Extension of https://github.com/SciML/StructuralIdentifiability.jl/issues/398
431+
@parameters k[1:2] a
432+
@variables (X(t))[1:2] (y(t))[1:2] [output = true]
433+
eqs = [
434+
D(X[1]) ~ k[1] - k[2] * X[2],
435+
D(X[2]) ~ k[1] - k[2] * X[1],
436+
y[1] ~ X[1] * X[2] + a,
437+
y[2] ~ X[1] - X[2],
438+
]
439+
@mtkbuild osys = ODESystem(eqs, t)
440+
correct = OrderedDict(
441+
X[1] => :locally,
442+
X[2] => :locally,
443+
k[1] => :locally,
444+
k[2] => :globally,
445+
a => :globally,
446+
)
447+
@test assess_identifiability(osys) == correct
448+
430449
#------------------------------------
431450
# system from the SciML tutorial
432451
# https://docs.sciml.ai/ModelingToolkit/stable/tutorials/parameter_identifiability/

0 commit comments

Comments
 (0)