Gekko: Fixed Parameter and fixed Variable value changes after solving

Viewed 193

I am developing a mathematical process model based on the gekko package (version 1.0.2) to solve the balance equations (partial differential equations), and I observed a strange behavior when defining fixed parameter values for a dynamic simulation.

At a specific number of defined parameters or variables, the fixed values change after solving. Therefore, I assume that there must be something like a memory limit. Furthermore, the maximum achievable number of correct fixed values depends if a name of the parameter or variable is set or, in the case of variables, if a lower or upper bound is defined.

In general: the number of correct values decreases with the number of information (name, value, lb, ub) given.

Please look at this minimal working example to reproduce the strange behavior:

from gekko import GEKKO
import numpy as np
        

m = GEKKO(remote = False)
time = np.linspace(0,2,2+1)
m.time = time
a_value = [2.0, 3.0, 4.0]


num = 685 # limit with m.Param()
a = [m.Param(value=a_value, name="a_"+str(i)) for i in range(num)]

b = [m.Var(value=0, lb=0, name="b_"+str(i)) for i in range(num)]

for i in range(num):
    m.Equation(b[i].dt() == a[i])

m.options.IMODE = 7
m.options.SOLVER = 1
# m.open_folder()
m.solve(disp = False) 
m.cleanup()
        
for i in range(num):
    for t in range(len(m.time)):
        if(a[i].value[t] != a_value[t]):
            print("i=" + str(i) + ", t=" + str(t) + ": wrong value -> a.value[" + str(t) + "]: " + str(a[i].value[t]) + ", a_value[" + str(t) + "]: " + str(a_value[t]))

This code leads to the following output:

i=684, t=0: wrong value -> a.value[0]: 1.0, a_value[0]: 2.0
i=684, t=1: wrong value -> a.value[1]: 1.0, a_value[1]: 3.0
i=684, t=2: wrong value -> a.value[2]: 1.0, a_value[2]: 4.0

If m.Var() is used instead of m.Param(), the maximum number of correct values increases, but there is still a limit:

from gekko import GEKKO
import numpy as np
        

m = GEKKO(remote = False)
time = np.linspace(0,2,2+1)
m.time = time
a_value = [2.0, 3.0, 4.0]

num = 1301 # limit with m.Var()
a = [m.Var(value=0, name="a_"+str(i)) for i in range(num)]
for i in range(num):
    for j in range(len(m.time)):
        m.fix(a[i], val=a_value[j], pos=j)

b = [m.Var(value=0, lb=0, name="b_"+str(i)) for i in range(num)]

for i in range(num):
    m.Equation(b[i].dt() == a[i])

m.options.IMODE = 7
m.options.SOLVER = 1
# m.open_folder()
m.solve(disp = False) 
m.cleanup()
        
for i in range(num):
    for t in range(len(m.time)):
        if(a[i].value[t] != a_value[t]):
            print("i=" + str(i) + ", t=" + str(t) + ": wrong value -> a.value[" + str(t) + "]: " + str(a[i].value[t]) + ", a_value[" + str(t) + "]: " + str(a_value[t]))

Output:

i=1300, t=0: wrong value -> a.value[0]: 3.0, a_value[0]: 2.0
i=1300, t=2: wrong value -> a.value[2]: 3.0, a_value[2]: 4.0

Hence, my question is: Can this maximum limit be increased by the user or is there a workaround? (as I can not decrease the size of my problem)

0 Answers
Related