Closed CaptainFerMag closed 4 years ago
Thanks for letting us know about this and welcome to GEKKO.
It is throwing Fortran runtime error: Out of memory
, so it looks like your system is running out of memory during the solve process. Is that likely with your system?
If an error crashes the Fortran backend during the solve, then no solution is returned to the Python process and you get a 'results.json' not found
error.
@dhill2522 is correct on diagnosing the problem. Even though you may not be running out of RAM on your computer, it may be a restriction to <=4GB with the 32-bit Windows local process. The macOS and Linux versions of the local executable are 64-bit.
One way to get around this error is to try m.options.IMODE = 7
. It should give the same results as m.options.IMODE=4
but processes the file sequentially instead of simultaneously. This is especially useful if you have large data files or a large model.
Thank you very much @APMonitor & @dhill2522 .
I am running the code on a windows 10 64bit 16GB RAM machine with latest Anaconda and Jupyter and Python and Gekko.
I triedIMODE=7
but now it is saying the DOF
should be zero:
APMonitor, Version 0.9.2 APMonitor Optimization Suite
--------- APM Model Size ------------ Each time step contains Objects : 0 Constants : 4 Variables : 163 Intermediates: 72 Connections : 0 Equations : 107 Residuals : 35
Number of state variables: 98 Number of total equations: - 69 Number of slack variables: - 0
Degrees of freedom : 29
@error: Degrees of Freedom
- Error: DOF must be zero for this mode STOPPING...
Exception Traceback (most recent call last)
in 416 m.options.SOLVER = 1 417 print("ZZZZZZZZZ") --> 418 m.solve(disp=True, debug=True) 419 print("XXXXXXXXXXX") 420 ##State vector C:\Anaconda3\lib\site-packages\gekko\gekko.py in solve(self, disp, debug, GUI, **kwargs) 2057 print("Error:", errs) 2058 if (debug >= 1) and record_error: -> 2059 raise Exception(apm_error) 2060 2061 else: #solve on APM server Exception: @error: Degrees of Freedom * Error: DOF must be zero for this mode STOPPING...
Gekko is correctly reporting that you need to have the same number of m.Var
as m.Equation
for simulation. If it hadn't run out of memory, IMODE=4
would have reported the same error. When you get to optimization then you can have more variables than equations. However, for simulation mode, you'll need to specify some of your variables so that you have a square system.
Thank you again @APMonitor. Then I guess it is related to my intermediate equations. My ODE system has been implemented in MATLAB before and dynamic simulation and solvers work fine. My ODE system is a stiff model of biochemical reactions and my differential equations look like this:
state_n_initial, state_n, v1, v2, v3 = m.Var()
c1 , c2 = m.Const()
p1, p2 = m.Param()
I1 = m.Intermediate(c1 * v1+p1 )
I2 = m.Intermediate(c2 / v2 +I1 - p2 )
.
.
.
state_n.dt() = c3 + v3 * (state_n_initial - state_n) + I2
.
.
m.options.IMODE = 4
m.options.MAX_ITER = 1000
m.options.SOLVER = 1
m.solve(disp=True, debug=True)
state_n_initial is the initial value for state variable state_n What I was trying to point out was that I have nested intermediate equations because 1) differential equations are very long 2) there are different modes of my system that I can change by changing the intermediate equations Thanking you in advance for your help :)
Nested Intermediates shouldn't be a problem and don't contribute to the Degree of Freedom calculation. One way to diagnose your problem is to view the model file that Gekko creates with m.open_folder()
somewhere before the m.solve()
command. You can open the .apm
file with a text editor to view your equations and variables. If you want to make it more readable then give your variables a name with x = m.Var(name='concentration')
. You should have the same number of variables and equations.
Here are some references with:
Lewis, N.R., Hedengren, J.D., Haseltine, E.L., Hybrid Dynamic Optimization Methods for Systems Biology with Efficient Sensitivities, Special Issue on Algorithms and Applications in Dynamic Optimization, Processes, 2015, 3(3), 701-729; doi:10.3390/pr3030701.
Safdarnejad, S.M., Hedengren, J.D., Lewis, N.R., Haseltine, E., Initialization Strategies for Optimization of Dynamic Systems, Computers and Chemical Engineering, Vol. 78, pp. 39-50, DOI: 10.1016/j.compchemeng.2015.04.016.
that may be relevant to your problem.
Thanks a million @APMonitor I will close the issue and come back with comments after I try your links.
Thank you again for your help. The solver worked and is validated. I usedIMODE=7
and for DOF
I had to set some m.Var
as m.FV
That is great to hear! If you do find it useful, please consider including a citation to one of these two references if the work is for eventual publication.
Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014, doi: 10.1016/j.compchemeng.2014.04.013.
Beal, L.D.R., Hill, D., Martin, R.A., and Hedengren, J. D., GEKKO Optimization Suite, Processes, Volume 6, Number 8, 2018, doi: 10.3390/pr6080106.
Absolutely!
Hi, I am trying to solve ODE using Gekko in Python. I running Jupyter and Anaconda on WIn10 64bit, my gekko model arguments are as follows:
and the output I receive is as follow. can you please help me with the issue?