2

Running the attached code results in the below error. The error is the same even if changing m.options.SOLVER to 2 or 3

Traceback (most recent call last): File "C:\Users\17576\Documents\Python\Scratch.py", line 33, in m.solve() File "C:\Users\17576\Documents\Python\venv\lib\site-packages\gekko\gekko.py", line 2227, in solve self.load_JSON() File "C:\Users\17576\Documents\Python\venv\lib\site-packages\gekko\gk_post_solve.py", line 13, in load_JSON f = open(os.path.join(self._path,'options.json')) FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\17576\AppData\Local\Temp\tmpp6w85mm5gk_model0\options.json'

Error: The system cannot find the path specified.

Error: 'results.json' not found. Check above for additional error details

Process finished with exit code 1

from gekko import GEKKO

# Variables
var_a = 155.31
var_b = 6.27
var_c = 12
var_d = 750
var_e = 10
var_f = 1
var_d_lower_bound_percentage = .99
var_e_lower_bound_percentage = .99
var_e_upper_bound_percentage = 1.01
x_value = 1
y_value = 3

# Optimization
m = GEKKO(remote=False)

x = m.Var(value=x_value, lb=0)
y = m.Var(value=y_value, lb=0, integer=True)

m.Equation(x*var_a + y*var_b <= var_d)
m.Equation(x*var_a + y*var_b >= var_d*var_d_lower_bound_percentage)

m.Equation(((x*var_a)/(x*var_a + y*var_b)) + ((y*var_b)/(x*var_a + y*var_b)) == 1)

m.Equation(((x*var_a)/(x*var_a + y*var_b))*var_f + ((y*var_b)/(x*var_a + y*var_b))*var_c <= var_e*var_e_upper_bound_percentage)
m.Equation(((x*var_a)/(x*var_a + y*var_b))*var_f + ((y*var_b)/(x*var_a + y*var_b))*var_c >= var_e*var_e_lower_bound_percentage)

m.Obj(((x*var_a)/(x*var_a + y*var_b))*var_f + ((y*var_b)/(x*var_a + y*var_b))*var_c)

m.options.SOLVER = 1
m.solve()

print(x.value)
print(y.value)
JackW24
  • 135
  • 9
  • Surely there's more to that error? Like, I would assume there's some context that appeared beforehand... – Random Davis Sep 20 '22 at 21:00
  • This is the only other context: `Traceback (most recent call last): File "C:\Users\17576\Documents\Python\Scratch.py", line 33, in m.solve() File "C:\Users\17576\Documents\Python\venv\lib\site-packages\gekko\gekko.py", line 2227, in solve self.load_JSON() File "C:\Users\17576\Documents\Python\venv\lib\site-packages\gekko\gk_post_solve.py", line 13, in load_JSON f = open(os.path.join(self._path,'options.json')) FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\17576\\AppData\\Local\\Temp\\tmpb0n_da1ogk_model0\\options.json'` – JackW24 Sep 20 '22 at 21:22
  • Please put errors and code into the question itself as formatted text, never in comments. – Random Davis Sep 20 '22 at 21:35
  • Anyway, it's telling you that `options.json` is missing. That's the same error that was in [this post](https://stackoverflow.com/questions/60649331/python-gekko-cant-find-options-json-file). You didn't mention you'd looked up anything previously or made any kind of research effort, so also make sure to update your post if you've tried the solutions at that link already. – Random Davis Sep 20 '22 at 21:37
  • I added the full message in the body of the question. I mentioned in the question that I tried one of those solves and the other I just tried (bounding decision variables) and still get the same error – JackW24 Sep 20 '22 at 22:13

1 Answers1

0

Try upgrading the version of gekko. See instructions on managing packages if additional support is needed.

pip install gekko --upgrade

Both remote and local solutions complete successfully with gekko version 1.0.5. From the path error, it appears that it is either an older version or else there is a permission error with writing to the tmp run directory folder on your Windows computer.

 ----------------------------------------------------------------
 APMonitor, Version 1.0.0
 APMonitor Optimization Suite
 ----------------------------------------------------------------
 --------- APM Model Size ------------
 Each time step contains
   Objects      :  0
   Constants    :  0
   Variables    :  6
   Intermediates:  0
   Connections  :  0
   Equations    :  6
   Residuals    :  6
 
 Number of state variables:    6
 Number of total equations: -  5
 Number of slack variables: -  4
 ---------------------------------------
 Degrees of freedom       :    -3
 
 * Warning: DOF <= 0
 ----------------------------------------------
 Steady State Optimization with APOPT Solver
 ----------------------------------------------
Iter:     1 I:  0 Tm:      0.00 NLPi:    5 Dpth:    0 Lvs:    2 Obj:  9.90E+00 Gap:       NaN
--Integer Solution:   9.90E+00 Lowest Leaf:   9.90E+00 Gap:   0.00E+00
Iter:     2 I:  0 Tm:      0.00 NLPi:    5 Dpth:    1 Lvs:    2 Obj:  9.90E+00 Gap:  0.00E+00
 Successful solution
 
 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :  0.0156 sec
 Objective      :  9.9
 Successful solution
 ---------------------------------------------------

[0.91446827259]
[96.0]

Update

It appears that there is an error with running the apm executable locally for JackW24, but not with the cloud-based service (default option) with remote=True. An error with running locally can be diagnosed by running the executable such as the following for Linux:

user@domain:/$ cd /home/user/.local/lib/python3.8/site-packages/gekko/bin/
user@domain:~/.local/lib/python3.8/site-packages/gekko/bin$ ./apm
 ----------------------------------------------------------------
 APMonitor, Version 1.0.1
 APMonitor Optimization Suite
 ----------------------------------------------------------------
 
 @error: Model File Not Found
 Model file does not exist: model.apm
 STOPPING...

If there is a different result than this, it indicates that there is a problem with running remote=False.

TexasEngineer
  • 684
  • 6
  • 15
John Hedengren
  • 12,068
  • 1
  • 21
  • 25
  • I upgraded and am still getting the same error. How would you recommend I approach determining if it is a permission error? – JackW24 Sep 21 '22 at 21:17
  • Try the command m.open_folder() to see if the files are written to the directory. Another potential issue is that apm.exe is prevented from running although I haven’t seen that error previously. Are you on a corporate computer with restrictive policies? – John Hedengren Sep 22 '22 at 00:52
  • If the problem runs successfully with remote=True then it is likely a tmp folder permission error. If it is only with remote=False then it is likely an executable blocked. What is the version of Python? – John Hedengren Sep 22 '22 at 00:55
  • 1
    Sorry for the late response, it is not a corporate computer, it is personal and i haven't set any restrictions. And I have Python 3.10 – JackW24 Sep 24 '22 at 02:42
  • Do you get an error with remote=True? – John Hedengren Sep 24 '22 at 03:38
  • 1
    I do not get an error with remote=True – JackW24 Sep 24 '22 at 19:11
  • I can't reproduce the error, unfortunately. Could you try running `apm.exe` that is in the python Lib/site-packages/gekko/bin folder? There may be an error with running the local executable on your computer. If there is an error, please send any message that it returns to a `cmd` prompt. – John Hedengren Sep 25 '22 at 03:59
  • 1
    `JackW24` - I added a method that has helped me diagnose local run issues. See `update`. – TexasEngineer Oct 07 '22 at 13:07