Skip to content

Commit c07372d

Browse files
fix: use new varmap_to_vars
1 parent 71361dd commit c07372d

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

ext/MTKBifurcationKitExt.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ function BifurcationKit.BifurcationProblem(nsys::System,
113113
J = jac ? ofun.jac : nothing
114114

115115
# Converts the input state guess.
116-
u0_bif_vals = ModelingToolkit.varmap_to_vars(u0_bif,
117-
unknowns(nsys);
118-
defaults = ModelingToolkit.get_defaults(nsys))
119-
p_vals = ModelingToolkit.varmap_to_vars(
120-
ps, parameters(nsys); defaults = ModelingToolkit.get_defaults(nsys))
116+
u0_bif = ModelingToolkit.to_varmap(u0_bif, unknowns(nsys))
117+
u0_buf = merge(ModelingToolkit.get_defaults(nsys), u0_bif)
118+
u0_bif_vals = ModelingToolkit.varmap_to_vars(u0_bif, unknowns(nsys))
119+
ps = ModelingToolkit.to_varmap(ps, parameters(nsys))
120+
ps = merge(ModelingToolkit.get_defaults(nsys), ps)
121+
p_vals = ModelingToolkit.varmap_to_vars(ps, parameters(nsys))
121122

122123
# Computes bifurcation parameter and the plotting function.
123124
bif_idx = findfirst(isequal(bif_par), parameters(nsys))

src/systems/problem_utils.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,11 +1215,11 @@ Keyword arguments:
12151215
- `fully_determined`: Override whether the initialization system is fully determined.
12161216
- `check_initialization_units`: Enable or disable unit checks when constructing the
12171217
initialization problem.
1218-
- `tofloat`: Passed to [`better_varmap_to_vars`](@ref) when building the parameter vector of
1218+
- `tofloat`: Passed to [`varmap_to_vars`](@ref) when building the parameter vector of
12191219
a non-split system.
12201220
- `u0_eltype`: The `eltype` of the `u0` vector. If `nothing`, finds the promoted floating point
12211221
type from `op`.
1222-
- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
1222+
- `u0_constructor`: A function to apply to the `u0` value returned from `varmap_to_vars`
12231223
to construct the final `u0` value.
12241224
- `p_constructor`: A function to apply to each array buffer created when constructing the parameter object.
12251225
- `check_length`: Whether to check the number of equations along with number of unknowns and
@@ -1340,11 +1340,10 @@ function process_SciMLProblem(
13401340
@warn "Cycles in unknowns:\n$msg"
13411341
end
13421342
end
1343-
evaluate_varmap!(op, dvs; limit = substitution_limit)
13441343

1345-
u0 = better_varmap_to_vars(
1346-
op, dvs; buffer_eltype = u0_eltype,
1347-
container_type = u0Type, allow_symbolic = symbolic_u0, is_initializeprob)
1344+
u0 = varmap_to_vars(
1345+
op, dvs; buffer_eltype = u0_eltype, container_type = u0Type,
1346+
allow_symbolic = symbolic_u0, is_initializeprob, substitution_limit)
13481347

13491348
if u0 !== nothing
13501349
u0 = u0_constructor(u0)
@@ -1365,15 +1364,15 @@ function process_SciMLProblem(
13651364
@warn "Cycles in parameters:\n$msg"
13661365
end
13671366
end
1368-
evaluate_varmap!(op, ps; limit = substitution_limit)
1367+
13691368
if is_split(sys)
13701369
# `pType` is usually `Dict` when the user passes key-value pairs.
13711370
if !(pType <: AbstractArray)
13721371
pType = Array
13731372
end
13741373
p = MTKParameters(sys, op; floatT = floatT, p_constructor)
13751374
else
1376-
p = p_constructor(better_varmap_to_vars(op, ps; tofloat, container_type = pType))
1375+
p = p_constructor(varmap_to_vars(op, ps; tofloat, container_type = pType))
13771376
end
13781377

13791378
if implicit_dae

test/discrete_system.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ syss = mtkcompile(sys)
3636
df = DiscreteFunction(syss)
3737
# iip
3838
du = zeros(3)
39-
u = ModelingToolkit.better_varmap_to_vars(
39+
u = ModelingToolkit.varmap_to_vars(
4040
Dict([S(k - 1) => 1, I(k - 1) => 2, R(k - 1) => 3]), unknowns(syss))
4141
p = MTKParameters(syss, [c, nsteps, δt, β, γ] .=> collect(1:5))
4242
df.f(du, u, p, 0)

test/extensions/test_infiniteopt.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ permutation = [findfirst(isequal(x), expected_state_order) for x in dvs] # This
3535

3636
##
3737

38-
ub = varmap_to_vars([model.θ => 2pi, model.ω => 10], dvs)
39-
lb = varmap_to_vars([model.θ => -2pi, model.ω => -10], dvs)
40-
xf = varmap_to_vars([model.θ => pi, model.ω => 0], dvs)
38+
ub = varmap_to_vars(Dict{Any, Any}([model.θ => 2pi, model.ω => 10]), dvs)
39+
lb = varmap_to_vars(Dict{Any, Any}([model.θ => -2pi, model.ω => -10]), dvs)
40+
xf = varmap_to_vars(Dict{Any, Any}([model.θ => pi, model.ω => 0]), dvs)
4141
nx = length(dvs)
4242
nu = length(inputs)
4343
ny = length(outputs)
@@ -71,8 +71,8 @@ cp = f_obs(x, u, p, τ) # Test that it's possible to trace through an observed f
7171
@constraint(m, [i = 1:nx], x[i](0)==x0[i]) # Initial condition
7272
@constraint(m, [i = 1:nx], x[i](1)==xf[i]) # Terminal state
7373

74-
x_scale = varmap_to_vars([model.θ => 1
75-
model.ω => 1], dvs)
74+
x_scale = varmap_to_vars(Dict{Any, Any}([model.θ => 1
75+
model.ω => 1]), dvs)
7676

7777
# Add dynamics constraints
7878
@constraint(m, [i = 1:nx], ((x[i], τ) - tf * xp[i]) / x_scale[i]==0)

test/odesystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ end
649649
# 1561
650650
let
651651
vars = @variables x y
652-
arr = ModelingToolkit.varmap_to_vars([x => 0.0, y => [0.0, 1.0]], vars) #error
652+
arr = ModelingToolkit.varmap_to_vars(
653+
Dict([x => 0.0, y => [0.0, 1.0]]), vars; use_union = true) #error
653654
sol = Union{Float64, Vector{Float64}}[0.0, [0.0, 1.0]]
654655
@test arr == sol
655656
@test typeof(arr) == typeof(sol)

test/symbolic_parameters.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ u0 = [
2222
]
2323
ns = System(eqs, [x, y, z], [σ, ρ, β], name = :ns, defaults = [par; u0])
2424
ModelingToolkit.get_defaults(ns)[y] = u * 1.1
25-
resolved = ModelingToolkit.varmap_to_vars(Dict(), parameters(ns),
26-
defaults = ModelingToolkit.defaults(ns))
25+
resolved = ModelingToolkit.varmap_to_vars(defaults(ns), parameters(ns))
2726
@test resolved == [1, 0.1 + 1, (0.1 + 1) * 1.1]
2827

2928
prob = NonlinearProblem(complete(ns), [u => 1.0])
@@ -36,8 +35,7 @@ top = System([0 ~ -a + ns.x + b], [a], [b], systems = [ns], name = :top)
3635
ModelingToolkit.get_defaults(top)[b] = ns.σ * 0.5
3736
ModelingToolkit.get_defaults(top)[ns.x] = unknowns(ns, u) * 0.5
3837

39-
res = ModelingToolkit.varmap_to_vars(Dict(), parameters(top),
40-
defaults = ModelingToolkit.defaults(top))
38+
res = ModelingToolkit.varmap_to_vars(defaults(top), parameters(top))
4139
@test res == [0.5, 1, 0.1 + 1, (0.1 + 1) * 1.1]
4240

4341
top = complete(top)

0 commit comments

Comments
 (0)