The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++.
PennyLane is a cross-platform Python library for quantum machine learning, automatic differentiation, and optimization of hybrid quantum-classical computations.
Combine PennyLane-Lightning's high-performance simulators with PennyLane's automatic differentiation and optimization.
PennyLane-Lightning requires Python version 3.9 and above. It can be installed using pip
:
pip install pennylane-lightning
To build PennyLane-Lightning from source you can run
pip install pybind11 pennylane-lightning --no-binary :all:
A C++ compiler such as g++
, clang++
, or MSVC
is required.
On Debian-based systems, this can be installed via apt
:
sudo apt install g++
On MacOS, we recommend using the latest version of clang++
and libomp
:
brew install llvm libomp
The pybind11 library is also used for binding the C++ functionality to Python.
Alternatively, 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-dev.txt
pip install -e .
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.
You can also pass cmake
options with CMAKE_ARGS
as follows:
CMAKE_ARGS="-DENABLE_OPENMP=OFF -DENABLE_BLAS=OFF -DENABLE_KOKKOS=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;ENABLE_KOKKOS=OFF"
python3 setup.py develop
For GPU support, PennyLane-Lightning-GPU
can be installed by providing the optional [gpu]
tag:
$ pip install pennylane-lightning[gpu]
For more information, please refer to the PennyLane Lightning GPU documentation.
To test that the plugin is working correctly you can test the Python code within the cloned repository:
make test-python
while the C++ code can be tested with
make test-cpp
One can also build the plugin using CMake:
cmake -S. -B build
cmake --build build
To test the C++ code:
mkdir build && cd build
cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..
make
Other supported options are
-DENABLE_WARNINGS=ON
-DENABLE_NATIVE=ON
(for-march=native
)-DENABLE_BLAS=ON
-DENABLE_OPENMP=ON
-DENABLE_KOKKOS=ON
-DENABLE_CLANG_TIDY=ON
You can also compile Pennylane-Lightning on Windows using Microsoft Visual C++ compiler. You need cmake and appropriate Python environment (e.g. using Anaconda).
We recommend to use [x64 (or x86)] Native Tools Command Prompt for VS [version]
for compiling 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-dev.txt
pip install -e .
Note that OpenMP and BLAS are disabled in this setting.
Please refer to the plugin documentation as well as to the PennyLane documentation for further reference.
One can also build the Pennylane-Lightning image using Docker:
git clone https://github.com/PennyLaneAI/pennylane-lightning.git
cd pennylane-lightning
docker build -t lightning/base -f docker/Dockerfile .
Please refer to the PennyLane installation for detailed description about PennyLane Docker support.
We welcome contributions - simply fork the repository of this plugin, and then make a pull request containing your contribution. All contributors to this plugin will be listed as authors on the releases.
We also encourage bug reports, suggestions for new features and enhancements, and even links to cool projects or applications built on PennyLane.
If you contribute to the Python code, please mind the following.
The Python code is formatted with the PEP 8 compliant opinionated formatter Black (black==23.7.0
).
We set a line width of a 100 characters.
The Python code is statically analyzed with Pylint.
We set up a pre-commit hook (see Git hooks) to run both of these on git commit
.
Please make your best effort to comply with black
and pylint
before using disabling pragmas (e.g. # pylint: disable=missing-function-docstring
).
PennyLane-Lightning is the work of many contributors.
If you are doing research using PennyLane and PennyLane-Lightning, please cite our paper:
Ville Bergholm et al. PennyLane: Automatic differentiation of hybrid quantum-classical computations. 2018. arXiv:1811.04968
- Source Code: https://github.com/PennyLaneAI/pennylane-lightning
- Issue Tracker: https://github.com/PennyLaneAI/pennylane-lightning/issues
- PennyLane Forum: https://discuss.pennylane.ai
If you are having issues, please let us know by posting the issue on our Github issue tracker, or by asking a question in the forum.
The PennyLane lightning plugin is free and open source, released under the Apache License, Version 2.0.
PennyLane Lightning makes use of the following libraries and tools, which are under their own respective licenses:
- pybind11: https://github.com/pybind/pybind11
- Kokkos Core: https://github.com/kokkos/kokkos