PennyLane-Lightning plugin
Project description
The Lightning plugin ecosystem provides fast state-vector simulators written in C++.
PennyLane is a cross-platform Python library for quantum machine learning, automatic differentiation, and optimization of hybrid quantum-classical computations. PennyLane supports Python 3.9 and above.
Features
Combine Lightning’s high performance simulators with PennyLane’s automatic differentiation and optimization.
Lightning Qubit installation
Lightning Qubit can be installed using pip:
$ pip install pennylane-lightning
To build 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.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
Testing
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
CMake Support
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
Compile on Windows with MSVC
You can also compile 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.txt
$ pip install -e .
Note that OpenMP and BLAS are disabled in this setting.
Lightning Kokkos installation
We suggest first installing Kokkos with the wanted configuration following the instructions found in the Kokkos documentation. Next, append the install location to CMAKE_PREFIX_PATH. If an installation is not found, our builder will install it from scratch nevertheless.
The simplest way to install PennyLane-Lightning-Kokkos (OpenMP backend) is using pip.
CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" PL_BACKEND="lightning_kokkos" python -m pip install .
or for an editable pip installation with:
CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" PL_BACKEND="lightning_kokkos" python -m pip install -e .
Alternatively, you can install the Python interface with:
CMAKE_ARGS="-DKokkos_ENABLE_OPENMP=ON" PL_BACKEND="lightning_kokkos" python setup.py build_ext
python setup.py bdist_wheel
pip install ./dist/PennyLane*.whl --force-reinstall
To build the plugin directly with CMake:
cmake -B build -DKokkos_ENABLE_OPENMP=ON -DPLKOKKOS_BUILD_TESTS=ON -DPL_BACKEND=lightning_kokkos -G Ninja
cmake --build build
Supported backend options are “SERIAL”, “OPENMP”, “THREADS”, “HIP” and “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.
Testing
To test with the ROCm stack using a manylinux2014 container we must first mount the repository into the container:
docker run -v `pwd`:/io -it quay.io/pypa/manylinux2014_x86_64 bash
Next, within the container, we install the ROCm software stack:
yum install -y https://repo.radeon.com/amdgpu-install/21.40.2/rhel/7.9/amdgpu-install-21.40.2.40502-1.el7.noarch.rpm
amdgpu-install --usecase=hiplibsdk,rocm --no-dkms
We next build the test suite, with a given AMD GPU target in mind, as listed here.
cd /io
export PATH=$PATH:/opt/rocm/bin/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib
export CXX=/opt/rocm/hip/bin/hipcc
cmake -B build -DCMAKE_CXX_COMPILER=/opt/rocm/hip/bin/hipcc -DKokkos_ENABLE_HIP=ON -DPLKOKKOS_BUILD_TESTS=ON -DKokkos_ARCH_VEGA90A=ON
cmake --build build --verbose
We may now leave the container, and run the built test suite on a machine with access to the targeted GPU.
For a system with access to the ROCm stack outside of a manylinux container, an editable pip installation can be built and installed as:
CMAKE_ARGS="-DKokkos_ENABLE_HIP=ON -DKokkos_ARCH_VEGA90A=ON" PL_BACKEND="lightning_kokkos" python -m pip install -e .
Please refer to the plugin documentation as well as to the PennyLane documentation for further reference.
GPU support
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.
Docker Support
One can also build the 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.
Contributing
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.
Black & Pylint
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).
Support
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.
License
The PennyLane lightning plugin is free and open source, released under the Apache License, Version 2.0.
Acknowledgements
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for PennyLane_Lightning-0.32.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc7e2e3432cf45ff739d8b0651263975c45a25ef78118d5fe1d5cd64155bc279 |
|
MD5 | aa54e7574e86e81ed3d615bcddbca5f9 |
|
BLAKE2b-256 | 99a1cda69a7bfad3733ed043e5378c1c7aaf2a5aa565151fe77f2f42255d1232 |
Hashes for PennyLane_Lightning-0.32.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ac239d8998808a06bf9d0adbe99e76564ba5c62758654da27fa7b5ce44a7480 |
|
MD5 | f19504e9123a3fc0c4091f120f17355f |
|
BLAKE2b-256 | 77248fab61e0a7719da8df794518d9f903147a5af6ba36f6ad344a6e238a0024 |
Hashes for PennyLane_Lightning-0.32.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9da6715c4f9b0826084825ee4711fb99a337b7b9e5b41fc2a1d4f6226782f32 |
|
MD5 | bbf3c375ab31a7a635961cf49877ef2c |
|
BLAKE2b-256 | e105dc2d60a54c92061d401d3fb99b7752cda25167ce96b8967441bfd02b0a34 |
Hashes for PennyLane_Lightning-0.32.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83256d9895b519b82715ea70453a1ca6492400f5a7d21eae2941463c63dc8973 |
|
MD5 | eadbd3952b9e185d2d7ad2ee7c7cf2c2 |
|
BLAKE2b-256 | d74d50827a5945eeee63997ca6dd453077e2ebb5b26e974a7d0357de9fe5a10f |
Hashes for PennyLane_Lightning-0.32.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 779b2766f70e44f5d11c3eb0fc675c9107fdcb452c1de6cb744c1e8d6b4fcb19 |
|
MD5 | 6b0cc7e8ef1851e2515f0437dd399598 |
|
BLAKE2b-256 | 8f74a2fe3a69e6d219336510fb53a7e4b255dda4b85d233655c74af1b54e849e |
Hashes for PennyLane_Lightning-0.32.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22717a8325371b2c031230dc9f4be22c9a7140f05b768297d737ce8b5a066e4e |
|
MD5 | 9ea6e4d5baa43f7ae97c17a5f471838a |
|
BLAKE2b-256 | a3f2fc98af8d0bd35207918ba8085ae7054ab1d77c9b7c2fa6e5beb1cbac50de |
Hashes for PennyLane_Lightning-0.32.0-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a0846ca49d8b82c42d258683b09452651a9f57bf81106a3ac2e92eb65130779 |
|
MD5 | 662ac533b5790d24085d8d295abbb278 |
|
BLAKE2b-256 | f13bff445c004b432afcd3712fc10ba883d4c5225210a905244e20f482c6b4d9 |
Hashes for PennyLane_Lightning-0.32.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7397081deb00c53d632e46f07df70280d2fc9925c1c7605e84d832fd6ce9a1a3 |
|
MD5 | ba3fbab67ed134af63d9e743f668f2ee |
|
BLAKE2b-256 | d795c0ede5787ebaf31062f8ba3d6b0abce57c25e3a088fc8873d5932d69ad63 |
Hashes for PennyLane_Lightning-0.32.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98cf43ea10245fe739fce7b00dae99edce6ca3fadc1348d5d01783189427c13f |
|
MD5 | 1ae9e805fc20351a60eff18fcba79fec |
|
BLAKE2b-256 | e36cf35e27846f5efb6a42bb0fb9f40f2e6025681392370e3ca89976217b47e5 |
Hashes for PennyLane_Lightning-0.32.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5e166f869d293be616c2aa4e86b66c58e68607ec805f2b45004cae6e5d7c5fa |
|
MD5 | 2b2bc67baa532064138b881b8b309eb0 |
|
BLAKE2b-256 | 92aca4b8bfb3468b12e6e5bf2637af26f814fd09ae72c933d27ec07a72e4d973 |
Hashes for PennyLane_Lightning-0.32.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 835c9effeb44cb2dfc491a56fbdb8a8d8c119226a2a9a25ebd78dca56765bc95 |
|
MD5 | afe91d7cd2f7432d71e6478aee5eec8b |
|
BLAKE2b-256 | ff9105da2277c146aca98edea55f2c3a212aa9351706431cd66ebe558962cd97 |
Hashes for PennyLane_Lightning-0.32.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 481647245cf97ba242ed4b99a06f07a525173a2f024bb007709815f19e8d908f |
|
MD5 | b793e5d612ba997d73c27499df049256 |
|
BLAKE2b-256 | 744da9e4d78658926892c1078fed4c3731eeb227b4f93af02e262a867a99e2ed |
Hashes for PennyLane_Lightning-0.32.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c6b969df5706310d2210a94d34fc194d25a5965cfb9eae4994b92e80d5b0c38 |
|
MD5 | 5a8e99d3a438e2b4b53656e8a56cb298 |
|
BLAKE2b-256 | 572b60f3c8f42fee2d09f7bafb08ab2eb6cb9f871892e28f797d4605ecff56b5 |
Hashes for PennyLane_Lightning-0.32.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 642d6e843c0d1cedf99fc8d24a5e9ce292644b065201234def31b77c354eea43 |
|
MD5 | 1826f21200450e8b8d9dbb29ce70a942 |
|
BLAKE2b-256 | 6dcacba359a10f30426085fb97b6a50a80797a42b45351e8f4bd8c06e0114dfe |
Hashes for PennyLane_Lightning-0.32.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043ac78948a17714fb41aecc62fb5550d727bdcb063c5d23db451e814d14803f |
|
MD5 | b9074b4f32d077d752338e9a434cc089 |
|
BLAKE2b-256 | 015e0f21e7e0b83eb2a07cdac55ddbb453b188ddb4b0d4b052bd0f33faaed721 |
Hashes for PennyLane_Lightning-0.32.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab3c86ca9a34ab9513e3f8f8afac8ba2b3eb00f20dc0671ab03fbd82e8225e3b |
|
MD5 | 2c9768598e31b95c2ee0cebc6cd38a35 |
|
BLAKE2b-256 | 4b38e976c08232982469b040df77cedd9c72f56e65a9867c7f4981f025deba34 |
Hashes for PennyLane_Lightning-0.32.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8706a8146fd0203fe5260b2a00ab9797187d56dc7122a58951513471aff0101e |
|
MD5 | a6b4d8b58c115233ad4e7d94fb8af70f |
|
BLAKE2b-256 | 4f9f687729c18c731edf26c4b63dbe3b1be91e8e234f985add22172dde89f716 |
Hashes for PennyLane_Lightning-0.32.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f915c2b2f1215b72d4ce8e118273b52351446abc3ff41d886ee7ec3adf79675a |
|
MD5 | 7cd2133c09d3f2bc0af9d729e5f31574 |
|
BLAKE2b-256 | 07509740623eacb8f436f7bc1cd953b649e52e34792b6cdb02b14d9ebbb20e11 |
Hashes for PennyLane_Lightning-0.32.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a6902414b0e7b2a67febf079a3082696cf87eada644e02cf0c1f182c03d1aa |
|
MD5 | 96719919a965fc098f671cb723191898 |
|
BLAKE2b-256 | 1e3331ba18f0e34a772ae2e56cecf69e0d1e2b0203be91ac7040c58d88cf4a16 |
Hashes for PennyLane_Lightning-0.32.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4595e635e0f28fa3feebb3559086dfdb2c16710cb06748f5149b82fdd5f50bd |
|
MD5 | b557645060941e0141c4376045526bdf |
|
BLAKE2b-256 | 323de5b3bdbe29a76198f7ac5bec09a975a430a1be06c93ac1f44fe56e3c1d6e |