0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ColabReactionをローカルで試すためにIpoptをビルドした話

Last updated at Posted at 2025-09-03

はじめに

ColabReactionをローカルで動かそうとしたところ、Pythonバインディングのcyipoptを使うにはIpopt本体が必要でした。
公式をざっと読むと、BLAS/LAPACK/MUMPSが入っていればビルドできそう……ということで、WSL2(Ubuntu)上でソースから構築した手順をチュートリアル風にまとめます。

  • 検証環境:WSL2 / Ubuntu 22.04(相当)
  • 目的:Ipopt本体+MUMPSをビルドして、後でcyipoptから使える状態にする

依存ライブラリのインストール

まずはコンパイラとBLAS/LAPACK、MUMPSが内部で使うMETISなどを入れます。

sudo apt-get update
sudo apt-get install -y \
  gcc g++ gfortran git patch wget pkg-config \
  liblapack-dev libmetis-dev

メモ:

  • BLAS/LAPACK:数値線形代数の基盤
  • METIS:MUMPSが行列分解の前処理で使うグラフ分割ツール
  • **Fortranコンパイラ(gfortran)**は数値計算系でほぼ必須

MUMPSのビルドとインストール

Ipoptと相性の良い構成にするため、COIN-ORが用意しているThirdParty-Mumps経由で取得します。

cd ~/
mkdir -p ipopt_make && cd ipopt_make

git clone https://github.com/coin-or-tools/ThirdParty-Mumps.git
cd ThirdParty-Mumps

./get.Mumps
./configure --prefix=/usr/local
make -j
sudo make install

ポイント:

  • make -jで並列ビルドにして時間短縮
  • インストール後、pkg-config --cflags coinmumpsが通ればOK
    /usr/local/lib/pkgconfig/coinmumps.pcが入る想定)

Ipopt本体のビルドとインストール

続いてIpopt本体をビルドします。MUMPSのヘッダとライブラリをpkg-configで参照しつつ、BLAS/LAPACKもリンクします。

cd ~/ipopt_make
git clone https://github.com/coin-or/Ipopt.git
cd Ipopt
mkdir -p build && cd build

CPPFLAGS="$(pkg-config --cflags coinmumps)" \
LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib" \
../configure \
  --with-mumps-cflags="$(pkg-config --cflags coinmumps)" \
  --with-mumps-lflags="$(pkg-config --libs coinmumps) -lblas -llapack -lgfortran"

make -j
sudo make install

ポイント:

  • -Wl,-rpath,/usr/local/lib を付けておくと、実行時に共有ライブラリを見つけやすい
  • うまくいかない場合はsudo ldconfigでリンクキャッシュを更新

動作確認(Ipopt本体)

インストールされたバイナリやライブラリが見えるかを簡単にチェックします。

# 共有ライブラリの検索パス更新(必要なら)
echo '/usr/local/lib' | sudo tee /etc/ld.so.conf.d/local-usrlocal.conf
sudo ldconfig

# インストール物の確認(存在すればOK)
ls /usr/local/lib | grep -i ipopt
ls /usr/local/include | grep -i ipopt

必要に応じてIpopt/examplesをビルドしてサンプル実行しても良いですが、本記事では割愛します。


ここまでのまとめ

  • cyipoptIpopt本体が事前に入っていることが前提
  • 公式ドキュメントは最小限なので、MUMPS+BLAS/LAPACKのリンク指定を明示しないと詰まりがち
  • 本記事の手順で、pkg-config coinmumpsを使いながらIpoptをビルド・インストールできる

次回予告

  • pip install cyipoptでPythonバインディングを導入
  • dmfを使ってみる

付録:トラブルシュート(簡易)

  • pkg-config --cflags coinmumpsが空になる
    ThirdParty-Mumpsmake installに失敗していないか確認。/usr/local/lib/pkgconfig/coinmumps.pcがあるかチェック。
  • リンク時にundefined referencelibmumps系が見つからない
    LDFLAGS-L/usr/local/libが入っているか、ldconfigを実行したか確認。
  • ランタイムでlibipopt.so: cannot open shared object file
    -Wl,-rpath,/usr/local/libの付与 or /etc/ld.so.conf.d/usr/local/libを追加してsudo ldconfig
  • 下記が出たらPythonの開発ヘッダが未インストール。
cyipopt/cython/ipopt_wrapper.c:42:10: fatal error: Python.h: No such file or directory
         42 | #include "Python.h"
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

下記でインストールできる。

sudo apt-get install -y python3-dev python3.12-dev

以上。次回はcyipoptインストールとdmf実行まで行きます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?