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

 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. draw(qnode[, charset, wire_order, …]) Create a function that draws the given qnode. draw_mpl(qnode[, wire_order, …]) Draw a qnode with matplotlib get_unitary_matrix(circuit[, wire_order]) Construct the matrix representation of a quantum circuit. 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]) Resource information about a quantum circuit. mitigate_with_zne(circuit, scale_factors, …) Mitigate an input circuit using zero-noise extrapolation.

### Transforms that act on quantum functions¶

These transforms accept quantum functions (Python functions containing quantum operations) that are used to construct QNodes.

 Create a function that applies the adjoint (inverse) of the provided operation or template. ctrl(fn, control) Create a method that applies a controlled version of the provided method. 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 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 Compile a circuit by applying a series of transforms to a quantum function. cancel_inverses Quantum function transform to remove any operations that are applied next to their (self-)inverse. commute_controlled Quantum function transform to move commuting gates past control and target qubits of controlled operations. merge_rotations Quantum function transform to combine rotation gates of the same type that act sequentially. single_qubit_fusion Quantum function transform to fuse together groups of single-qubit operations into a general single-qubit unitary operation (Rot). unitary_to_rot Quantum function transform to decomposes all instances of single-qubit and select instances of two-qubit QubitUnitary operations to parametrized single-qubit operations. merge_amplitude_embedding Quantum function transform to combine amplitude embedding templates that act on different qubits. remove_barrier Quantum function transform to remove Barrier gates. undo_swaps Quantum function transform to remove SWAP gates by running from right to left through the circuit changing the position of the qubits accordingly.

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.

### Transforms that act on tapes¶

These transforms accept quantum tapes, and return one or more tapes as well as a classical processing function.

 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:

 single_tape_transform(transform_fn) 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. qfunc_transform(tape_transform) Given a function which defines a tape transform, convert the function into one that applies the tape transform to quantum functions (qfuncs). Returns a function that generates the tape from a quantum function without any operation queuing taking place. 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.