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

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

我使用的是 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 才能有物理意义;在这里,我给了它一个略高的“合理”下限。

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

这是预期的行为吗?有没有办法防止这种情况发生?

我尝试过的事情

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

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

为什么我没有 MWE

我尝试在这个初始组之后删除模型的一部分,但这样做时我不得不更改目标函数。然后,问题不再发生。

可能的提示?

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

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,那么它会尊重你的界限。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res