gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:51:03 32 4
gpt4 key购买 nike

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

最佳答案

处理求解器错误的一种方法是将求解命令包装在 tryexcept 语句中。 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信息在本地运行时在run目录下的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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com