qml.transforms.match_controlled_iX_gate

match_controlled_iX_gate(tape, num_controls=1)[source]

Quantum transform to replace controlled iX gates with their equivalent circuit.

A controlled-iX gate is a controlled-S and a Toffoli. The equivalence used is given in Giles, Brett, and Peter Selinger. “Exact Synthesis of Multiqubit Clifford+T Circuits”, arXiv:1212.0506, arXiv, 2013. doi:10.48550/arXiv.1212.0506.

Note

This transform will also replace any subcircuits from the full pattern (composed of the controlled iX gate and its decomposition) that can replaced by the rest of the pattern.

Parameters:
  • tape (QNode or QuantumScript or Callable) – A quantum circuit.

  • num_controls (int) – The number of controls on the CS gate.

Returns:

The transformed circuit as described in qml.transform.

Return type:

qnode (QNode) or quantum function (Callable) or tuple[List[.QuantumScript], function]

Example

Consider the following quantum function:

from functools import partial
import pennylane as qml

@partial(qml.transforms.match_controlled_iX_gate, num_controls=2)
@qml.qnode(qml.device("default.qubit"))
def circuit():
    qml.Hadamard(wires=0)
    qml.Hadamard(wires=1)
    qml.X(0)

    # begin multi-controlled iX gate

    qml.ctrl(qml.S(wires=[2]), control=[0, 1])
    qml.MultiControlledX(wires=[0, 1, 2, 3])

    # end multi-controlled iX gate

    qml.Hadamard(wires=1)
    qml.X(0)

    return qml.expval(qml.Z(0))

The circuit (containing a controlled iX gate) before decomposition:

>>> print(qml.draw(circuit, level=0)())
0: ──H──X─╭●─╭●──X─┤  <Z>
1: ──H────├●─├●──H─┤
2: ───────╰S─├●────┤
3: ──────────╰X────┤

The multi-controlled iX gate is replaced after the transform:

>>> print(qml.draw(circuit, level=1)())
0: ──H──X────────╭●───────────╭●──X─┤  <Z>
1: ──H───────────├●───────────├●──H─┤
2: ────────╭●────│──────╭●────│─────┤
3: ──H──T†─╰X──T─╰X──T†─╰X──T─╰X──H─┤