今回の参照先
やったこと
とりあえずコピペ
hello-qc.py
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler import generate_preset_pass_manager
from qiskit_ibm_runtime import EstimatorV2 as Estimator
# Create a new circuit with two qubits
qc = QuantumCircuit(2)
# Add a Hadamard gate to qubit 0
qc.h(0)
# Perform a controlled-X gate on qubit 1, controlled by qubit 0
qc.cx(0, 1)
# Return a drawing of the circuit using MatPlotLib ("mpl"). This is the
# last line of the cell, so the drawing appears in the cell output.
# Remove the "mpl" argument to get a text drawing.
qc.draw("mpl")
諸々抜けてると思うので簡単に環境作り
py -m venv venv
./vemv/Scripts/activate
pip install qiskit
とりあえず実行!
python ./hello-qc.py
モジュールがいろいろ足りていないらしい
ImportError: DLL load failed while importing symengine_wrapper: 指定されたモジュールが見つかりません。
qiskit.exceptions.MissingOptionalLibraryError: "The 'matplotlib' library is required to use 'MatplotlibDrawer'. You can install it with 'pip install matplotlib'."
qiskit.exceptions.MissingOptionalLibraryError: "The 'pylatexenc' library is required to use 'MatplotlibDrawer'. You can install it with 'pip install pylatexenc'."
上記の解消含めてやったこと
- C++ ランタイムインストール(https://www.microsoft.com/ja-jp/download/details.aspx?id=48145)
- symengineのバージョンダウン
pip uninstall symengine
pip install symengine==0.13.0
- matplotlibのpip install
pip install matplotlib
- pylatexencのpip install
pip install pylatexenc
再度実行してみた
python ./hello-qc.py
→何も出力されない...
サンプルコードには何かを出力するような処理はないらしい
以下の2行をコード中に追加
import matplotlib.pyplot as plt
plt.show()
最終姿
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler import generate_preset_pass_manager
from qiskit_ibm_runtime import EstimatorV2 as Estimator
import matplotlib.pyplot as plt
# Create a new circuit with two qubits
qc = QuantumCircuit(2)
# Add a Hadamard gate to qubit 0
qc.h(0)
# Perform a controlled-X gate on qubit 1, controlled by qubit 0
qc.cx(0, 1)
# Return a drawing of the circuit using MatPlotLib ("mpl"). This is the
# last line of the cell, so the drawing appears in the cell output.
# Remove the "mpl" argument to get a text drawing.
qc.draw("mpl")
plt.show()
今度こそ!
python ./hello-qc.py