This subpackage contains QNode, quantum function, device, and tape transforms.


Transforms that act on QNodes

These transforms accept QNodes, and return new transformed functions that compute the desired quantity.

classical_jacobian(qnode[, argnum, …])

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

batch_params(tape[, all_operations])

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

batch_input(tape, argnum)

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

batch_partial(qnode[, all_operations, …])

Create a batched partial callable object from the QNode specified.

metric_tensor(tape[, approx, …])

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

adjoint_metric_tensor(circuit[, device, hybrid])

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

specs(qnode[, max_expansion, expansion_strategy])

Resource information about a quantum circuit.


Splits a qnode measuring non-commuting 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.

cond(condition, true_fn[, false_fn])

Condition a quantum operation on the results of mid-circuit qubit measurements.


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

apply_controlled_Q(fn, wires, target_wire, …)

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

quantum_monte_carlo(fn, wires, target_wire, …)

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

insert(circuit, op, op_args[, position, before])

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(tape[, pipeline, basis_set, …])

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.

commute_controlled(tape[, direction])

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

merge_rotations(tape[, atol, include_gates])

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

single_qubit_fusion(tape[, atol, exclude_gates])

Quantum function transform to fuse together groups of single-qubit operations into a general single-qubit unitary operation (Rot).


Quantum function transform to decomposes all instances of single-qubit and select instances of two-qubit QubitUnitary operations to parametrized single-qubit operations.


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.

pattern_matching_optimization(tape, …[, …])

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

transpile(tape, coupling_map)

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.

zyz_decomposition(U, wire)

Recover the decomposition of a single-qubit matrix \(U\) in terms of elementary operations.

two_qubit_decomposition(U, wires)

Decompose a two-qubit unitary \(U\) in terms of elementary operations.

set_decomposition(custom_decomps, dev[, …])

Context manager for setting custom decompositions.

pattern_matching(circuit_dag, pattern_dag)

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

There are also utility functions that take a circuit and return a DAG.


Construct the pairwise-commutation DAG (directed acyclic graph) representation of a quantum circuit.


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

CommutationDAGNode([op, wires, …])

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_circuit(tape[, auto_cutter, …])

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_circuit_mc(tape[, …])

Cut up a circuit containing sample measurements into smaller fragments using a Monte Carlo method.

There are also low-level functions that can be used to build up the circuit cutting functionalities:


Converts a quantum tape to a directed multigraph.


Replace each WireCut node in the graph with a MeasureNode and PrepareNode.


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


Converts a directed multigraph to the corresponding QuantumTape.

remap_tape_wires(tape, wires)

Map the wires of a tape to a new set of wires.


Expands a fragment tape into a sequence of tapes for each configuration of the contained MeasureNode and PrepareNode operations.

expand_fragment_tapes_mc(tapes, …)

Expands fragment tapes into a sequence of random configurations of the contained pairs of MeasureNode and PrepareNode operations.

qcut_processing_fn(results, …[, …])

Processing function for the cut_circuit() transform.

qcut_processing_fn_sample(results, …)

Function to postprocess samples for the cut_circuit_mc() transform.

qcut_processing_fn_mc(results, …)

Function to postprocess samples for the cut_circuit_mc() transform.

CutStrategy(devices, …)

A circuit-cutting distribution policy for executing (large) circuits on available (comparably smaller) devices.

kahypar_cut(graph, num_fragments[, …])

Calls KaHyPar to partition a graph.

place_wire_cuts(graph, cut_edges)

Inserts a WireCut node for each provided cut edge into a circuit graph.

find_and_place_cuts(graph[, cut_method, …])

Automatically finds and places optimal WireCut nodes into a given tape-converted graph using a customizable graph partitioning function.

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.

measurement_grouping(tape, obs_list, coeffs_list)

Returns a list of measurement optimized tapes, and a classical processing function, for evaluating the expectation value of a provided Hamiltonian.

hamiltonian_expand(tape[, group])

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

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.

batch_transform(*args, **kwargs)

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).

op_transform(*args, **kwargs)

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_batch_transform(transform, tapes)

Map a batch transform over multiple tapes.

create_expand_fn(depth[, stop_at, device, …])

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

create_decomp_expand_fn(custom_decomps, dev)

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

expand_invalid_trainable(tape[, depth])

Expand out a tape so that it supports differentiation of requested operations.

expand_multipar(tape[, depth])

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

expand_trainable_multipar(tape[, depth])

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

expand_nonunitary_gen(tape[, depth])

Expand out a tape so that all its parametrized operations have a unitary generator.

Transforms for error mitigation

mitigate_with_zne(circuit, scale_factors, …)

Mitigate an input circuit using zero-noise extrapolation.

fold_global(circuit, scale_factor)

Differentiable circuit folding of the global unitary circuit.

poly_extrapolate(x, y, order)

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

richardson_extrapolate(x, y)

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