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?

QURI-Partsのインストールでちょっと詰まった

Last updated at Posted at 2025-03-29

QURI-Partsとは

QunaSysが提供している、量子計算ライブラリです。

はじめに結論

quri-parts[qualcs]をインストールする前に、環境にrust(rustup),cmake,boostをインストールすることで解決しました。
以下で詳細なエラーメッセージなどを書きます。

インストールエラー

筆者はMac(Apple M1)を使用しており、pythonのバージョンは3.13.1です。
早速READMEに従い、pipでインストールしてみます。今回は量子回路シミュレータであるQulacsを使用したいので、オプションとして[qulacs]を指定します。

pip install "quri-parts[qulacs]"

しかし、以下のエラーが出てinstallが失敗しました。

Collecting quri-parts-rust (from quri-parts-circuit->quri-parts[qulacs])
  Using cached quri_parts_rust-0.20.3.tar.gz (629 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
       Checking for Rust toolchain....
       
       Cargo, the Rust package manager, is not installed or is not on PATH.
       This package requires Rust and Cargo to compile extensions. Install it through
       the system's package manager or via https://rustup.rs/
       
  [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.

error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Note: you may need to restart the kernel to use updated packages.

ぐぬぬ。エラーメッセージの真ん中あたりに

Cargo, the Rust package manager, is not installed or is not on PATH.
This package requires Rust and Cargo to compile extensions. Install it through
the system's package manager or via https://rustup.rs/

とあるので、Rustが必要だけど入っていないと言われています。これは、quri-parts-rustquri-parts-circuit に依存)が Rust製のネイティブ拡張を含んでおりそれをビルドするために Rust のビルドツール(cargo)が必要となるためです。

ということでRustをインストールします。今回はrustupというツールを使ってインストールを行います。

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

環境変数を読み込みます。

source $HOME/.cargo/env

Rust/Cargoが使えるか確認しましょう。

rustc --version
cargo --version

rustc 1.85.1 (4eb161250 2025-03-15)とかのそれっぽい文字列が出たらOK。

これでpip install再挑戦!

インストールエラー その2

...
Downloading quri_parts_qulacs-0.20.3-py3-none-any.whl (22 kB)
Building wheels for collected packages: Qulacs, quri-parts-rust
  Building wheel for Qulacs (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for Qulacs (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [197 lines of output]
     ...
     RuntimeError: CMake must be installed to build the following extensions: qulacs_core
  [end of output]
  
Successfully built quri-parts-rust
Failed to build Qulacs
ERROR: Failed to build installable wheels for some pyproject.toml based projects (Qulacs)
Note: you may need to restart the kernel to use updated packages.

ぐぬぬ(2回目)。quri-parts-rustのbuildには成功したけど、今度はQulacsのbuildに失敗したみたいです。

真ん中あたりにまたエラーメッセージが書いてありますね。

RuntimeError: CMake must be installed to build the following extensions: qulacs_core

Qulacs(C++ ベースの量子シミュレータ)は C++ コンパイルが必要であり、そのビルドのためにCMakeが必要ですが、これがインストールされていないみたい。

というわけでCMakeをインストールします。今回はbrewで行います。

brew install cmake

再チャレンジ。

インストールエラー その3

error: subprocess-exited-with-error

× Building wheel for Qulacs (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [225 lines of output]

CMake Error at /opt/homebrew/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least version "1.71.0")

...

subprocess.CalledProcessError: Command '['cmake', ..., '-DCMAKE_CXX_COMPILER=g++', ...]' returned non-zero exit status 1.

note: This error originates from a subprocess, and is likely not a problem with pip.

ERROR: Failed building wheel for Qulacs
ERROR: Failed to build installable wheels for some pyproject.toml based projects (Qulacs)

読んでみると、BoostというC++ライブラリ(特にヘッダ)がないみたい。これがQulacsのビルドに必要みたいですね。

CMake Error at .../FindBoost.cmake: Could NOT find Boost (missing: Boost_INCLUDE_DIR)

というわけでbrew installします。

brew install boost

改めてインストール

改めてpip install "quri-parts[qulacs]"してみます。ドキドキ。

...
Using cached quri_parts_algo-0.20.3-py3-none-any.whl (40 kB)
Using cached quri_parts_chem-0.20.3-py3-none-any.whl (27 kB)
Using cached quri_parts_circuit-0.20.3-py3-none-any.whl (61 kB)
Using cached quri_parts_core-0.20.3-py3-none-any.whl (91 kB)
Using cached quri_parts_qulacs-0.20.3-py3-none-any.whl (22 kB)
Building wheels for collected packages: Qulacs
  Building wheel for Qulacs (pyproject.toml) ...   Created wheel for Qulacs: filename=qulacs-0.6.11-cp313-cp313-macosx_14_0_arm64.whl size=XXX sha256=XXX
  Stored in directory: /Users/XXX/Library/Caches/pip/wheels/~~~~
Successfully built Qulacs
Installing collected packages: quri-parts-rust, quri-parts-circuit, Qulacs, quri-parts-core, quri-parts-qulacs, quri-parts-chem, quri-parts-algo, quri-parts
Successfully installed Qulacs-0.6.11 quri-parts-0.20.3 quri-parts-algo-0.20.3 quri-parts-chem-0.20.3 quri-parts-circuit-0.20.3 quri-parts-core-0.20.3 quri-parts-qulacs-0.20.3 quri-parts-rust-0.20.3
Note: you may need to restart the kernel to use updated packages.

お。できていそう。確かめてみましょう。

pip list | grep quri-parts
quri-parts              0.20.3
quri-parts-algo         0.20.3
quri-parts-chem         0.20.3
quri-parts-circuit      0.20.3
quri-parts-core         0.20.3
quri-parts-qulacs       0.20.3
quri-parts-rust         0.20.3

ということで無事インストールできました。

せっかくなので以下のサイトを参考にVQEを実行してみます。こちらの記事における実装もQURI-Partsのチュートリアルを参考にしているらしいですが、現在はページが見られないようでした。

なんかそれっぽいグラフができたので出来ていそうですね。

これで環境のセットアップができたので、色々計算してみようと思います。

参考文献

  • ChatGPT
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?