python 壁虎 : How to avoid raising an error from IPOPT "Solved to Acceptable Level."

标签 python gekko

我正在模拟中求解一组方程(IMODE = 1,SOLVER = 3)。 IPOPT 求解器求解到可接受的水平并退出,但 gekko 为此返回错误并返回我的解。根据 IPOPT 文档,可接受级别的容差为 1.0e-6,这与 gekko 使用的 OTOL 和 RTOL 的默认值(以及我正在使用的值)相同。我能够修改 gekko.py 源代码来返回我的答案,但这样做我绕过了所有类型的错误。我不希望绕过所有错误,因为它们显然有助于调试其他问题,例如不可行性。是否有我缺少的 m.solve 选项,或者当 IPOPT 求解到可接受的水平时不触发错误的其他方法?

最佳答案

处理求解器错误的一种方法是将求解命令包装在 try except 语句中。 APPINFO输出可能会指导您遇到什么类型的错误,并让您对“不可行的解决方案”、“已解决到可接受的水平”或 other IPOPT error codes 做出不同的 react 。 .

try:
   m.solve(disp=True)
except:
   print('Solver error, looking at APPINFO')
   if m.options.APPINFO==1:
      print('APPINFO=1')
   elif m.options.APPINFO==2:
      print('APPINFO=2')

另一个选择是 try a different solver such as APOPT or BPOPT .

m.options.SOLVER = 1

编辑: 当 Gekko 引发求解器异常时,参数 APPINFO 不会更新。请尝试使用 debug=0 执行以下操作:

m.solve(disp=True,debug=0)
if m.options.APPINFO!=0:
   print('Solver error, looking at APPINFO')
if m.options.APPINFO==1:
   print('APPINFO=1')
elif m.options.APPINFO==2:
   print('APPINFO=2')

我刚刚更新了 Gekko,以便远程解决也将绕过引发的异常并使用 APPINFO 信息完成选项文件的处理。本地运行时,APPINFO 信息位于运行目录中的 options.json 中,并通过 gk_post_solve.py< 中的 load_JSON 读取.

关于 python 壁虎 : How to avoid raising an error from IPOPT "Solved to Acceptable Level.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58019008/

相关文章:

python - python pandas 转换 Unix 时间戳

python - 是什么导致 pyodbc 出现 'unable to connect to data source'?

python - 使用随机模块python进行不同程度的改组

python - 使用 GEKKO 解决约束 x(0) + x(2) =0 的最优控制问题

python - 使用 GEKKO 的 CSTR 稳态参数估计

gekko - 使用 Gekko 优化,为什么我的模型构建器比我的求解器慢得多?

python执行远程程序

python - Django框架: 'UserView' object has no attribute 'object'

iteration - Gekko 处理代数/隐式循环

python - 如何修复 'can' t 打开文件 'pip' : [Errno 2] No such file or directory' when installing gekko