PennyLane

A differentiable-programming framework for quantum machine learning and variational algorithms.

by Xanadu · Python · Moderate · Open source (Apache 2.0 per its repository; check) · reviewed December 2026

What it is

PennyLane treats a quantum circuit as a function you can differentiate. You write a circuit inside a decorated Python function, called a QNode, and PennyLane can compute gradients of its output, which makes it the natural tool for training circuits.

It is hardware-agnostic by design. The same QNode can run on its own simulators or, through plugins, on devices from several providers, and it connects to PyTorch, TensorFlow and JAX.

  • A circuit plus its measurement is a QNode, a function that returns numbers.
  • Gradients are a core feature, using methods such as the parameter-shift rule.
  • The device is a parameter, so changing hardware means changing one line.

Core ideas

Device
The simulator or hardware that executes the circuit, such as default.qubit.
QNode
A circuit and a device bound together as a callable function.
Measurement functions
expval, probs, sample and state decide what the QNode returns.
Plugins
Add other devices, for example Qiskit, Cirq and Braket backends.

Install and first program

Install

pip install pennylane

Bell state

import pennylane as qml

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def bell():
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.probs(wires=[0, 1])

print(bell())     # [0.5, 0. , 0. , 0.5]

PennyLane returns exact probabilities by default. Give the device a shots argument to sample instead. Not executed in this site’s build environment.

A gradient of a circuit

import pennylane as qml
from pennylane import numpy as np

dev = qml.device("default.qubit", wires=1)

@qml.qnode(dev)
def circuit(theta):
    qml.RX(theta, wires=0)
    return qml.expval(qml.PauliZ(0))

theta = np.array(0.3, requires_grad=True)
print(circuit(theta))              # cos(0.3)  = 0.9553
print(qml.grad(circuit)(theta))    # -sin(0.3) = -0.2955

The exact answers are cos θ and −sin θ, which you can check by hand. The VQE and QAOA Playground on this site uses the same parameter-shift idea.

Strengths

  • →Automatic differentiation of quantum circuits
  • →Integration with PyTorch, TensorFlow and JAX
  • →One code base for many devices through plugins
  • →A large library of ready-made templates for variational circuits
  • →Strong tutorial and demo collection

Weaknesses

  • →Less natural for plain circuit building and compilation
  • →Hardware access depends on plugins and accounts
  • →Smaller community than Qiskit for general questions
  • →The QNode style needs getting used to

Hardware access

Hardware is reached through plugins, so the list depends on which plugins and accounts you set up. Check PennyLane’s plugin directory for what is current.

Ecosystem

  • Lightning: faster simulators, including GPU versions
  • Plugins for Qiskit, Cirq and Amazon Braket
  • Catalyst: just-in-time compilation for hybrid programs
  • A demos library with worked examples

Choose it when

  • Quantum machine learning
  • Variational algorithms such as VQE and QAOA
  • Hardware-agnostic research code
  • Teaching optimisation of quantum circuits

Look elsewhere when

  • Low-level circuit compilation work
  • Projects that only need one vendor’s toolchain

Common pitfalls

  • Parameters that should be trained need to be created with requires_grad=True through PennyLane’s own NumPy.
  • The QNode must return measurement results. Printing inside it does not give you output.
  • Wire labels and wire order matter when you combine circuits.
  • Device names changed over versions. Copy them from current docs.

A learning path

  1. Install pennylane and run the Bell QNode below.
  2. Compute a gradient of a one-qubit circuit.
  3. Train a small variational circuit with an optimiser.
  4. Connect a PyTorch or JAX model.

Ratings

Editorial ratings from 0 to 3, not benchmarks.

Beginner friendliness
2
Quantum machine learning
3
IBM hardware
2
Google hardware
1
Many hardware providers
3
GPU simulation
2
Circuit compilation
1
Fault-tolerant planning
1
Low-level control
2

Compared with others

Learn more on QuantumAtlas

Questions

Do I need PyTorch to use PennyLane?

No. PennyLane has its own NumPy-based interface and optimisers. The ML integrations are optional.

Can PennyLane run on real hardware?

Yes, through plugins and the provider’s account. Availability depends on the provider.

Is PennyLane only for machine learning?

No, but differentiation is its main strength, so it is best for variational methods.

Sources

Frameworks change often. The official documentation is the final word on versions, devices and prices.