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.
Classes¶

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, where \(N\leq M\). 

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\). 
Class Inheritance Diagram¶
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.
Classes¶

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. 

Implements a local, expressive, and quantumnumberpreserving ansatz proposed by Anselmetti et al. in arXiv:2104.05692. 

Implements the heuristic VQE ansatz for quantum chemistry simulations using the particleconserving gate \(U_{1,\mathrm{ex}}\) proposed by Barkoutsos et al. in arXiv:1805.04340. 

Implements the heuristic VQE ansatz for Quantum Chemistry simulations using the particleconserving entangler \(U_\mathrm{ent}(\vec{\theta}, \vec{\phi})\) proposed in arXiv:1805.04340. 

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. 
Class Inheritance Diagram¶
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¶

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

Builds a quantum circuit to prepare correlated states of molecules by applying all 

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. 

Performs the Grover Diffusion Operator. 

Applies a permutation to a set of wires. 

Apply a quantum Fourier transform (QFT). 

Performs the quantum Monte Carlo estimation algorithm. 

Performs the quantum phase estimation circuit. 

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. 
Class Inheritance Diagram¶
State preparations¶
State preperations are templates that prepare a given quantum state, by decomposing it into elementary operations.
Classes¶

Implements an arbitrary state preparation on the specified wires. 

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

Prepares an arbitrary state on the given wires using a decomposition into gates developed by Möttönen et al. (2004). 
Class Inheritance Diagram¶
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 

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 
Utility functions for quantum Monte Carlo¶
Functions¶

Calculates the unitary that encodes a function onto an ancilla qubit register. 

Calculates the \(\mathcal{Q}\) matrix that encodes the expectation value according to the probability unitary \(\mathcal{A}\) and the functionencoding unitary \(\mathcal{R}\). 

Calculates the unitary matrix corresponding to an input probability distribution. 
Contents
Downloads