Interfaces and training

PennyLane offers seamless integration between classical and quantum computations. Code up quantum circuits in PennyLane, and connect them easily to the top scientific computing and machine learning libraries.

The bridge between the quantum and classical worlds is provided in PennyLane via interfaces. Currently, there are four built-in interfaces: NumPy, PyTorch, JAX, and TensorFlow. These interfaces make each of these libraries quantum-aware, allowing quantum circuits to be treated just like any other operation.

In PennyLane, an interface is declared when creating a QNode, e.g.,

@qml.qnode(dev, interface="tf")
def my_quantum_circuit(...):


If no interface is specified, PennyLane will default to the NumPy interface (powered by the autograd library).

This will allow native numerical objects of the specified library (NumPy arrays, Torch Tensors, or TensorFlow Tensors) to be passed as parameters to the quantum circuit. It also makes the gradients of the quantum circuit accessible to the classical library, enabling the optimization of arbitrary hybrid circuits.

See the links below for walkthroughs of each specific interface:

In addition to the core interfaces discussed above, PennyLane also provides higher-level classes for converting QNodes into both Keras and torch.nn layers:

pennylane.qnn.KerasLayer(qnode, …[, …])

Converts a QNode() to a Keras Layer.

pennylane.qnn.TorchLayer(qnode, weight_shapes)

Converts a QNode() to a Torch layer.