Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qiskit-aer-gpu throws an error when using AerSimulator(method='tensor_network', device='GPU') #2176

Closed
anonymouspanda-23 opened this issue Jun 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@anonymouspanda-23
Copy link

Informations

  • Qiskit Aer version: 0.15.0
  • Python version: 3.11
  • Operating system: Windows 11

What is the current behavior?

When building qiskit-aer with CUDA support from source, I expected the following code to work.

import matplotlib.pyplot as plt

from qiskit import QuantumCircuit, transpile
from qiskit.visualization import plot_histogram
from qiskit_aer import AerError, AerSimulator

print(AerSimulator().available_devices())
print(AerSimulator().available_methods())

# Initialize a GPU backend
# Note that the cloud instance for tutorials does not have a GPU
# so this will raise an exception.
try:
    # Create circuit
    circ = QuantumCircuit(2)
    circ.h(0)
    circ.cx(0, 1)
    circ.measure_all()

    simulator_gpu = AerSimulator()
    simulator_gpu.set_options(device="GPU", method="tensor_network")

    circ = transpile(circ, simulator_gpu)

    # Run and get counts
    result = simulator_gpu.run(circ).result()
    print(result)
    counts = result.get_counts(circ)
    plot_histogram(counts, title='Bell-State counts')
    plt.show()

except AerError as e:
    print(e)

However, it produced the following error

(qiskit-aer-gpu) C:\PycharmProjects\VQC>python gpu_test.py
('CPU', 'GPU')
('automatic', 'statevector', 'density_matrix', 'stabilizer', 'matrix_product_state', 'extended_stabilizer', 'unitary', 'superop', 'tensor_network')
Traceback (most recent call last):
  File "C:\PycharmProjects\VQC\gpu_test.py", line 26, in <module>
    result = simulator_gpu.run(circ).result()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\site-packages\qiskit_aer\jobs\utils.py", line 42, in _wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\site-packages\qiskit_aer\jobs\aerjob.py", line 114, in result
    return self._future.result(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\concurrent\futures\_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\site-packages\qiskit_aer\backends\aerbackend.py", line 475, in _execute_circuits_job
    output = self._execute_circuits(aer_circuits, noise_model, config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\site-packages\qiskit_aer\backends\aer_simulator.py", line 923, in _execute_circuits
    ret = cpp_execute_circuits(self._controller, aer_circuits, noise_model, config)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\anaconda3\envs\qiskit-aer-gpu\Lib\site-packages\qiskit_aer\backends\backend_utils.py", line 450, in cpp_execute_circuits
    return controller.execute(aer_circuits, noise_model, config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Invalid combination of simulation method and device, "tensor_network" only supports "device=GPU"

Steps to reproduce the problem

  1. Install CUDA Toolkit from here with the following options:

    • Operating System: Windows
    • Architecture: x86_64
    • Version: 11
    • Installer Type: exe (local)
  2. Install Visual Studio 2019 with the "Desktop development with C++" workload using the default options.

  3. Run git clone https://github.com/Qiskit/qiskit-aer.git in any non-root directory, then run cd qiskit-aer.

  4. Replace the following code in the "aer_controller_binding.hpp" file (located at the "qiskit_aer/backends/wrappers" sub-directory):

template <typename T>
void read_value(const py::tuple &t, size_t index, optional<T> &v) {
  if (t[index].cast<py::tuple>()[0].cast<bool>())
    v.value(t[index].cast<py::tuple>()[1].cast<T>());
}

template <typename T>
void read_value(const py::tuple &t, size_t index, T &v) {
  v = t[index].cast<T>();
}

with this code:

template <typename T>
void read_value(const py::tuple &t, size_t index, optional<T> &v) {
  if (py::bool_(t[index].cast<py::tuple>()[0]))
    v.value(py::cast<T>(py::class_<T>(t[index].cast<py::tuple>()[1])));
}

template <typename T>
void read_value(const py::tuple &t, size_t index, T &v) {
  v = py::cast<T>(t[index]);
}
  1. Run pip3 install build
  2. Run pip3 install -r requirements-dev.txt
  3. Run python ./setup.py bdist_wheel -- -DAER_THRUST_BACKEND=CUDA -DCMAKE_CXX_COMPILER=c++17 --
  4. Delete the "qiskit_aer" sub-directory.
  5. Run pip install -U -c constraints.txt -r requirements-dev.txt dist/*.whl, replacing "*" with the actual file name.

What is the expected behavior?

The original code provided at the top of this issue should run and provide me with the Bell-state counts.

Suggested solutions

Unfortunately, I have not found a possible workaround yet. I will add a comment under this issue if a workaround is found.

@anonymouspanda-23 anonymouspanda-23 added the bug Something isn't working label Jun 15, 2024
@doichanj
Copy link
Collaborator

To use tensor_network method, Aer should be built with cuQuantum, but cuQuantum does not support Windows. Please run Aer on Linux if you want to use tensor_network method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants