How to retrieve the 'infeasibilities.txt' from the gekko
Asked Answered
V

1

7

I've got an infeasibility error message from GEKKO simulation. I want to retrieve the 'infeasibilities.txt' file for debugging the algorithm.

Please let me know where I can find the file.

R1 = m.Intermediate(3/r0/W*((A3*(A2+B2+B3+F)+(A2+B2)*(B3+F))*(cg0[0]-ceq1) \
                     -(A3*(B2+B3+F)+B2*(B3+F))*(cg0[0]-ceq2) \
                     -A2*(B3+F)*(cg0[0]-ceq3)))
R2 = m.Intermediate(3/r0/W*(-(B2*(A3+B3+F)+A3*(B3+F))*(cg0[0]-ceq1) \
                     +((A1+B1+B2)*(A3+B3+F)+A3*(B3+F))*(cg0[0]-ceq2) \
                     -(A1+B1)*(B3+F)*(cg0[0]-ceq3)))
R3 = m.Intermediate(3/r0/W*(-A2*(B3+F)*(cg0[0]-ceq1) \
                    -(A1+B1)*(B3+F)*(cg0[0]-ceq2) \
                    +((A1+B1)*(A2+B2+B3+F)+A2*(B2+B1+F))*(cg0[0]-ceq3)))

m.Equation(cH.dt() == nus[0].dot([R1, R2, R3]))
m.Equation(cM.dt() == nus[1].dot([R1, R2, R3]))
m.Equation(cW.dt() == nus[2].dot([R1, R2, R3]))
m.Equation(cF.dt() == nus[3].dot([R1, R2, R3]))

m.options.IMODE = 4
m.options.SOLVER = 3
m.options.nodes = 2

Creating file: infeasibilities.txt

Use command apm_get(server,app,'infeasibilities.txt') to retrieve file

error: Solution Not Found

Vegetation answered 19/6, 2019 at 16:6 Comment(1)
Additional details about the equation residuals can be automatically displayed with or without a successful solution. See #77770895Hoffer
H
10

There are two ways to access the file. The first method is to switch to remote=False to solve locally and produce the infeasibilities.txt file on your computer. The second method is to retrieve the file from the remote directory. The first method is the most simple solution in terms of coding (just change an option and open the run folder). The second method is most convenient because it makes the file available in your run directory. The example that I include below is purposefully infeasible with equations x+y=1 and x+y=0.

Method 1 - Open run folder when remote=False

from gekko import GEKKO
m = GEKKO(remote=False) # remote=False to produce local folder with results          
x = m.Var()    
y = m.Var()
m.Equations([x+y==1, x+y==0])  # no solution
m.open_folder() # open folder if remote=False to see infeasibilities.txt
m.solve(disp=True)    # solve

Method 2 - Retrieve infeasibilities.txt file when remote=True

from gekko import GEKKO
m = GEKKO(remote=True)          
x = m.Var()    
y = m.Var()
m.Equations([x+y==1, x+y==0])  # no solution
try:
    m.solve(disp=True)    # solve
except:
    print('Not successful')
    from gekko.apm import get_file
    print(m._server)
    print(m._model_name)
    f = get_file(m._server,m._model_name,'infeasibilities.txt')
    f = f.decode().replace('\r','')
    with open('infeasibilities.txt', 'w') as fl:
        fl.write(str(f))

The infeasibilities.txt file is somewhat hard to read but it does try to identify equations that are causing the solution to fail. Here is the example from this problem.

************************************************
***** POSSIBLE INFEASBILE EQUATIONS ************
************************************************
____________________________________________________________________________
EQ Number   Lower        Residual     Upper        Infeas.     Name
         1   0.0000E+00  -9.4140E-01   0.0000E+00   9.4140E-01  ss.Eqn(1): 0 = (v1+v2)-(1)
 Variable   Lower        Value        Upper        $Value      Name
         1  -1.2346E+20   2.9300E-02   1.2346E+20   0.0000E+00  ss.v1
         2  -1.2346E+20   2.9300E-02   1.2346E+20   0.0000E+00  ss.v2
____________________________________________________________________________
EQ Number   Lower        Residual     Upper        Infeas.     Name
         2   0.0000E+00   5.8600E-02   0.0000E+00  -5.8600E-02  ss.Eqn(2): 0 = (v1+v2)-(0)
 Variable   Lower        Value        Upper        $Value      Name
         1  -1.2346E+20   2.9300E-02   1.2346E+20   0.0000E+00  ss.v1
         2  -1.2346E+20   2.9300E-02   1.2346E+20   0.0000E+00  ss.v2
************************************************
****** ACTIVE OBJECTIVE EQUATIONS **************
************************************************
Number           ID  Node    Horizon  Unscaled Res  Scaled Res   Scaling     Name
************************************************
************* ACTIVE EQUATIONS *****************
************************************************
Number           ID  Node    Horizon  Unscaled Res  Scaled Res   Scaling     Name
         1          1    1          1  -9.4140E-01  -9.4140E-01   1.0000E+00  ss.Eqn(1): 0 = (v1+v2)-(1)
         2          2    1          1   5.8600E-02   5.8600E-02   1.0000E+00  ss.Eqn(2): 0 = (v1+v2)-(0)
************************************************
************ INACTIVE EQUATIONS ****************
************************************************
Number     Unscaled Res    Scaled Res   Scaling      Name

If you use x = m.Var(name='x') to name your variables then the file will become more descriptive. Both equations were identified as potentially infeasible.

Hoffer answered 19/6, 2019 at 20:21 Comment(3)
Dear John, I really like gekko for DAEs and i appreciate all your answers here, but i'm really a noob and your codes almost always reproduce the same error. E.g., here your code produces "Use command apm_get(server,app,'infeasibilities.txt') to retrieve file". The noob question is: use the command where? Maybe because i'm running everything from jupyter notebook, it's different.Zaporozhye
Try using the command m.open_folder() before the solve command to see the run directory. If m=GEKKO(remote=False) then the infeasibilities.txt file shows up in the run directory. The other command is from APM when you use APM Python or APM Matlab. Gekko is a newer interface to APMonitor (APM).Hoffer
Another option is to set debug=0 when solving to not throw an exception if the solution is not successful. This will allow the program to continue without a try except. This will allow you to run the function m.open_folder() if m.options.APPSTATUS==0 (unsuccessful).Hoffer

© 2022 - 2024 — McMap. All rights reserved.