qml.templates¶
This module provides a growing library of templates of common variational circuit architectures that can be used to easily build, evaluate, and train quantum nodes.
Embeddings¶
Embeddings are templates encode features (i.e., classical data) into a quantum state. They can optionally be repeated, and may contain trainable parameters. Embeddings are typically used at the beginning of a circuit.
Functions¶

Encodes \(2^n\) features into the amplitude vector of \(n\) qubits. 

Encodes \(N\) features into the rotation angles of \(n\) qubits, where \(N \leq n\). 

Encodes \(n\) binary features into a basis state of \(n\) qubits. 

Encodes \(N\) features into the displacement amplitudes \(r\) or phases \(\phi\) of \(M\) modes, 

Encodes \(n\) features into \(n\) qubits using diagonal gates of an IQP circuit. 

Encodes \(N\) features into \(n>N\) qubits, using a layered, trainable quantum circuit that is inspired by the QAOA ansatz. 

Encodes \(N\) features into the squeezing amplitudes \(r \geq 0\) or phases \(\phi \in [0, 2\pi)\) of \(M\) modes, where \(N\leq M\). 
Layers¶
Layers are trainable templates that are typically repeated, using different adjustable parameters in each repetition. They implement a transformation from a quantum state to another quantum state.
Functions¶

Layers consisting of oneparameter singlequbit rotations on each qubit, followed by a closed chain or ring of CNOT gates. 

A sequence of layers of a continuousvariable quantum neural network, as specified in arXiv:1806.06871. 

Layers of randomly chosen single qubit rotations and 2qubit entangling gates, acting on randomly chosen qubits. 

Layers consisting of a simplified 2design architecture of PauliY rotations and controlledZ entanglers proposed in Cerezo et al.(2020).. 

Layers consisting of single qubit rotations and entanglers, inspired by the circuitcentric classifier design arXiv:1804.00633. 
Subroutines¶
Subroutines are the most basic template, consisting of a collection of quantum operations, and not fulfilling any of the characteristics of other templates (i.e. to prepare a specific state, to be repeated or to encode features).
Functions¶

Applies the Trotterized timeevolution operator for an arbitrary Hamiltonian, expressed in terms of Pauli gates. 

Implements an arbitrary unitary on the specified wires. 

Circuit to exponentiate the tensor product of Pauli matrices representing the doubleexcitation operator entering the Unitary CoupledCluster Singles and Doubles (UCCSD) ansatz. 

General linear interferometer, an array of beamsplitters and phase shifters. 

Circuit to exponentiate the tensor product of Pauli matrices representing the singleexcitation operator entering the Unitary CoupledCluster Singles and Doubles (UCCSD) ansatz. 

Implements the Unitary CoupledCluster Singles and Doubles (UCCSD) ansatz. 
State preperations¶
State preperations are templates that prepare a given quantum state, by decomposing it into elementary operations.
Functions¶

Implements an arbitrary state preparation on the specified wires. 

Prepares a basis state on the given wires using a sequence of Pauli X gates. 

Prepares an arbitrary state on the given wires using a decomposition into gates developed by Möttönen et al. 
Custom templates¶
The template decorator can used to register a quantum function as a template.
Register a quantum template with PennyLane. 
Broadcasting function¶
The broadcast function creates a new template by broadcasting templates (or normal gates) over wires in a
predefined pattern. You can import this function both via qml.broadcast
and qml.templates.broadcast
.

Applies a unitary multiple times to a specific pattern of wires. 
Layering Function¶
The layer function creates a new template by repeatedly applying a sequence of quantum
gates to a set of wires. You can import this function both via
qml.layer
and qml.templates.layer
.

Repeatedly applies a unitary a given number of times. 
Utility functions for input checks¶
Utility functions provided for the templates. These are useful for standard input checks, for example to make sure that arguments have the right shape, range or type.
Functions¶

Check that the value of 

Checks that 

Check that all sequences in 

Check that the shape of 

Check that the shape of elements in the 

Check that the type of 

Checks that 

Turn 
Contents
Downloads