Qiskit / qiskit-aer

Aer is a high performance simulator for quantum circuits that includes noise models
https://qiskit.github.io/qiskit-aer/
Apache License 2.0
471 stars 353 forks source link

[qiskit-aer-gpu] Cannot execute parallel processes with mpirun #2025

Closed intelligi123 closed 6 months ago

intelligi123 commented 6 months ago

Informations

What is the current behavior?

I have installed qiskit-aer-gpu and MPI4PY using pip3 in order to run qiskit code on multiple nodes. My code is currently running on two nodes but independently. Below is the code I am running:

from qiskit import *
from qiskit.circuit.library import *
from qiskit.providers.aer import *
sim = AerSimulator(method='statevector', device='GPU', cuStateVec_enable=True, blocking_enable=True, blocking_qubits=10)
shots = 100
depth=10
qubits =  25
circuit = transpile(QuantumVolume(qubits, depth, seed=0),
backend=sim,
optimization_level=0)
circuit.measure_all()
result = execute(circuit,sim,shots=shots,seed_simulator=12345, blocking_enable=True, blocking_qubits=10).result()
dict=result.to_dict()
meta = dict['metadata']
myrank = meta['mpi_rank']
data = dict['results'][0]['data']['counts']
#print (myrank)
if (myrank==0):
   print(meta)

And the command is: mpirun -np 3 -machinefile machinefile.txt python3 demo.py

I am getting following output as result:


{'time_taken_execute': 22.230309361, 'mpi_rank': 0, 'num_mpi_processes': 1, 'max_gpu_memory_mb': 5933, 'max_memory_mb': 15903, 'parallel_experiments': 1, 'num_processes_per_experiments': 1, 'omp_enabled': True}
{'time_taken_execute': 180.515637528, 'mpi_rank': 0, 'num_mpi_processes': 1, 'max_gpu_memory_mb': 5933, 'max_memory_mb': 15903, 'parallel_experiments': 1, 'num_processes_per_experiments': 1, 'omp_enabled': True}
{'time_taken_execute': 180.538947709, 'mpi_rank': 0, 'num_mpi_processes': 1, 'max_gpu_memory_mb': 5933, 'max_memory_mb': 15903, 'parallel_experiments': 1, 'num_processes_per_experiments': 1, 'omp_enabled': True}

All processes have rank=0 and num_mpi_processes=1. My goal is to share GPU resources of two nodes in order to run computation.

Steps to reproduce the problem

Installation of MPI4PY and qiskit-aer-gpu

What is the expected behavior?

My expectation is that output should show num_mpi_processes=3 (for this particular command) and mpi_rank should be assigned according to process number and computation share the resources (CPU+GPU) of both nodes.

Suggested solutions

I cannot suggest any solution but I am concerned about installation of qiskit-aer-gpu? Is it come with support for MPI and GPU itself when installed it with pip3 or I have to build it separately with particular flags as mentioned in CONTIBUTING.md installation instructions

doichanj commented 6 months ago

pip install qiskit-aer-gpu does not support MPI parallelization, but Aer should be built from source to add support for MPI parallel execution.

intelligi123 commented 6 months ago

Thank you, Is there any link to guide for its build with all per-requisites?

doichanj commented 6 months ago

Please refer to https://github.com/Qiskit/qiskit-aer/blob/main/CONTRIBUTING.md#building-with-mpi-support

intelligi123 commented 6 months ago

Thank you, I started that but I am getting Error at the very last step while building Command I am running: python3 ./setup.py bdist_wheel -- -DAER_THRUST_BACKEND=CUDA -DAER_MPI=True

Error is:

/home/dell/.local/lib/python3.11/site-packages/pybind11/include/pybind11/detail/../cast.h: In function ‘typename pybind11::detail::type_caster<typename pybind11::detail::intrinsic_type<T>::type>::cast_op_type<T> pybind11::detail::cast_op(make_caster<T>&)’:
/home/dell/.local/lib/python3.11/site-packages/pybind11/include/pybind11/detail/../cast.h:45:120: error: expected template-name before ‘<’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                        ^
/home/dell/.local/lib/python3.11/site-packages/pybind11/include/pybind11/detail/../cast.h:45:120: error: expected identifier before ‘<’ token
/home/dell/.local/lib/python3.11/site-packages/pybind11/include/pybind11/detail/../cast.h:45:123: error: expected primary-expression before ‘>’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                           ^
/home/dell/.local/lib/python3.11/site-packages/pybind11/include/pybind11/detail/../cast.h:45:126: error: expected primary-expression before ‘)’ token
   45 |     return caster.operator typename make_caster<T>::template cast_op_type<T>();
      |                                                                                                                              ^
gmake[2]: *** [qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/build.make:77: qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/bindings.cc.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:854: qiskit_aer/backends/wrappers/CMakeFiles/controller_wrappers.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
Traceback (most recent call last):
  File "/home/dell/.local/lib/python3.11/site-packages/skbuild/setuptools_wrap.py", line 674, in setup
    cmkr.make(make_args, install_target=cmake_install_target, env=env)
  File "/home/dell/.local/lib/python3.11/site-packages/skbuild/cmaker.py", line 697, in make
    self.make_impl(clargs=clargs, config=config, source_dir=source_dir, install_target=install_target, env=env)
  File "/home/dell/.local/lib/python3.11/site-packages/skbuild/cmaker.py", line 742, in make_impl
    raise SKBuildError(msg)

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

Should I need to install any particular version of pybind11?

doichanj commented 6 months ago

Yes pybind11 is required to be installed on the system