mindquantum.algorithm.compiler.swap_decompose

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

Decompose SWAPGate gate.

Parameters

gate (SWAPGate) – A SWAPGate gate.

Returns

List[Circuit], All possible decompose solution.

Examples

>>> from mindquantum.algorithm.compiler.decompose import swap_decompose
>>> from mindquantum.core.circuit import Circuit
>>> from mindquantum.core.gates import SWAP
>>> swap = SWAP.on([1, 0])
>>> origin_circ = Circuit() + swap
>>> decomposed_circ = swap_decompose(swap)[0]
>>> origin_circ
q0: ──╳───


q1: ──╳───
>>> decomposed_circ
      ┏━━━┓       ┏━━━┓
q0: ──┨╺╋╸┠───■───┨╺╋╸┠───
      ┗━┳━┛   ┃   ┗━┳━┛
        ┃   ┏━┻━┓   ┃
q1: ────■───┨╺╋╸┠───■─────
            ┗━━━┛