Recently, there has been an increase in inquiries about cuQuantum. A challenge up until now has been the difficulty of installation, but with the latest update, it has been improved, making installation much easier.
最近cuQuantumに関する問い合わせが増えています。これまでのcuQuantumはインストールが難しいというのが難点でしたが、今回アップデートがあり、更新され、簡単にインストールができるようになりました。
The new page is available here.
新しいページはこちらです。
https://docs.nvidia.com/cuda/cuquantum/latest/getting_started/getting_started.html
The challenging aspect of installing cuQuantum was its compatibility with platforms like Google Colab and with tools like IBM Qiskit. This time around, these issues have been significantly improved, allowing for seamless use with Google Colab.
cuQuantumのインストールで難しいところは、Google Colabなどのとの相性やIBM Qiskitなどとの相性でした。今回はこの辺りがだいぶ改善されていてGoogle Colabでも問題なく利用ができます。
Matching the CUDA version for cuQuantum was necessary, but with the recent update of Google Colab to CUDA 12, it has become possible to install cuQuantum without having to worry much about the version compatibility.
cuQuantumのcudaのバージョンを揃える必要があるのですが、最近Google Colabがcuda12にアップデートされたことから、あまりバージョンを考えずにcuQuantumを導入することができるようになりました。
As for the installation, I was able to do it with the current setup.
インストールですが、現状はこちらでできました。
pip install -v --no-cache-dir qiskit pylatexenc qiskit-aer-gpu cuquantum-python
First, let's try running a simple circuit without a GPU.
最初にGPU無しで簡単な回路を実行してみます。
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.draw("mpl")
Then, we will run it with a GPU, but a difference from before is that Qiskit has been updated, so some of the libraries have changed.
そして、GPUを実行しますが、以前と異なるところはQiskitのアップデートが入りましたので、ライブラリが一部変更となりました。
import qiskit
from qiskit_aer import AerSimulator
circ = qiskit.QuantumCircuit(3)
circ.h(0)
circ.cx(0, 1)
circ.cx(1, 2)
circ.measure_all()
aersim = AerSimulator(method='statevector', device='GPU', cuStateVec_enable=True)
result_ideal = aersim.run(circ).result()
counts_ideal = result_ideal.get_counts(0)
print('Counts(ideal):', counts_ideal)
Version is
バージョンは、
Qiskit == 1.0.0
cuQuantum == 23.10.0
Let's try it with a larger circuit.
もっと大きめの回路でやってみましょう。
Reference / 参考
https://medium.com/qiskit/improve-quantum-simulations-with-qiskit-aer-cuquantum-9cd4bf69f042
First, let's try running it on a CPU.
まずはCPUで実行してみます。
from qiskit import *
from qiskit.circuit.library import *
from qiskit_aer import AerSimulator
sim = AerSimulator(method='statevector')
qubits = 25
depth=10
shots = 10
circuit = QuantumVolume(qubits, depth, seed=0)
circuit.measure_all()
circuit = transpile(circuit, sim)
result = sim.run(circuit,shots=shots,seed_simulator=12345).result()
print("{0} qubits Quantum Volume, Simulation Time = {1} sec".format(qubits,result.to_dict()['results'][0]['time_taken']))
counts = result.get_counts()
print(counts)
25 qubits Quantum Volume, Simulation Time = 37.322770233 sec
{'1010111101100001111010011': 1, '1000111000011010101000011': 1, '1001000111000110110100000': 1, '0101101110100000011100100': 1, '0011010010001011101111100': 1, '0000011101100010011010000': 1, '1010111101000011110100001': 1, '0111011110110010100001000': 1, '0110011010011001111001110': 1, '0011010001101001110011010': 1}
Next, let's try running it on a GPU.
次にGPUで実行してみます。
sim = AerSimulator(method='statevector', device='GPU', cuStateVec_enable=True)
25 qubits Quantum Volume, Simulation Time = 1.133072321 sec
{'1010111101100001111010011': 1, '1000111000011010101000011': 1, '1001000111000110110100000': 1, '0101101110100000011100100': 1, '0011010010001011101111100': 1, '0000011101100010011010000': 1, '1010111101000011110100001': 1, '0111011110110010100001000': 1, '0110011010011001111001110': 1, '0011010001101001110011010': 1}
There was a significant difference in speed. Even with Google Colab's T4 GPU, the computation was able to be performed very quickly.
かなりの速度差が出ましたね。Google ColabのT4GPUでも十分に高速に計算ができました。
Let's try running it with an even larger circuit.
もう少し大きめの回路で実行してみます。
def circ(qubits, depth):
circuit = QuantumVolume(qubits, depth, seed=0)
circuit.measure_all()
circuit = transpile(circuit, sim)
result = sim.run(circuit,shots=10,seed_simulator=12345).result()
return result.to_dict()['results'][0]['time_taken']
sim = AerSimulator(method='statevector')
arr_cpu = []
for i in range(10):
arr_cpu.append(circ(15+i, 30))
sim = AerSimulator(method='statevector', device='GPU', cuStateVec_enable=True)
arr_gpu = []
for i in range(10):
arr_gpu.append(circ(15+i, 30))