Skip to main content

PennyLane-Lightning plugin

Project description

Linux x86_64 tests (branch) Windows tests (branch) Linux x86_64 wheel builds (branch) Codecov coverage CodeFactor Grade Read the Docs PyPI PyPI - Python Version

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).

Authors

Lightning is the work of many contributors.

If you are doing research using PennyLane and Lightning, please cite our paper:

Ville Bergholm, Josh Izaac, Maria Schuld, Christian Gogolin, M. Sohaib Alam, Shahnawaz Ahmed, Juan Miguel Arrazola, Carsten Blank, Alain Delgado, Soran Jahangiri, Keri McKiernan, Johannes Jakob Meyer, Zeyue Niu, Antal Száva, and Nathan Killoran. PennyLane: Automatic differentiation of hybrid quantum-classical computations. 2018. arXiv:1811.04968

Support

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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PennyLane_Lightning-0.32.0.tar.gz (62.9 kB view hashes)

Uploaded Source

Built Distributions

PennyLane_Lightning-0.32.0-py3-none-any.whl (84.1 kB view hashes)

Uploaded Python 3

PennyLane_Lightning-0.32.0-cp311-cp311-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

PennyLane_Lightning-0.32.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

PennyLane_Lightning-0.32.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (9.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

PennyLane_Lightning-0.32.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

PennyLane_Lightning-0.32.0-cp311-cp311-macosx_11_0_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ x86-64

PennyLane_Lightning-0.32.0-cp311-cp311-macosx_11_0_arm64.whl (940.5 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

PennyLane_Lightning-0.32.0-cp310-cp310-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

PennyLane_Lightning-0.32.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

PennyLane_Lightning-0.32.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (9.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

PennyLane_Lightning-0.32.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

PennyLane_Lightning-0.32.0-cp310-cp310-macosx_11_0_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ x86-64

PennyLane_Lightning-0.32.0-cp310-cp310-macosx_11_0_arm64.whl (940.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

PennyLane_Lightning-0.32.0-cp39-cp39-win_amd64.whl (3.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

PennyLane_Lightning-0.32.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

PennyLane_Lightning-0.32.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (9.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

PennyLane_Lightning-0.32.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

PennyLane_Lightning-0.32.0-cp39-cp39-macosx_11_0_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ x86-64

PennyLane_Lightning-0.32.0-cp39-cp39-macosx_11_0_arm64.whl (940.7 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page