mindquantum.algorithm.compiler.cswap_decompose

View Source On Gitee
mindquantum.algorithm.compiler.cswap_decompose(gate: gates.SWAPGate)[source]

Decompose controlled SWAPGate gate.

Parameters

gate (SWAPGate) – a SWAPGate with one control qubit.

Returns

List[Circuit], all possible decompose solution.

Examples

>>> from mindquantum.algorithm.compiler.decompose import cswap_decompose
>>> from mindquantum.core import Circuit, SWAP
>>> cswap = SWAP.on([1, 2], 0)
>>> origin_circ = Circuit() + cswap
>>> decomposed_circ = cswap_decompose(cswap)[0]
>>> origin_circ
q0: ──■───


q1: ──╳───


q2: ──╳───
>>> decomposed_circ
q0: ──────────■───────────

      ┏━━━┓   ┃   ┏━━━┓
q1: ──┨╺╋╸┠───■───┨╺╋╸┠───
      ┗━┳━┛   ┃   ┗━┳━┛
        ┃   ┏━┻━┓   ┃
q2: ────■───┨╺╋╸┠───■─────
            ┗━━━┛