qml.transforms¶
This subpackage contains QNode, quantum function, device, and tape transforms.
Transforms¶
Transforms that act on QNodes¶
These transforms accept QNodes, and return new transformed functions that compute the desired quantity.

Returns a function to extract the Jacobian matrix of the classical part of a QNode. 

Transform a QNode to support an initial batch dimension for operation parameters. 

Transform a QNode to support an initial batch dimension for gate inputs. 

Create a batched partial callable object from the QNode specified. 

Returns a function that computes the metric tensor of a given QNode or quantum tape. 

Implements the adjoint method outlined in Jones to compute the metric tensor. 

Resource information about a quantum circuit. 

Splits a qnode measuring noncommuting observables into groups of commuting observables. 
Transforms that act on quantum functions¶
These transforms accept quantum functions (Python functions containing quantum operations) that are used to construct QNodes.

Condition a quantum operation on the results of midcircuit qubit measurements. 

Quantum function transform that substitutes operations conditioned on measurement outcomes to controlled operations. 

Provides the circuit to apply a controlled version of the \(\mathcal{Q}\) unitary defined in this paper. 

Provides the circuit to perform the quantum Monte Carlo estimation algorithm. 

Insert an operation into specified points in an input circuit. 
Transforms for circuit compilation¶
This set of transforms accept quantum functions, and perform basic circuit compilation tasks.

Compile a circuit by applying a series of transforms to a quantum function. 

Quantum function transform to remove any operations that are applied next to their (self)inverses or adjoint. 

Quantum function transform to move commuting gates past control and target qubits of controlled operations. 

Quantum function transform to combine rotation gates of the same type that act sequentially. 

Quantum function transform to fuse together groups of singlequbit operations into a general singlequbit unitary operation ( 

Quantum function transform to decomposes all instances of singlequbit and select instances of twoqubit 
Quantum function transform to combine amplitude embedding templates that act on different qubits. 


Quantum function transform to remove Barrier gates. 

Quantum function transform to remove SWAP gates by running from right to left through the circuit changing the position of the qubits accordingly. 

Quantum function transform to optimize a circuit given a list of patterns (templates). 

Transpile a circuit according to a desired coupling map 
There are also utility functions and decompositions available that assist with both transforms, and decompositions within the larger PennyLane codebase.

Decompose a onequbit unitary \(U\) in terms of elementary operations. 

Decompose a twoqubit unitary \(U\) in terms of elementary operations. 

Context manager for setting custom decompositions. 

Function that applies the pattern matching algorithm and returns the list of maximal matches. 

This transform converts a PennyLane quantum tape to a ZXGraph in the PyZX framework. 

Converts a graph from PyZX to a PennyLane tape, if the graph is diagramlike. 
There are also utility functions that take a circuit and return a DAG.

Construct the pairwisecommutation DAG (directed acyclic graph) representation of a quantum circuit. 

Class to represent a quantum circuit as a directed acyclic graph (DAG). 

Class to store information about a quantum operation in a node of the commutation DAG. 
Transform for circuit cutting¶
The cut_circuit()
transform accepts a QNode and returns a new function that cuts the original circuit,
allowing larger circuits to be split into smaller circuits that are compatible with devices that
have a restricted number of qubits.

Cut up a quantum circuit into smaller circuit fragments. 
The cut_circuit_mc()
transform is designed to be used for cutting circuits which contain sample()
measurements and is implemented using a Monte Carlo method. Similarly to the cut_circuit()
transform, this transform accepts a QNode and returns a new function that cuts the original circuit.
This transform can also accept an optional classical processing function to calculate an
expectation value.

Cut up a circuit containing sample measurements into smaller fragments using a Monte Carlo method. 
There are also lowlevel functions that can be used to build up the circuit cutting functionalities:

Converts a quantum tape to a directed multigraph. 

Replace each 

Fragments a graph into a collection of subgraphs as well as returning the communication (quotient) graph. 

Converts a directed multigraph to the corresponding 

Expands a fragment tape into a sequence of tapes for each configuration of the contained 

Expands fragment tapes into a sequence of random configurations of the contained pairs of 

Processing function for the 

Function to postprocess samples for the 

Function to postprocess samples for the 

A circuitcutting distribution policy for executing (large) circuits on available (comparably smaller) devices. 

Calls KaHyPar to partition a graph. 

Inserts a 

Automatically finds and places optimal 
Transforms that act on tapes¶
These transforms accept quantum tapes, and return one or more tapes as well as a classical processing function.

Expand a broadcasted tape into multiple tapes and a function that stacks and squeezes the results. 

Splits a tape measuring a Hamiltonian expectation into mutliple tapes of Pauli expectations, and provides a function to recombine the results. 

Splits a tape measuring a (fastforwardable) Hamiltonian expectation into mutliple tapes of the Xi or sgn decomposition, and provides a function to recombine the results. 

Splits a quantum tape measuring a Sum expectation into multiple tapes of summand expectations, and provides a function to recombine the results. 
This transform accepts a single tape and returns a single tape:

Transforms a circuit to one with purely numpy parameters. 
Decorators and utility functions¶
The following decorators and convenience functions are provided to help build custom QNode, quantum function, and tape transforms:

For registering a tape transform that takes a tape and outputs a single new tape. 

Class for registering a tape transform that takes a tape, and outputs a batch of tapes to be independently executed on a quantum device. 

Given a function which defines a tape transform, convert the function into one that applies the tape transform to quantum functions (qfuncs). 

Convert a function that applies to operators into a functional transform. 

Returns a function that generates the tape from a quantum function without any operation queuing taking place. 

Map a batch transform over multiple tapes. 

Create a function for expanding a tape to a given depth, and with a specific stopping criterion. 

Creates a custom expansion function for a device that applies a set of specified custom decompositions. 

Expand out a tape so that it supports differentiation of requested operations. 
Expand out a tape so that it supports differentiation of requested operations with the Hadamard test gradient. 


Expand out a tape so that all its parametrized operations have a single parameter. 

Expand out a tape so that all its trainable operations have a single parameter. 

Expand out a tape so that all its parametrized operations have a unitary generator. 
Transforms for error mitigation¶

Mitigate an input circuit using zeronoise extrapolation. 

Differentiable circuit folding of the global unitary 

Extrapolator to \(f(0)\) for polynomial fit. 

Polynomial fit where the degree of the polynomial is fixed to being equal to the length of 