Lightning-Qubit installation¶
PyPI wheels (pip)¶
Lightning plugins can be installed using pip
as follows
$ pip install pennylane-lightning
The above command will install the Lightning-Qubit plugin (the default since it is most broadly supported). In order to install the Lightning-GPU and Lightning-Kokkos (OpenMP) backends, you can respectively use the following commands:
$ pip install pennylane-lightning[gpu]
$ pip install pennylane-lightning[kokkos]
Install from source¶
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
or lightning_kokkos
.
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 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} pip install -e . -vv
Note that subsequent calls to pip install -e .
will use cached binaries stored in the
build
folder. 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 . -vv
or with build_ext
and the --define
flag as follows:
$ python3 setup.py build_ext -i --define="ENABLE_OPENMP=OFF;ENABLE_BLAS=OFF"
$ python3 setup.py develop
where -D
must not be included before ;
-separated options.
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.
CMake support¶
One can also build the plugin using CMake:
$ cmake -S. -B build
$ cmake --build build
Supported options are
-DENABLE_WARNINGS:BOOL=ON
-DENABLE_NATIVE:BOOL=ON
(for-march=native
)-DENABLE_BLAS:BOOL=ON
-DENABLE_OPENMP:BOOL=ON
-DENABLE_CLANG_TIDY:BOOL=ON
Testing¶
To test that a plugin is working correctly, test the Python code with:
$ make test-python device=${PL_DEVICE}
where ${PL_DEVICE}
can be lightning.qubit
(default), lightning.gpu
or lightning.kokkos
.
These differ from ${PL_BACKEND}
by replacing the underscore by a dot.
The C++ code can be tested with
$ PL_BACKEND=${PL_BACKEND} make test-cpp