BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization
https://machinelearning.byu.edu
Other
580 stars 103 forks source link

No JSON object could be decoded #43

Closed costezki closed 5 years ago

costezki commented 5 years ago

I am new to GEKKO, it seems an amazing tool but there are some things that are nit entirely clear to me so some help would be greatly appreciated.

I run the code below and get an exception about badly encoded rtesults.json. It is true, the json file contains HTML codeof some 404 server not found page. It is not clear to me: (a) why this simulator needs to use a json file, why it strangely, (b) when something seems incorrect (though starting from time 1 is not really incorrect) the json file is ill written and (c) what is a good method (if any available) to test if the provided ODE is well or ill defined.

long_term_inflation_rate = 0.0173 m = GEKKO(remote=None) print(m.path+'/results.json') m.options.IMODE = 4 m.time = np.linspace(1,10,100) # fails to run if not set from zero t = m.Param(value=m.time) i = long_term_inflation_rate x = m.Var(value=10)

y = m.Var(value=20)

m.Equation(x.dt() == i*x) m.solve(disp=False) plt.xlabel('time') plt.ylabel('x') plt.plot(m.time,x.value)

When I try to run the ODE solver for a simple equation, and the time is not set from zero then i get this exception. The content of the results.json file is actually HTML content provided after the exception.


ValueError Traceback (most recent call last)

in () 16 m.Equation(x.dt() == i*x) 17 ---> 18 m.solve(disp=False) 19 20 plt.xlabel('time') /usr/local/lib/python2.7/dist-packages/gekko/gekko.pyc in solve(self, disp, debug, GUI, **kwargs) 734 if timing == True: 735 t = time.time() --> 736 self.load_results() 737 if timing == True: 738 print('load results', time.time() - t) /usr/local/lib/python2.7/dist-packages/gekko/gk_post_solve.pyc in load_results(self) 76 if (os.path.isfile(os.path.join(self._path, 'results.json'))): 77 f = open(os.path.join(self._path,'results.json')) ---> 78 data = json.load(f) 79 f.close() 80 /usr/lib/python2.7/json/__init__.pyc in load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 289 parse_float=parse_float, parse_int=parse_int, 290 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, --> 291 **kw) 292 293 /usr/lib/python2.7/json/__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 337 parse_int is None and parse_float is None and 338 parse_constant is None and object_pairs_hook is None and not kw): --> 339 return _default_decoder.decode(s) 340 if cls is None: 341 cls = JSONDecoder /usr/lib/python2.7/json/decoder.pyc in decode(self, s, _w) 362 363 """ --> 364 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 365 end = _w(s, end).end() 366 if end != len(s): /usr/lib/python2.7/json/decoder.pyc in raw_decode(self, s, idx) 380 obj, end = self.scan_once(s, idx) 381 except StopIteration: --> 382 raise ValueError("No JSON object could be decoded") 383 return obj, end ValueError: No JSON object could be decoded

The contents of results.json:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

404 Not Found

Not Found

The requested URL /online/195.218.17.172_gk_model22/results.json was not found on this server.

APMonitor commented 5 years ago

There was an error and the json results file was not produced. You can see your error if you print the output of the solve command such as:

output = m.solve() print(output)

There is an APMonitor / GEKKO discussion group available at http://apmonitor.com/wiki/index.php/Main/UsersGroup if you'd like to send support requests or initiate other discussions. This location is also fine.

APMonitor commented 5 years ago

The latest release has much better error handling. Please update with: pip install gekko --upgrade to get the latest release. This should avoid any issues with trying to read a json file that is not present (results in 404: not found) because of an error with the model or data.