Skip to content

Commit 61b9120

Browse files
refactor: use SciMLStructures
1 parent 05f7e49 commit 61b9120

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/OptimizationMOI/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
88
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
99
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
1010
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
11+
SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226"
1112
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1213
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
1314
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

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
@@ -237,7 +238,8 @@ Replaces every expression `:p[i]` with its numeric value from `p`
237238
_replace_parameter_indices!(expr, p) = expr
238239
function _replace_parameter_indices!(expr::Expr, p)
239240
if expr.head == :ref && expr.args[1] == :p
240-
p_ = p[expr.args[2]]
241+
tunable, _, _ = SciMLStructures.canonicalize(SciMLStructures.Tunable(), p)
242+
p_ = tunable[expr.args[2]]
241243
(!isa(p_, Real) || isnan(p_) || isinf(p_)) &&
242244
throw(ArgumentError("Expected parameters to be real valued: $(expr.args[2]) => $p_"))
243245
return p_

0 commit comments

Comments
 (0)