优化器返回错误时加载pyomo解决方案

问题描述 投票:0回答: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
optimization pyomo ipopt
1个回答
0
投票

我有一个类似的问题/用例。我正在使用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正在保护我(用户)免受自身侵害,并且在恢复失败后没有提供解决方案。有没有方法可以覆盖它?

© www.soinside.com 2019 - 2024. All rights reserved.