1

在使用 ipopt 优化 pyomo 模型时,我收到以下消息:

恢复阶段收敛到原始问题的过滤器无法接受的可行点。恢复阶段中的恢复阶段失败。

这意味着 ipopt 找到了一个可行的点,但是因为它对过滤器来说是不可接受的,所以 ipopt 没有继续尝试寻找问题的局部最优值。这会将“错误”状态返回给 pyomo,我无法加载结果。尝试在实例上使用 pprint 会在它们的起点为我提供所有变量。当 ipopt 遇到恢复失败时,我想找出变量的值。有没有办法我可以做到这一点?

这是我正在使用的代码

try:
    results = opt.solve(instance, tee=tee)
    instance.solutions.load_from(results)
except Exception:
    print('MA.Solve encountered an error:', sys.exc_info()[0])
    traceback.print_exc()

    with open('results.txt', 'w') as f:
        instance.pprint(ostream=f)

这是输出

MA.Solve encountered an error: <class 'ValueError'>
Traceback (most recent call last):
  File "----", line 393, in ----
    results = opt.solve(self.instance, tee=tee)
  File "/usr/lib64/python3.6/site-packages/pyomo/opt/base/solvers.py", line 657, in solve
    default_variable_value=self._default_variable_value)
  File "/usr/lib64/python3.6/site-packages/pyomo/core/base/PyomoModel.py", line 249, in load_from
    % str(results.solver.status))
ValueError: Cannot load a SolverResults object with bad status: error
4

1 回答 1

3

我有一个类似的问题/用例。我正在使用 Pyomo.DAE 来集成 PDE(平方问题)。我的模型名为full.

SolverFactory('ipopt').solve(full, tee=True)

IPOPT 在最后一次迭代中出现恢复失败。

 679r 0.0000000e+00 1.86e-09 4.04e+02 -11.0 1.27e-07  -6.0 1.00e+00 4.88e-04f 12
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
 680r 0.0000000e+00 9.31e-10 1.29e-12 -11.0 1.52e-08  -6.4 1.00e+00 1.00e+00s 36
Restoration phase converged to a point with small primal infeasibility.

Number of Iterations....: 680

                                   (scaled)                 (unscaled)
Objective...............:   0.0000000000000000e+00    0.0000000000000000e+00
Dual infeasibility......:   1.2866497665187040e-12    1.2866497665187040e-12
Constraint violation....:   3.4197000786662102e-10    9.3132257461547852e-10
Complementarity.........:   9.9004652442607800e-12    9.9004652442607800e-12
Overall NLP error.......:   3.4197000786662102e-10    9.3132257461547852e-10


Number of objective function evaluations             = 1800
Number of objective gradient evaluations             = 328
Number of equality constraint evaluations            = 1800
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 719
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 681
Total CPU secs in IPOPT (w/o function evaluations)   =    479.182
Total CPU secs in NLP function evaluations           =     21.007

EXIT: Restoration Failed!

我的模型可能病得很厉害。重新制定正在进行中。不过,我真的很想在最后一次迭代之后检查 IPOPT 解决方案。Pyomo 在 IPOPT 输出后立即抛出此错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-a1795f441929> in <module>
----> 1 SolverFactory('ipopt').solve(full, tee=True)

/anaconda3/lib/python3.7/site-packages/pyomo/opt/base/solvers.py in solve(self, *args, **kwds)
    631                             result,
    632                             select=self._select_index,
--> 633                             default_variable_value=self._default_variable_value)
    634                         result._smap_id = None
    635                         result.solution.clear()

/anaconda3/lib/python3.7/site-packages/pyomo/core/base/PyomoModel.py in load_from(self, results, allow_consistent_values_for_fixed_vars, comparison_tolerance_for_fixed_vars, ignore_invalid_labels, id, delete_symbol_map, clear, default_variable_value, select, ignore_fixed_vars)
    249                 raise ValueError("Cannot load a SolverResults object "
    250                                  "with bad status: %s"
--> 251                                  % str(results.solver.status))
    252         if clear:
    253             #

ValueError: Cannot load a SolverResults object with bad status: error

我的理解是 Pyomo 是在保护我(用户)免受我自己的伤害,而不是在恢复失败后给我解决方案。有没有办法覆盖这个?

于 2019-10-24T12:04:14.483 回答