qp.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 to uncompute_op=qp.adjoint(compute_op).

Returns:

the operator representing the compute-uncompute pattern.

Return type:

ChangeOpBasis

Example

Consider the following example involving a ChangeOpBasis. The compute, uncompute pattern is composed of a Quantum Fourier Transform (QFT), followed by a PhaseAdder, and finally an inverse QFT.

import pennylane as qp
from functools import partial

qp.decomposition.enable_graph()

dev = qp.device("default.qubit")
@qp.qnode(dev)
def circuit():
    qp.H(0)
    qp.CNOT([1,2])
    qp.ctrl(
        qp.change_op_basis(qp.QFT([1,2]), qp.PhaseAdder(1, x_wires=[1,2])),
        control=0
    )
    return qp.state()

circuit2 = qp.transforms.decompose(circuit, max_expansion=1)

When this circuit is decomposed, the compute_op and uncompute_op are not controlled, resulting in a much more resource-efficient decomposition:

>>> print(qp.draw(circuit2)())
0: ──H──────╭●────────────────┤  State
1: ─╭●─╭QFT─├PhaseAdder─╭QFT†─┤  State
2: ─╰X─╰QFT─╰PhaseAdder─╰QFT†─┤  State

See also

ChangeOpBasis