mindquantum.algorithm.compiler.ccx_decompose

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

Decompose a toffoli gate.

Parameters

gate (XGate) – a XGate with two control qubits.

Returns

List[Circuit], all possible decompose solution.

Examples

>>> from mindquantum.algorithm.compiler.decompose import ccx_decompose
>>> from mindquantum.core.circuit import Circuit
>>> from mindquantum.core.gates import X
>>> ccx = X.on(2, [0,1])
>>> origin_circ = Circuit() + ccx
>>> decomposed_circ = ccx_decompose(ccx)[0]
>>> origin_circ
q0: ────■─────


q1: ────■─────

      ┏━┻━┓
q2: ──┨╺╋╸┠───
      ┗━━━┛
>>> decomposed_circ
                                           ┏━━━┓        ┏━━━┓ ┏━━━━┓ ┏━━━┓
q0: ──────────■────────────────────────■───┨ T ┠────────┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠───
              ┃                        ┃   ┗━━━┛        ┗━┳━┛ ┗━━━━┛ ┗━┳━┛
              ┃                        ┃                  ┃   ┏━━━┓    ┃
q1: ──────────╂────────────■───────────╂────────────■─────■───┨ T ┠────■─────
              ┃            ┃           ┃            ┃         ┗━━━┛
      ┏━━━┓ ┏━┻━┓ ┏━━━━┓ ┏━┻━┓ ┏━━━┓ ┏━┻━┓ ┏━━━━┓ ┏━┻━┓ ┏━━━┓ ┏━━━┓
q2: ──┨ H ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠─┨ T ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠─┨ T ┠─┨ H ┠──────────
      ┗━━━┛ ┗━━━┛ ┗━━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛