PennyLane-Lightning
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.
Warnings
- gotcha The `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.
- breaking Building Catalyst Lightning plugins requires compatibility with specific Catalyst Runtime versions.
- gotcha Specialized 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.
- gotcha Like 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.
- gotcha Support for mid-circuit measurements (MCMs) and their different execution methods (`mcm_method`) was introduced and refined, potentially impacting performance or available features.
Install
-
pip install pennylane-lightning
Imports
- qml.device
import pennylane as qml device = qml.device("lightning.qubit", wires=4)
Quickstart
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}")