Registry / ai-ml / pennylane-lightning

pennylane-lightning

JSON →
library0.45.0pypypi✓ verified 24d ago

PennyLane-Lightning provides high-performance C++ quantum simulators that integrate as plugins with the PennyLane quantum machine learning library. The base package includes the `lightning.qubit` device for CPU-based state-vector simulation, with other specialized devices (GPU, Kokkos, Tensor, AMDGPU) available via separate installation packages. It is actively maintained with frequent, typically monthly or bi-monthly, releases.

pip install pennylane-lightning
INSTALL
IMPORT
SIG · PENNYLANE-LIGHTNIN
P
pennylane-lightning
ai-mlpythonv0.45.0
Install
13.9s avg
Import
4676ms
Disk
388MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.42.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 3.874s · 341.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 13.9s · import 3.608s · 338MB
388MB installed
● package 388MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

qml.device
import pennylane as qml device = qml.device("lightning.qubit", wires=4)
from pennylane_lightning import LightningQubit
PennyLane-Lightning devices are loaded via `qml.device` using their string name, not by direct import of a class from the `pennylane_lightning` package itself. Attempting direct import will fail.

This quickstart demonstrates how to initialize the `lightning.qubit` device and use it within a PennyLane quantum circuit to compute an expectation value and its gradients. Ensure PennyLane is also installed.

import pennylane as qml import numpy as np # Create a Lightning Qubit device dev = qml.device("lightning.qubit", wires=2) @qml.qnode(dev) def circuit(x): qml.RX(x[0], wires=0) qml.RY(x[1], wires=1) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)) # Run the circuit params = np.array([0.54, 0.12], requires_grad=True) result = circuit(params) print(f"Expectation value: {result}") # Calculate gradients dq = qml.grad(circuit)(params) print(f"Gradients: {dq}")
Debug
Known issues
gotchaThe `pennylane-lightning` package only provides the `lightning.qubit` CPU device. For GPU-accelerated (`lightning.gpu`), Kokkos-enabled (`lightning.kokkos`), Tensor Network (`lightning.tensor`), or AMDGPU (`lightning.amdgpu`) devices, separate `pennylane-lightning-gpu`, `pennylane-lightning-kokkos`, `pennylane-lightning-tensor`, and `pennylane-lightning-amdgpu` packages must be installed respectively.
fix
Install the specific package for the desired device, e.g., `pip install pennylane-lightning-gpu`.
affects: All versions
breakingBuilding Catalyst Lightning plugins requires compatibility with specific Catalyst Runtime versions.
fix
Ensure your Catalyst Runtime version (e.g., v0.11.0 for PennyLane-Lightning v0.41.1) is compatible when using Lightning devices within Catalyst. Refer to the release notes for specific version requirements.
affects: 0.41.1 onwards
gotchaSpecialized devices like `lightning.gpu`, `lightning.kokkos`, and `lightning.amdgpu` have specific hardware and driver requirements (e.g., NVIDIA CUDA, AMD ROCm). They will not function without the correct setup.
fix
Consult the PennyLane-Lightning documentation for detailed hardware, driver, and CUDA/ROCm toolkit installation instructions before attempting to use these devices.
affects: All versions supporting these devices
gotchaLike all state-vector simulators, `lightning.qubit`'s memory consumption scales exponentially with the number of qubits. This can quickly become a bottleneck for circuits with a large number of wires.
fix
For very large numbers of qubits, consider using tensor network simulators (`lightning.tensor`), or sampling-based approaches, or distributed computing solutions (e.g., `lightning.kokkos` with MPI).
affects: All versions
gotchaSupport for mid-circuit measurements (MCMs) and their different execution methods (`mcm_method`) was introduced and refined, potentially impacting performance or available features.
fix
For optimal MCM performance and full feature set, ensure you are using a recent version (0.43.0+) and explicitly specify the `mcm_method` if required, e.g., `qml.device("lightning.qubit", wires=4, mcm_method="device")`.
affects: Prior to 0.43.0 for full support, 0.43.0 introduced `mcm_method="device"` and `"tree-traversal"`
Errors
Common errors & fixes
ImportError: Pre-compiled binaries for lightning.qubit are not available.
This error often occurs when the pre-compiled binaries for `lightning.qubit` (or other Lightning devices like `lightning.gpu`, `lightning.tensor`) are not compatible with your system's `glibc` version (common on older Linux distributions like RHEL 7), or due to an unsupported Python version, or issues within your virtual environment.
fix
Ensure you are using a Python version supported by PennyLane-Lightning (e.g., 3.10 or newer) and that your system's `glibc` library is sufficiently new (e.g., 2.28 or greater for `manylinux_2_28` wheels). Using a virtual environment (like Conda or `venv`) is recommended. If problems persist, consider using cloud environments like Google Colab or qBraid, or compiling PennyLane-Lightning from source if you have specific system constraints.
DeviceError: Device lightning.gpu does not exist. Make sure the required plugin is installed.
This error indicates that the `lightning.gpu` device could not be found or properly initialized. This typically happens when the NVIDIA cuQuantum SDK's `custatevec` library is not installed, is not accessible in the system's library path, or if your GPU hardware or CUDA Toolkit version is incompatible.
fix
Install the appropriate `custatevec` package for your CUDA version (e.g., `pip install custatevec-cu11` for CUDA 11.x or `custatevec-cu12` for CUDA 12.x). Verify that your NVIDIA CUDA Toolkit is correctly installed and configured, your NVIDIA drivers are up to date, and your GPU meets the minimum compute capability requirement (SM7.0 or newer).
ImportError: libcudart.so.11.0: cannot open shared object file: No such file or directory
This error, or similar messages like 'Error in PennyLane Lightning: the provided PTX was compiled with an unsupported toolchain,' signifies a mismatch between the CUDA runtime libraries available on your system and the CUDA version `pennylane-lightning-gpu` was compiled against or expects. It often occurs with outdated CUDA versions or incorrect `LD_LIBRARY_PATH` settings.
fix
Ensure your CUDA Toolkit is at a supported version (e.g., 11.5 or newer, 11.8 preferred, or 12.x for recent `pennylane-lightning` versions). Update your NVIDIA drivers and CUDA SDK if necessary. Crucially, ensure that the `LD_LIBRARY_PATH` environment variable includes the directory where your CUDA runtime libraries (e.g., `libcudart.so`) are located.
ModuleNotFoundError: No module named 'pennylane_lightning.core'
This error typically points to a version incompatibility between the main `pennylane` library and the `pennylane-lightning` plugin, or an issue when installing `pennylane-lightning` from source without a matching `pennylane` installation. The internal structure of PennyLane can evolve, leading to missing modules if versions don't align.
fix
Ensure both `pennylane` and `pennylane-lightning` are installed from a compatible release, preferably by upgrading both simultaneously using `pip install pennylane pennylane-lightning --upgrade`. If you are building from source, clone and install `pennylane` from a compatible branch or version before installing `pennylane-lightning`.
Upgrade
Version history
0.45.0latest on PyPI · released May 12, 2026
Audit
Dependencies
pennylanerequiredCore library; PennyLane-Lightning provides devices for PennyLane.
numpyrequiredNumerical operations and array handling.
Agent activity
6 hits · last 30 days
node
4
Amazon
1
Resources