在 OpenMDAO 中,为什么优化器可能会尝试远远超出指定范围的设计变量值?

In OpenMDAO, why might the optimizer try values for design variables far outside the specified range?

我正在使用 pyOptSparseDriver,我的优化器是 SLSQP。我有一个设计变量 A 定义为

ivc = om.IndepVarComp()
ivc.add_output("A", 2.00)
...
prob.model.add_design_var("A", lower=1.6, upper=5.00, ref=1.6)

A表示圆环的纵横比,所以它总是需要大于1才有意义;在这里,我给了它一个稍高的 'reasonable' 下限。

在一个组件中——实际上是模型中第一组中的第一个组件——我看到 A 在其输入中被赋予负值,甚至 nan(结果错误并最终停止代码)。该组件是一个 ExplicitComponent 并且它所在的组没有附加特定的求解器; n2 显示它是 LN:RUNONCE.

这是预期的行为吗?有什么办法可以防止这种情况发生吗?

我尝试过的事情

pyOptSparseDriver 更改为 ScipyOptimizerDriver 不会引发此问题,但出于其他原因我可能想使用前者。

我在模型的其他地方有其他名为 A 的变量(但封装在组中)所以我怀疑这可能是与命名相关的错误;我尝试将 A 重命名为 Asp(这在我的模型中是独一无二的),但问题仍然存在。

为什么我没有 MWE

我尝试在这个初始组之后删除部分模型,但在这样做时我不得不更改 objective 函数。然后,问题就没有了。

可能的提示?

稍后在模型中我有一个带有 NewtonSolver 的组,我将其称为 secondsolver。它使用 Armijo 线性搜索,默认参数为 rhoc.

newton.linesearch = om.ArmijoGoldsteinLS(retry_on_analysis_error=True,
            rho=0.5, c=0.1, method="Armijo", bound_enforcement="vector")

我在组件的计算函数中添加了一个print语句;当我 运行 它输出的代码时

...

===========
thirdsolver
===========
NL: Newton 0 ; 6.54500652 1
|  LS: BCHK 0 ; 0.000394994169 6.03504623e-05
NL: Newton 1 ; 4.4408921e-17 6.7851607e-18
NL: Newton Converged
A in compute is [-37490.25190183]
A in compute is [-18743.90453135]
A in compute is [-9370.73084611]
A in compute is [-4684.1440035]
A in compute is [-2340.85058219]
A in compute is [-1169.20387153]
A in compute is [-583.3805162]
A in compute is [-290.46883854]
A in compute is [-144.01299971]
A in compute is [-70.78508029]
A in compute is [-34.17112058]
<test.py>:104: RuntimeWarning: invalid value encountered in power
<problematic line here; it's from the
 analytic derivative of this first component, where A is being raised to a small, constant, nonzero power>
A in compute is [nan]

这里thirdsolver是模型后面的NewtonSolver。也许印刷发生故障?无论如何,A 的值各相差 2(至少在较高值时),所以这可能与 rho=0.5 有关。如果我在该行搜索上更改参数 rhoc,则错误不再发生。

我可以稍微更改其中一个参数并继续,但如果对正在发生的事情有更好的解释,我希望将来能够避免它。

在旧版本的 SLSQP 中,设计变量边界执行中存在错误。这已在 scipy SLSQP 代码库中修复,但从未在 pyoptsparse 代码库中修复。换句话说,两个代码库中的 SLSQP 代码是不一样的,并且有一点分歧。这解释了为什么 ScipyOptimizerDriver 尊重你的界限而 pyOptSparseDriver 不尊重你的界限(当使用 SLSQP 时)。如果你在 pyOptSparse 中切换到 IPOPT,那么它会尊重你的界限。