Lightning-GPU installation¶
For the majority of cases, Lightning-GPU can be installed by following our installation instructions at pennylane.ai/install.
Install Lightning-GPU from source¶
Note
The below contains instructions for installing Lightning-GPU *from source*. For most cases, this is not required and one can simply use the installation instructions at pennylane.ai/install. If those instructions do not work for you, or you have a more complex build environment that requires building from source, then consider reading on.
To install Lightning-GPU from the package sources using the direct SDK path, Lightning-Qubit should be install before Lightning-GPU (compilation is not necessary):
git clone https://github.com/PennyLaneAI/pennylane-lightning.git
cd pennylane-lightning
pip install -r requirements.txt
pip install custatevec-cu12
PL_BACKEND="lightning_qubit" python scripts/configure_pyproject_toml.py
SKIP_COMPILATION=True pip install -e . --config-settings editable_mode=compat -vv
Then a CUQUANTUM_SDK
environment variable can be set:
export CUQUANTUM_SDK=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum')")
The Lightning-GPU can then be installed with pip
:
PL_BACKEND="lightning_gpu" python scripts/configure_pyproject_toml.py
python -m pip install -e . --config-settings editable_mode=compat -vv
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 in the editable mode:
PL_BACKEND="lightning_gpu" python scripts/configure_pyproject_toml.py
CMAKE_ARGS="-DENABLE_MPI=ON" python -m pip install -e . --config-settings editable_mode=compat -vv
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;