qml.change_op_basis¶
- change_op_basis(compute_op, target_op, uncompute_op=None)[source]¶
Construct an operator that represents the product of the operators provided; particularly a compute-uncompute pattern.
- Parameters:
compute_op (
Operator
) – A single operator or product that applies quantum operations.target_op (
Operator
) – A single operator or a product that applies quantum operations.uncompute_op (None |
Operator
) – An optional single operator or a product that applies quantum operations.None
corresponds touncompute_op=qml.adjoint(compute_op)
.
- Returns:
the operator representing the compute-uncompute pattern.
- Return type:
Example
Consider the following example involving a
ChangeOpBasis
. The compute, uncompute pattern is composed of a Quantum Fourier Transform (QFT
), followed by aPhaseAdder
, and finally an inverseQFT
.import pennylane as qml from functools import partial qml.decomposition.enable_graph() dev = qml.device("default.qubit") @qml.qnode(dev) def circuit(): qml.H(0) qml.CNOT([1,2]) qml.ctrl( qml.change_op_basis(qml.QFT([1,2]), qml.PhaseAdder(1, x_wires=[1,2])), control=0 ) return qml.state() circuit2 = qml.transforms.decompose(circuit, max_expansion=1)
When this circuit is decomposed, the
compute_op
anduncompute_op
are not controlled, resulting in a much more resource-efficient decomposition:>>> print(qml.draw(circuit2)()) 0: ──H──────╭●────────────────┤ State 1: ─╭●─╭QFT─├PhaseAdder─╭QFT†─┤ State 2: ─╰X─╰QFT─╰PhaseAdder─╰QFT†─┤ State
See also