You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu下配置HSL MA86与OpenMDAO中IPOPT协同的问题排查

问题:OpenMDAO中IPOPT配置HSL MA86线性求解器失败

在Linux Ubuntu系统中配置OpenMDAO的IPOPT求解器使用HSL MA86线性求解器,已完成以下操作:

  • 解压HSL MA86和IPOPT到指定位置
  • 安装BLAS、LAPACK、METIS等依赖库
  • 配置MA86与依赖库的路径关联

运行时错误

启用MA86线性求解器(取消注释以下代码)时:

p.driver.opt_settings['linear_solver'] = 'ma86'

IPOPT输出错误:

Exit Status
      Inform  Description
         -12  Invalid Option
--------------------------------------------------------------------------------

推测IPOPT未成功关联HSL MA86。

HSL MA86安装时的异常

执行make install(在make和make check之后)时,出现以下错误片段(路径已隐去):

/usr/bin/install: 'include/hsl_ma86s.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_ma86s.h' are the same file
/usr/bin/install: 'include/hsl_ma86d.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_ma86d.h' are the same file
/usr/bin/install: 'include/hsl_ma86c.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_ma86c.h' are the same file
/usr/bin/install: 'include/hsl_ma86z.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_ma86z.h' are the same file
/usr/bin/install: 'include/hsl_mc68i.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_mc68i.h' are the same file
/usr/bin/install: 'include/hsl_mc69s.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_mc69s.h' are the same file
/usr/bin/install: 'include/hsl_mc69d.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_mc69d.h' are the same file
/usr/bin/install: 'include/hsl_mc69c.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_mc69c.h' are the same file
/usr/bin/install: 'include/hsl_mc69z.h' and '/path/to/hsl_ma86-1.7.4/include/hsl_mc69z.h' are the same file
make[2]: *** [Makefile:418: install-includeHEADERS] Error 1
make[2]: Leaving directory '/path/to/hsl_ma86-1.7.4'
make[1]: *** [Makefile:749: install-am] Error 2
make[1]: Leaving directory '/path/to/hsl_ma86-1.7.4'
make: *** [Makefile:445: install-recursive] Error 1

当前路径设置方式

默认LD_LIBRARY_PATH未包含MA86库路径,使用以下Python代码临时修改路径运行OpenMDAO程序:

import os
import subprocess

def my_function():
    # Path to HSL MA86 libraries -- needed to temporarily change for OpenMDAO code
    ma86_path = "/path/to/hsl_ma86-1.7.4/lib"

    # Obtains the original library path necessary for other code
    original_libPath = os.environ.get('LD_LIBRARY_PATH', '')    

    try:
        # Temporarily sets the library path to HSL MA86 so that IPOPT can find it
        # os.environ['LD_LIBRARY_PATH'] = f"{ma86_path}:{original_libPath}"
        os.environ['LD_LIBRARY_PATH'] = ma86_path
        print('LD_LIBRARY_PATH: {}'.format(os.environ['LD_LIBRARY_PATH']))
        print('Subprocess executed')
        # Execute trajectory code using HSL MA86
        subprocess.run(["python", "my_openmdao_code.py"])
        

    finally:
        # Resets initial library path for use in optimization
        os.environ['LD_LIBRARY_PATH'] = original_libPath
        print('Restoration Occured')
        print('LD_LIBRARY_PATH: {}'.format(os.environ['LD_LIBRARY_PATH']))
if __name__ == '__main__':
    
    my_function()

排查建议

  1. 修复MA86安装错误

    • 执行make install时指定非源码目录的安装路径,比如:
      ./configure --prefix=/usr/local/hsl-ma86
      make && make check && make install
      
    • 避免将安装目录设置为源码目录本身,这会导致install命令尝试覆盖源码文件,引发错误。
  2. 验证IPOPT编译时是否关联MA86

    • 重新编译IPOPT时,确保指定MA86的库和头文件路径,比如:
      ./configure --with-hsl=/usr/local/hsl-ma86
      make && make install
      
    • 编译完成后,检查IPOPT是否能找到MA86:
      ipopt --version
      
      正常情况下会显示HSL求解器支持。
  3. 修正LD_LIBRARY_PATH设置

    • 不要覆盖原有LD_LIBRARY_PATH,改为追加MA86路径:
      os.environ['LD_LIBRARY_PATH'] = f"{ma86_path}:{original_libPath}"
      
    • 或者直接在终端中临时设置路径后运行程序,排除Python代码的环境传递问题:
      export LD_LIBRARY_PATH=/usr/local/hsl-ma86/lib:$LD_LIBRARY_PATH
      python my_openmdao_code.py
      
  4. 检查IPOPT配置选项

    • 确认IPOPT支持ma86求解器,部分版本可能需要用linear_solver=MA86的全大写格式,可通过IPOPT官方文档确认正确的选项名称。

内容的提问来源于stack exchange,提问作者ilaudo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 18:05:12