Lightning-Qubit installation¶
Lightning-Qubit comes pre-installed with PennyLane. Please follow our installation instructions to install PennyLane.
Install from source¶
Note
The below contains instructions for installing Lightning-Qubit *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 build Lightning plugins from source you can run
PL_BACKEND=${PL_BACKEND} pip install pybind11 pennylane-lightning --no-binary :all:
where ${PL_BACKEND}
can be lightning_qubit
(default), lightning_gpu
, lightning_kokkos
, or lightning_tensor
.
The pybind11 library is required to bind the C++ functionality to Python.
A C++ compiler such as g++
, clang++
, or MSVC
is required.
On Debian-based systems, this can be installed via apt
:
sudo apt -y update && sudo apt install -y g++ libomp-dev
where libomp-dev
is included to also install OpenMP.
On MacOS, we recommend using the latest version of clang++
and libomp
:
brew install llvm libomp
The Lightning-GPU backend has several dependencies (e.g. CUDA
, custatevec-cu12
, etc.), and hence we recommend referring to Lightning-GPU installation section.
Similarly, for Lightning-Kokkos it is recommended to configure and install Kokkos independently as prescribed in the Lightning-Kokkos installation section.
Development installation¶
For development and testing, you can install by cloning the repository:
git clone https://github.com/PennyLaneAI/pennylane-lightning.git
cd pennylane-lightning
pip install -r requirements.txt
PL_BACKEND=${PL_BACKEND} python scripts/configure_pyproject_toml.py
pip install -e . --config-settings editable_mode=compat -vv
Note that subsequent calls to pip install -e .
will use cached binaries stored in the
build
folder, and the pyproject.toml
file defined by the configuration script. Run make clean
if you would like to recompile from scratch.
You can also pass cmake
options with CMAKE_ARGS
as follows:
CMAKE_ARGS="-DENABLE_OPENMP=OFF -DENABLE_BLAS=OFF" pip install -e . --config-settings editable_mode=compat -vv
Supported options are -DENABLE_WARNINGS
, -DENABLE_NATIVE
(for -march=native
) -DENABLE_BLAS
, -DENABLE_OPENMP
, and -DENABLE_CLANG_TIDY
.
Compile MSVC (Windows)¶
Lightning-Qubit can be compiled on Windows using the Microsoft Visual C++ compiler. You need cmake and appropriate Python environment (e.g. using Anaconda).
We recommend using [x64 (or x86)] Native Tools Command Prompt for VS [version]
to compile the library.
Be sure that cmake
and python
can be called within the prompt.
cmake --version
python --version
Then a common command will work.
pip install -r requirements.txt
pip install -e .
Note that OpenMP and BLAS are disabled on this platform.
Testing¶
To test that a plugin is working correctly, one can check both Python and C++ unit tests for each device.
Python Test¶
Test the Python code with:
make test-python device=${PL.DEVICE}
where ${PL.DEVICE}
differ from ${PL_BACKEND}
by replacing the underscore by a dot. And can be
lightning.qubit
(default)lightning.gpu
lightning.kokkos
lightning.tensor