Lightning-Kokkos installation

On most Linux systems, Lightning-Kokkos can be installed via Spack or Docker by following our installation instructions at pennylane.ai/install.

Install Lightning-Kokkos from source

Note

The below contains instructions for installing Lightning-Kokkos *from source*. For most cases, one can install Lightning-Kokkos via Spack or Docker by 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.

As Kokkos enables support for many different HPC-targeted hardware platforms, lightning.kokkos can be built to support any of these platforms when building from source.

Install Kokkos (Optional)

We suggest first installing Kokkos with the wanted configuration following the instructions found in the Kokkos documentation. For example, the following will build Kokkos for NVIDIA A100 cards

Download the Kokkos code. Lightning Kokkos was tested with Kokkos version <= 4.3.01

# Replace x, y, and z by the correct version
wget https://github.com/kokkos/kokkos/archive/refs/tags/4.x.yz.tar.gz
tar -xvf 4.x.y.z.tar.gz
cd kokkos-4.x.y.z

Build Kokkos for NVIDIA A100 cards (SM80 architecture)

cmake -S . -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=RelWithDebugInfo \
    -DCMAKE_INSTALL_PREFIX=/opt/kokkos/4.x.y.z/AMPERE80 \
    -DCMAKE_CXX_STANDARD=20 \
    -DBUILD_SHARED_LIBS:BOOL=ON \
    -DBUILD_TESTING:BOOL=OFF \
    -DKokkos_ENABLE_SERIAL:BOOL=ON \
    -DKokkos_ENABLE_CUDA:BOOL=ON \
    -DKokkos_ARCH_AMPERE80:BOOL=ON \
    -DKokkos_ENABLE_EXAMPLES:BOOL=OFF \
    -DKokkos_ENABLE_TESTS:BOOL=OFF \
    -DKokkos_ENABLE_LIBDL:BOOL=OFF
cmake --build build && cmake --install build
export CMAKE_PREFIX_PATH=/opt/kokkos/4.x.y.z/AMPERE80:$CMAKE_PREFIX_PATH

Next, append the install location to CMAKE_PREFIX_PATH. Note that the C++20 standard is required (-DCMAKE_CXX_STANDARD=20 option), and hence CUDA v12 is required for the CUDA backend.

Install Lightning-Kokkos

If an installation of Kokkos is not found, then our builder will clone and install it during the build process. Lightning-Qubit should be installed (compilation is not necessary):

The simplest way to install Lightning-Kokkos (OpenMP backend) through pip.

git clone https://github.com/PennyLaneAI/pennylane-lightning.git
cd pennylane-lightning
PL_BACKEND="lightning_qubit" python scripts/configure_pyproject_toml.py
SKIP_COMPILATION=True pip install -e . --config-settings editable_mode=compat
PL_BACKEND="lightning_kokkos" python scripts/configure_pyproject_toml.py
CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" python -m pip install -e . --config-settings editable_mode=compat -vv

The supported backend options are

SERIAL

OPENMP

THREADS

HIP

CUDA

and the corresponding build options are -DKokkos_ENABLE_XXX=ON, where XXX needs be replaced by the backend name, for instance OPENMP.

One can activate simultaneously one serial, one parallel CPU host (e.g. OPENMP, THREADS) and one parallel GPU device backend (e.g. HIP, CUDA), but not two of any category at the same time. For HIP and CUDA, the appropriate software stacks are required to enable compilation and subsequent use. Similarly, the CMake option -DKokkos_ARCH_{...}=ON must also be specified to target a given architecture. A list of the architectures is found on the Kokkos wiki. Note that THREADS backend is not recommended since Kokkos does not guarantee its safety.