Search code examples
pythonnonlinear-optimizationgekko

"TypeError: 'module' object is not callable" when initializing Gekko module in function


I'm trying to write a function that, given a set of parameters, uses Gekko to solve an optimal control problem. For whatever reason, whenever I run this function, it gives this error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-92ece108f7ea> in <module>
      1 import gekko as GEKKO
----> 2 solve_system()

<ipython-input-6-9d154ef663e4> in solve_system(theta, alpha, rho, chi, L_bar, n, w, delta_inc, xi, phi, tau, kappa, GAMMA, T, SIGMA, BETA, s_init, i_init, r_init)
     26 
     27     ##### initialize model #####
---> 28     m = GEKKO()
     29 
     30     ##### parameters #####

TypeError: 'module' object is not callable

I was looking into it and it seems to generally be an issue with the way you import the package/module, but I did this similarly (but not in a function) previously and had no issues. I have no idea where to start solving it: any pointers?


Solution

  • From the docs I think the import is supposed to be:

    from gekko import GEKKO