2

Got the code from here: Implementation of a Lateral contoller using non linear model predictive control in GEKKO

I can't seem to run it. The error I get is:

Solver starts ...

Error: dyld: Library not loaded: /usr/local/opt/gcc/lib/gcc/9/libquadmath.0.dylib

Referenced from: /anaconda3/envs/wsb/lib/python3.6/site-packages/gekko/bin/apm_mac

Reason: image not found

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

Traceback (most recent call last): m.solve(disp=True) File "/anaconda3/envs/wsb/lib/python3.6/site-packages/gekko/gekko.py", line 2216, in solve self.load_JSON() File "/anaconda3/envs/wsb/lib/python3.6/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: '/var/folders/wr/gchm_8mx0dz3sr20158wz4bm0000gn/T/tmp6i1ltndkgk_model0/options.json'

I also tried debugging: Python gekko cant find "options.json" file

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt

m = GEKKO()
m.time = np.linspace(0,20,41)

# Parameters
mass = 500
b = m.Param(value=50)
K = m.Param(value=0.8)

# Manipulated variable
p = m.MV(value=0, lb=0, ub=100)
p.STATUS = 1  # allow optimizer to change
p.DCOST = 0.1 # smooth out gas pedal movement
p.DMAX = 20   # slow down change of gas pedal

# Controlled Variable
v = m.CV(value=0)
v.STATUS = 1  # add the SP to the objective
m.options.CV_TYPE = 2 # squared error
v.SP = 40     # set point
v.TR_INIT = 1 # set point trajectory
v.TAU = 5     # time constant of trajectory

# Process model
m.Equation(mass*v.dt() == -v*b + K*b*p)

m.options.IMODE = 6 # control
m.solve(disp=False)

# get additional solution information
import json
with open(m.path+'//results.json') as f:
    results = json.load(f)

plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(m.time,results['v1.tr'],'k-',label='Reference Trajectory')
plt.plot(m.time,v.value,'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
abrer
  • 61
  • 3
  • FYI: You can use a limited version of markdown to format your questions and answers quite nicely. [Here's some formatting help](https://stackoverflow.com/help/formatting). – martineau Apr 26 '21 at 23:46

1 Answers1

0

The script runs successfully as it is written in your problem statement. The error that you are receiving is because you are using MacOS and switch to m=GEKKO(remote=False). The error and solution is described in this GitHub issue. If you use the remote server then there is no error.

MPC

John Hedengren
  • 12,068
  • 1
  • 21
  • 25