使用带有 OpenMDAO 的 pyoptsparse 驱动程序访问 NSGA2 种群大小

Accessing NSGA2 population size using pyoptsparse driver with OpenMDAO

我正在尝试修改通过 OpenMDAO 的 pyoptsparse 驱动程序使用 NSGA2 优化器时的 GA 人口规模。

我尝试使用 opt_settings 字典从 pyNSGA2.py 访问 PopSize,如下所示:

prob.driver = om.pyOptSparseDriver(optimizer='NSGA2')
prob.driver.opt_settings["PopSize"] = 150

但是,这会导致分段错误,消息如下:

[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind
[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory corruption errors
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run 
[0]PETSC ERROR: to get more information on the crash.
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 50152059.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.

是否有不同的方法来访问 NSGA2 优化器的选项而不是 opt_settings 字典?我对 Python 比较陌生,所以我也怀疑我的语法也可能不正确。

更新: 对于更多上下文,我尝试 运行 没有 PETSC。优化在不尝试更改 PopSize 的情况下成功,但是在尝试更改 PopSize 时它仅因 Segmentation fault 而崩溃。跟踪错误,根据下面的消息

,我相信分段错误的来源在 pyoptsparse/pyNSGA2/source/crossover.c
Program received signal SIGSEGV, Segmentation fault.
0x00007fffbc85747b in realcross (parent1=parent1@entry=0x1864bf0, parent2=parent2@entry=0x186d030, 
    child1=child1@entry=0x1868280, child2=child2@entry=0x18682c0, global=..., nrealcross=<optimized out>)
    at pyoptsparse/pyNSGA2/source/crossover.c:104
104                 child2->xreal[i] = parent2->xreal[i];

我还尝试在新机器上全新安装 PETSC,但这让我又遇到了同样的错误。

在查看 NSGA2 优化器的 C 源代码时,我发现问题不在于访问人口规模选项,而是我指定了无效的人口规模。根据 nsga2.c 的文件头注释, 种群大小必须是 4 的倍数。

我能够成功 运行 在人口规模为 160 而不是 150 时进行优化。