I am in the process of validating a couple of models that I have written in pyoptsparse and scipy. I want to be able to test the same code in Gekko to see if the results are consistent with the more symbolic Gekko version that I originally made. To do this I have tried to use Odeint and integrating with my own code instead of using the built in Gekko capabilities. Is it possible to do it this way? is the issue with the optimizers ability to take the gradient of the Odeint?
import numpy as np
from scipy.integrate import odeint
from gekko import GEKKO
nhrs = 24
time = np.arange(nhrs)
m = GEKKO(remote=True)
gen = m.Array(m.Param, nhrs)
for geni in gen:
geni.value = 1
tes_store = m.Array(m.Var, nhrs)
for tesi in tes_store:
tesi.value = 0
tesi.lower = -1
tesi.upper = 1
T = m.Array(m.SV, nhrs)
for testi in T:
testi.upper = 24
testi.lower = 0
def tes_T_dt(t, T, gen, tes_store):
return gen*tes_store
def tes_T(gen, tes_store, t):
T_hist = [0]
T_new = 0
for i in range(len(t)):
step = odeint(tes_T_dt, T_new, [0, 1], args=(gen[i].value, tes_store[i].value))
T_new = step[1][0]
T_hist.append(T_new)
return T_hist
Temp = tes_T(gen, tes_store, time)[1:]
equations = []
m.Equation(T == tes_T(gen, tes_store, time)[1:])
m.Obj(-T[23])
Temp = tes_T(gen, tes_store, time)[1:]
m.options.SOLVER = 3
m.solve()
for i in range(len(T)):
print(f'{i} gen={gen[i].value}, tes_store={tes_store[i].value}, T={T[i].value}, Temp={Temp[i]}')
I am getting the following error
@error: Equation Definition
Equation without an equality (=) or inequality (>,<)
false
STOPPING...
Traceback (most recent call last):
File "gekkopyoptsimpleTEST.py", line 54, in <module>
m.solve()
File "/home/prism/miniconda3/lib/python3.7/site-packages/gekko/gekko.py", line 2103, in solve
raise Exception(response)
Exception: @error: Equation Definition
Equation without an equality (=) or inequality (>,<)
false
STOPPING...
