Lightning-GPU installation¶
Lightning-GPU can be installed using pip
:
pip install pennylane-lightning[gpu]
Lightning-GPU requires CUDA 12 and the cuQuantum SDK (only the cuStateVec library is required).
The SDK may be installed within the Python environment site-packages
directory using pip
or conda
or the SDK library path appended to the LD_LIBRARY_PATH
environment variable.
Please see the cuQuantum SDK install guide for more information.
Install Lightning-GPU from source¶
To install Lightning-GPU from the package sources using the direct SDK path, Lightning-Qubit should be install before Lightning-GPU:
git clone https://github.com/PennyLaneAI/pennylane-lightning.git
cd pennylane-lightning
pip install -r requirements.txt
PL_BACKEND="lightning_qubit" pip install -e . -vv
Then the cuStateVec library can be installed and set a CUQUANTUM_SDK
environment variable.
python -m pip install wheel custatevec-cu12
export CUQUANTUM_SDK=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum/lib')")
The Lightning-GPU can then be installed with pip
:
PL_BACKEND="lightning_gpu" python -m pip install -e .
To simplify the build, we recommend using the containerized build process described in Docker support section.
Install Lightning-GPU with MPI¶
Building Lightning-GPU with MPI also requires the NVIDIA cuQuantum SDK
(currently supported version: custatevec-cu12), mpi4py
and CUDA-aware MPI
(Message Passing Interface).
CUDA-aware MPI
allows data exchange between GPU memory spaces of different nodes without the need for CPU-mediated transfers.
Both the MPICH
and OpenMPI
libraries are supported, provided they are compiled with CUDA support.
The path to libmpi.so
should be found in LD_LIBRARY_PATH
.
It is recommended to install the NVIDIA cuQuantum SDK
and mpi4py
Python package within pip
or conda
inside a virtual environment.
Please consult the cuQuantum SDK , mpi4py,
MPICH, or OpenMPI install guide for more information.
Before installing Lightning-GPU with MPI support using the direct SDK path, please ensure Lightning-Qubit, CUDA-aware MPI
and custatevec
are installed and the environment variable CUQUANTUM_SDK
is set properly.
Then Lightning-GPU with MPI support can then be installed with pip
:
CMAKE_ARGS="-DENABLE_MPI=ON" PL_BACKEND="lightning_gpu" python -m pip install -e .
Test Lightning-GPU with MPI¶
You may test the Python layer of the MPI enabled plugin as follows:
mpirun -np 2 python -m pytest mpitests --tb=short
The C++ code is tested with
rm -rf ./BuildTests
cmake . -BBuildTests -DBUILD_TESTS=1 -DBUILD_TESTS=1 -DENABLE_MPI=ON -DCUQUANTUM_SDK=<path to sdk>
cmake --build ./BuildTests --verbose
cd ./BuildTests
for file in *runner_mpi ; do mpirun -np 2 ./BuildTests/$file ; done;