Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if type(byte) is bytes:
return byte.decode().replace('\r','')
else:
return byte
try:
results = byte2str(get_file(self._server,self._model_name,'results.json'))
f = open(os.path.join(self._path,'results.json'), 'w')
f.write(str(results))
f.close()
options = byte2str(get_file(self._server,self._model_name,'options.json'))
f = open(os.path.join(self._path,'options.json'), 'w')
f.write(str(options))
f.close()
if self.options.CSV_WRITE >= 1:
results = byte2str(get_file(self._server,self._model_name,'results.csv'))
with open(os.path.join(self._path,'results.csv'), 'w') as f:
f.write(str(results))
if self.options.CSV_WRITE >1:
results_all = byte2str(get_file(self._server,self._model_name,'results_all.csv'))
with open(os.path.join(self._path,'results_all.csv'), 'w') as f:
f.write(str(results_all))
except:
raise ImportError('No solution or server unreachable.\n'+\
' Show errors with m.solve(disp=True).\n'+\
' Try local solve with m=GEKKO(remote=False).')
if timing == True:
print('solve', time.time() - t)
if timing == True:
t = time.time()
#solve remotely
response = cmd(self._server, self._model_name, 'solve', disp, debug)
#print APM error message and die
if (debug >= 1) and ('@error' in response):
raise Exception(response)
#load results
def byte2str(byte):
if type(byte) is bytes:
return byte.decode().replace('\r','')
else:
return byte
try:
results = byte2str(get_file(self._server,self._model_name,'results.json'))
f = open(os.path.join(self._path,'results.json'), 'w')
f.write(str(results))
f.close()
options = byte2str(get_file(self._server,self._model_name,'options.json'))
f = open(os.path.join(self._path,'options.json'), 'w')
f.write(str(options))
f.close()
if self.options.CSV_WRITE >= 1:
results = byte2str(get_file(self._server,self._model_name,'results.csv'))
with open(os.path.join(self._path,'results.csv'), 'w') as f:
f.write(str(results))
if self.options.CSV_WRITE >1:
results_all = byte2str(get_file(self._server,self._model_name,'results_all.csv'))
with open(os.path.join(self._path,'results_all.csv'), 'w') as f:
f.write(str(results_all))
except:
if (debug >= 1) and ('@error' in response):
raise Exception(response)
#load results
def byte2str(byte):
if type(byte) is bytes:
return byte.decode().replace('\r','')
else:
return byte
try:
results = byte2str(get_file(self._server,self._model_name,'results.json'))
f = open(os.path.join(self._path,'results.json'), 'w')
f.write(str(results))
f.close()
options = byte2str(get_file(self._server,self._model_name,'options.json'))
f = open(os.path.join(self._path,'options.json'), 'w')
f.write(str(options))
f.close()
if self.options.CSV_WRITE >= 1:
results = byte2str(get_file(self._server,self._model_name,'results.csv'))
with open(os.path.join(self._path,'results.csv'), 'w') as f:
f.write(str(results))
if self.options.CSV_WRITE >1:
results_all = byte2str(get_file(self._server,self._model_name,'results_all.csv'))
with open(os.path.join(self._path,'results_all.csv'), 'w') as f:
f.write(str(results_all))
except:
raise ImportError('No solution or server unreachable.\n'+\
' Show errors with m.solve(disp=True).\n'+\
' Try local solve with m=GEKKO(remote=False).')
try:
results = byte2str(get_file(self._server,self._model_name,'results.json'))
f = open(os.path.join(self._path,'results.json'), 'w')
f.write(str(results))
f.close()
options = byte2str(get_file(self._server,self._model_name,'options.json'))
f = open(os.path.join(self._path,'options.json'), 'w')
f.write(str(options))
f.close()
if self.options.CSV_WRITE >= 1:
results = byte2str(get_file(self._server,self._model_name,'results.csv'))
with open(os.path.join(self._path,'results.csv'), 'w') as f:
f.write(str(results))
if self.options.CSV_WRITE >1:
results_all = byte2str(get_file(self._server,self._model_name,'results_all.csv'))
with open(os.path.join(self._path,'results_all.csv'), 'w') as f:
f.write(str(results_all))
except:
raise ImportError('No solution or server unreachable.\n'+\
' Show errors with m.solve(disp=True).\n'+\
' Try local solve with m=GEKKO(remote=False).')
if timing == True:
print('solve', time.time() - t)
if timing == True:
t = time.time()
self.load_results()
if timing == True:
print('load results', time.time() - t)