Skip to content

Commit 1c8978f

Browse files
refactor: update for MTKv9
1 parent 4da7756 commit 1c8978f

File tree

4 files changed

+6
-43
lines changed

4 files changed

+6
-43
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ForwardDiff = "0.10.26"
5151
LinearAlgebra = "1.10"
5252
Logging = "1.10"
5353
LoggingExtras = "0.4, 1"
54-
ModelingToolkit = "8.74"
54+
ModelingToolkit = "8.74, 9"
5555
Pkg = "1"
5656
Printf = "1.10"
5757
ProgressLogging = "0.1"

lib/OptimizationMOI/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1717
Ipopt_jll = "=300.1400.400"
1818
Juniper = "0.9"
1919
MathOptInterface = "1"
20-
ModelingToolkit = "8.74"
20+
ModelingToolkit = "9"
2121
Optimization = "3.21"
2222
Reexport = "1.2"
2323
SymbolicIndexingInterface = "0.3"

lib/OptimizationMOI/src/OptimizationMOI.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using MathOptInterface
66
using Optimization.SciMLBase
77
using SymbolicIndexingInterface
88
using SparseArrays
9-
import ModelingToolkit: parameters, states, varmap_to_vars, mergedefaults, toexpr
9+
import ModelingToolkit: parameters, unknowns, varmap_to_vars, mergedefaults, toexpr
1010
import ModelingToolkit
1111
const MTK = ModelingToolkit
1212
using Symbolics
@@ -182,12 +182,12 @@ end
182182
"""
183183
convert_to_expr(eq, sys; expand_expr = false, pairs_arr = expr_map(sys))
184184
185-
Converts the given symbolic expression to a Julia `Expr` and replaces all symbols, i.e. states and
185+
Converts the given symbolic expression to a Julia `Expr` and replaces all symbols, i.e. unknowns and
186186
parameters with `x[i]` and `p[i]`.
187187
188188
# Arguments:
189189
- `eq`: Expression to convert
190-
- `sys`: Reference to the system holding the parameters and states
190+
- `sys`: Reference to the system holding the parameters and unknowns
191191
- `expand_expr=false`: If `true` the symbolic expression is expanded first.
192192
"""
193193
function convert_to_expr(eq, expr_map; expand_expr = false)
@@ -206,7 +206,7 @@ function convert_to_expr(eq, expr_map; expand_expr = false)
206206
end
207207

208208
function get_expr_map(sys)
209-
dvs = ModelingToolkit.states(sys)
209+
dvs = ModelingToolkit.unknowns(sys)
210210
ps = ModelingToolkit.parameters(sys)
211211
return vcat([ModelingToolkit.toexpr(_s) => Expr(:ref, :x, i)
212212
for (i, _s) in enumerate(dvs)],

src/cache.jl

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
2-
function Base.getproperty(cache::SciMLBase.AbstractOptimizationCache, x::Symbol)
3-
if x in (:u0, :p)
4-
return getfield(cache.reinit_cache, x)
5-
end
6-
return getfield(cache, x)
7-
end
8-
9-
SciMLBase.has_reinit(cache::SciMLBase.AbstractOptimizationCache) = true
10-
function SciMLBase.reinit!(cache::SciMLBase.AbstractOptimizationCache; p = missing,
11-
u0 = missing)
12-
if p === missing && u0 === missing
13-
p, u0 = cache.p, cache.u0
14-
else # at least one of them has a value
15-
if p === missing
16-
p = cache.p
17-
end
18-
if u0 === missing
19-
u0 = cache.u0
20-
end
21-
if (eltype(p) <: Pair && !isempty(p)) || (eltype(u0) <: Pair && !isempty(u0)) # one is a non-empty symbolic map
22-
hasproperty(cache.f, :sys) && hasfield(typeof(cache.f.sys), :ps) ||
23-
throw(ArgumentError("This cache does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
24-
" Please use `remake` with the `p` keyword argument as a vector of values, paying attention to parameter order."))
25-
hasproperty(cache.f, :sys) && hasfield(typeof(cache.f.sys), :states) ||
26-
throw(ArgumentError("This cache does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
27-
" Please use `remake` with the `u0` keyword argument as a vector of values, paying attention to state order."))
28-
p, u0 = SciMLBase.process_p_u0_symbolic(cache, p, u0)
29-
end
30-
end
31-
32-
cache.reinit_cache.p = p
33-
cache.reinit_cache.u0 = u0
34-
35-
return cache
36-
end
37-
381
struct OptimizationCache{F, RC, LB, UB, LC, UC, S, O, D, P, C} <:
392
SciMLBase.AbstractOptimizationCache
403
f::F

0 commit comments

Comments
 (0)