I am using a function to create a dictionary containing gekko variables. Please can someone tell me what is causing the syntax error?
Here is the code I am running:
from gekko import GEKKO
m = GEKKO(remote = False)
def tank(tank_id, area, gm): #gm = gekko model
tank_dict = {}
tank_dict['id'] = tank_id
tank_dict['area'] = gm.Param(value = area, name = tank_id + '_area')
tank_dict['volume'] = gm.FV(value = 10, name = tank_id + '_volume')
tank_dict['height'] = gm.Var(name = tank_id + '_height')
gm.Equation(tank_dict['height'] == tank_dict['volume']/tank_dict['area'])
return(tank_dict)
tank_1 = tank('tank_1', area = 5, gm = m)
m.solve(disp = True)
This is the error message I get:
----------------------------------------------------------------
APMonitor, Version 1.0.0
APMonitor Optimization Suite
----------------------------------------------------------------
--------- APM Model Size ------------
Each time step contains
Objects : 0
Constants : 0
Variables : 3
Intermediates: 0
Connections : 0
Equations : 1
Residuals : 1
@error: Model Expression
*** Error in syntax of function string: Missing opening parenthesis
Position: 4
tank_1_height-(((tank_1_volume)/(tank_1_area)))
?
I'm expecting the 'height' key in the tank_1 dictionary to contain a value of 2.
There are reserved keywords for naming variables in
gekkobecause of how the underlyingAPMonitormodel is written and compiled to byte-code. Those keywords include thetan()function that is used in the nametankin the variable definition. Naming the variables is optional, but does help if you need to read thegk0_model.apmfile in the run directorym._path. Prepending something likex_to the variable names overcomes this error.Here is the full script.
Alternatively, just let
gekkohandle the internal variable naming:Here is a list of other reserved keywords in
gekkofor naming variables:This list is also found in the APMonitor Documentation.