mindquantum.algorithm.compiler.ccx_decompose
- mindquantum.algorithm.compiler.ccx_decompose(gate: gates.XGate)[源代码]
分解一个 toffoli 门。
样例:
>>> 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 ┠────────── ┗━━━┛ ┗━━━┛ ┗━━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛