PennyLane-Lightning

0.44.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

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}")

view raw JSON →