Skip to content

Commit b38753c

Browse files
refactor: use SciMLStructures
1 parent d8637f4 commit b38753c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/OptimizationMOI/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
99
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1010
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
1111
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
12+
SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226"
1213
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1314
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
1415
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
@@ -17,9 +18,10 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1718
Ipopt_jll = "=300.1400.400"
1819
Juniper = "0.9"
1920
MathOptInterface = "1"
20-
ModelingToolkit = "9"
21+
ModelingToolkit = "8.76, 9"
2122
Optimization = "3.21"
2223
Reexport = "1.2"
24+
SciMLStructures = "1.0"
2325
SymbolicIndexingInterface = "0.3"
2426
Symbolics = "5"
2527
julia = "1"

lib/OptimizationMOI/src/OptimizationMOI.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Reexport
44
@reexport using Optimization
55
using MathOptInterface
66
using Optimization.SciMLBase
7+
using SciMLStructures
78
using SymbolicIndexingInterface
89
using SparseArrays
910
import ModelingToolkit: parameters, unknowns, varmap_to_vars, mergedefaults, toexpr
@@ -234,7 +235,8 @@ Replaces every expression `:p[i]` with its numeric value from `p`
234235
_replace_parameter_indices!(expr, p) = expr
235236
function _replace_parameter_indices!(expr::Expr, p)
236237
if expr.head == :ref && expr.args[1] == :p
237-
p_ = p[expr.args[2]]
238+
tunable, _, _ = SciMLStructures.canonicalize(SciMLStructures.Tunable(), p)
239+
p_ = tunable[expr.args[2]]
238240
(!isa(p_, Real) || isnan(p_) || isinf(p_)) &&
239241
throw(ArgumentError("Expected parameters to be real valued: $(expr.args[2]) => $p_"))
240242
return p_

0 commit comments

Comments
 (0)