How do I find GEKKO application success status?

Question:

I am running m.solve() in a try .. except construct to elegantly handle any exceptions raised by the solver due to maximum iterations or convergence to an infeasibility but want to interrogate APPINFO and APPSTATUS to determine if a solution was found. I was surprised to see that I always seem to get APPINFO=0 and APPSTATUS=1 even though the the solver reports that a solutions was not found.

What am I missing in my interpretation of the document on APPINFO and APPSTATUS?

Piece of code to reproduce error.

from gekko import GEKKO

m=GEKKO(remote=False)

m.x=m.Var()
m.y=m.Var()

m.total=m.Intermediate(m.x+m.y)

m.Equation(m.total>20)  #if included, no feasible solution exists
m.Equation(m.x<9)
m.Equation(m.y<9)
m.Maximize(m.total)
m.options.SOLVER=3
try:
   m.solve()
except Exception as e:
    print('Exception',e)
    
print('APPINFO', m.options.APPINFO)
print('APPSTATUS', m.options.APPSTATUS)
Asked By: JacquesStrydom

||

Answers:

Use debug=False to not raise an exception when Gekko fails to solve. When there is an exception, the results are not loaded back into m.options.

from gekko import GEKKO

m=GEKKO(remote=False)

m.x=m.Var()
m.y=m.Var()

m.total=m.Intermediate(m.x+m.y)

m.Equation(m.total>20)  #if included, no feasible solution exists
m.Equation(m.x<9)
m.Equation(m.y<9)
m.Maximize(m.total)
m.options.SOLVER=3
m.solve(debug=False)
    
print('APPINFO', m.options.APPINFO)
print('APPSTATUS', m.options.APPSTATUS)

This produces the correct error response:

 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :  0.0156 sec
 Objective      :  -18.023281704731964
 Unsuccessful with error code  0
 ---------------------------------------------------
 
 Creating file: infeasibilities.txt
 Use command apm_get(server,app,'infeasibilities.txt') to retrieve file
 @error: Solution Not Found

APPINFO 2
APPSTATUS 0
Answered By: John Hedengren
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.