Skip to content

Commit 55b2ebd

Browse files
committed
fix: fix pyomo problems on lts
1 parent 0214527 commit 55b2ebd

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

ext/MTKPyomoDynamicOptExt.jl

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using NaNMath
77
using Setfield
88
const MTK = ModelingToolkit
99

10-
SPECIAL_FUNCTIONS_DICT = Dict([acos => Pyomo.py_acos,
10+
const SPECIAL_FUNCTIONS_DICT = Dict([acos => Pyomo.py_acos,
1111
acosh => Pyomo.py_acosh,
1212
asin => Pyomo.py_asin,
1313
tan => Pyomo.py_tan,
@@ -33,22 +33,11 @@ struct PyomoDynamicOptModel
3333
function PyomoDynamicOptModel(model, U, V, tₛ, is_free_final)
3434
@variables MODEL_SYM::Symbolics.symstruct(ConcreteModel) T_SYM DUMMY_SYM
3535
model.dU = dae.DerivativeVar(U, wrt = model.t, initialize = 0)
36-
#add_time_equation!(model, MODEL_SYM, T_SYM)
3736
new(model, U, V, tₛ, is_free_final, nothing,
3837
PyomoVar(model.dU), MODEL_SYM, T_SYM, DUMMY_SYM)
3938
end
4039
end
4140

42-
function add_time_equation!(model::ConcreteModel, model_sym, t_sym)
43-
model.dtime = dae.DerivativeVar(model.time)
44-
45-
mdt = Symbolics.value(pysym_getproperty(model_sym, :dtime))
46-
mts = Symbolics.value(pysym_getproperty(model_sym, :tₛ))
47-
expr = mdt[t_sym] - mts == 0
48-
f = Pyomo.pyfunc(eval(Symbolics.build_function(expr, model_sym, t_sym)))
49-
model.time_eq = pyomo.Constraint(model.t, rule = f)
50-
end
51-
5241
struct PyomoDynamicOptProblem{uType, tType, isinplace, P, F, K} <:
5342
AbstractDynamicOptProblem{uType, tType, isinplace}
5443
f::F
@@ -119,7 +108,7 @@ function MTK.add_constraint!(pmodel::PyomoDynamicOptModel, cons; n_idxs = 1)
119108
else
120109
cons.lhs - cons.rhs 0
121110
end
122-
expr = Symbolics.substitute(Symbolics.unwrap(expr), SPECIAL_FUNCTIONS_DICT)
111+
expr = Symbolics.substitute(Symbolics.unwrap(expr), SPECIAL_FUNCTIONS_DICT, fold = false)
123112

124113
cons_sym = Symbol("cons", hash(cons))
125114
if occursin(Symbolics.unwrap(t_sym), expr)
@@ -133,7 +122,7 @@ end
133122

134123
function MTK.set_objective!(pmodel::PyomoDynamicOptModel, expr)
135124
@unpack model, model_sym, t_sym, dummy_sym = pmodel
136-
expr = Symbolics.substitute(expr, SPECIAL_FUNCTIONS_DICT)
125+
expr = Symbolics.substitute(expr, SPECIAL_FUNCTIONS_DICT, fold = false)
137126
if occursin(Symbolics.unwrap(t_sym), expr)
138127
f = eval(Symbolics.build_function(expr, model_sym, t_sym))
139128
model.obj = pyomo.Objective(model.t, rule = Pyomo.pyfunc(f))

0 commit comments

Comments
 (0)