qiskit-aer icon indicating copy to clipboard operation
qiskit-aer copied to clipboard

cuStateVec_enable=True not working

Open Gopal-Dahale opened this issue 1 year ago • 3 comments

Informations

  • Qiskit Aer version: 0.11.0 (qiskit-aer-gpu)
  • Python version: 3.7.14
  • Operating system: Linux

What is the current behavior?

Passing cuStateVec_enable=True as a parameter to AerSimulator and executing the simulation results into the following error.

WARNING:qiskit_aer.backends.aerbackend:Simulation failed and returned the following error message:
ERROR: Failed to load qobj: Simulation device "GPU" does not supported cuStateVec on this system

Steps to reproduce the problem

On Google Colab:

  1. Install cuQuantum from the steps mentioned in the documentation
  2. Set environment variables
import os
os.environ['CUQUANTUM_ROOT']='/usr/local/cuquantum'
os.environ['CUQUANTUM_DIR']='/usr/local/cuquantum'
os.environ['LD_LIBRARY_PATH']=f"/usr/local/cuquantum/lib:{os.environ['LD_LIBRARY_PATH']}"
os.environ['PATH']=f"/usr/local/cuquantum/lib:{os.environ['PATH']}"
  1. Run the code example and ensure the output is example PASSED.
  2. Execute the following program
from qiskit import *
from qiskit.circuit.library import *
from qiskit.providers.aer import *

sim = AerSimulator(method='statevector', device='GPU', cuStateVec_enable=True)

qubits = 15
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)

What is the expected behavior?

Program should execute without any errors and should give the following output (as per Qiskit's medium post)

cuStateVector is used for the simulation
15 qubits, Time = 0.007037462 sec
{'011010000111101': 1, '100101001000001': 1, '101100010110011': 1, '011110101110001': 1, '000001110000100': 1, '001101110000100': 1, '101100010101010': 1, '010111001000001': 1, '100100010100111': 1, '001101110011000': 1}

Suggested solutions

Gopal-Dahale avatar Oct 01 '22 15:10 Gopal-Dahale

We are sorry but there is no binary distribution supporting cuQuantum APIs. qiskit-aer-gpu does not support cuStateVec_enable option.

To enable cuQuantum on Qiskit Aer, please build from the source code by referring to the following document. https://github.com/Qiskit/qiskit-aer/blob/main/CONTRIBUTING.md#building-with-gpu-support

doichanj avatar Oct 04 '22 00:10 doichanj

Hi @doichanj, thanks you for the link. I followed the steps but got an error

10 errors detected in the compilation of "/content/qiskit-aer/qiskit_aer/backends/wrappers/bindings.cc".
qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/build.make:75: recipe for target 'qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/bindings.cc.o' failed
make[2]: *** [qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/bindings.cc.o] Error 1
CMakeFiles/Makefile2:873: recipe for target 'qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/all' failed
make[1]: *** [qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/skbuild/setuptools_wrap.py", line 645, in setup
    cmkr.make(make_args, install_target=cmake_install_target, env=env)
  File "/usr/local/lib/python3.7/dist-packages/skbuild/cmaker.py", line 680, in make
    self.make_impl(clargs=clargs, config=config, source_dir=source_dir, install_target=install_target, env=env)
  File "/usr/local/lib/python3.7/dist-packages/skbuild/cmaker.py", line 719, in make_impl
    os.path.abspath(CMAKE_BUILD_DIR()),

An error occurred while building with CMake.
  Command:
    /usr/local/lib/python3.7/dist-packages/cmake/data/bin/cmake --build . --target install --config Release --
  Install target:
    install
  Source directory:
    /content/qiskit-aer
  Working directory:
    /content/qiskit-aer/_skbuild/linux-x86_64-3.7/cmake-build
Please check the install target is valid and see CMake's output for more information.

I am using the following command (cuquantum files are moved to /usr/loca/cuquantum).

python ./setup.py bdist_wheel -- -DAER_THRUST_BACKEND=CUDA -DCUSTATEVEC_ROOT=/usr/local/cuquantum

Here is the link of Google Colab code for more details.

Gopal-Dahale avatar Oct 05 '22 07:10 Gopal-Dahale

CMake logs its errors. @Gopal-Dahale what are the 10 errors?

jwoehr avatar Oct 12 '22 03:10 jwoehr

Okay, I was able to build it successfully, but the code snippet is not working and gives the following error

 No module named 'qiskit.providers.aer'

Gopal-Dahale avatar Oct 21 '22 10:10 Gopal-Dahale

could you try uninstall older Qiskit Aer and install built one pip uninstall qiskit-aer-gpu pip uninstall qiskit-aer pip install -U dist/*

doichanj avatar Oct 24 '22 04:10 doichanj

@doichanj thanks, it worked. I performed the benchmarking with thrust and custatevec with 1000 shots and found this strange peak with a single qubit. Any explanation for this? test

Gopal-Dahale avatar Oct 27 '22 16:10 Gopal-Dahale

I think there is relatively large overhead for small number of qubits, so the simulation time will be unstable.

doichanj avatar Nov 01 '22 07:11 doichanj

I think the issue was solved, I close this one.

doichanj avatar Nov 01 '22 07:11 doichanj

Hi everyone, I am running this on AWS server with a Tesla V100 and I am stuck while building, I ran the following command: python ./setup.py bdist_wheel -- -DAER_THRUST_BACKEND=CUDA -DCUSTATEVEC_ROOT=/local/ubuntu/cuquantum-archive

/local/ubuntu/cuquantum-archive is where the cuQuantum file exists. Its the same error as "please check the install target".

I can't figure out how to successfully build this, can somebody please help?

ramona1313 avatar Nov 01 '22 17:11 ramona1313