mindquantum.algorithm.compiler.kak_decompose
- mindquantum.algorithm.compiler.kak_decompose(gate: QuantumGate, return_u3: bool = True)[源代码]
通过kak分解来分解任意的两量子比特门。
更多信息,请参考论文 An Introduction to Cartan's KAK Decomposition for QC Programmers.
- 参数:
gate (
QuantumGate
) - 只有一个控制为的单比特量子门。return_u3 (bool) - 如果为
True
,则返回U3
形式的分解,否则返回UnivMathGate
形式的分解。默认值:True
。
- 返回:
Circuit
,由6个单比特门和最多三个CNOT门构成的量子线路。
样例:
>>> import mindquantum as mq >>> from mindquantum.algorithm.compiler.decompose import kak_decompose >>> from scipy.stats import unitary_group >>> g = mq.UnivMathGate('U', unitary_group.rvs(4, random_state=123)).on([0, 1]) >>> print(mq.Circuit() + g) ┏━━━┓ q0: ──┨ ┠─── ┃ ┃ ┃ U ┃ q1: ──┨ ┠─── ┗━━━┛ >>> circ_decomposed = kak_decompose(g) >>> print(circ_decomposed) ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ q0: ──┨ U3(θ=2.2601, φ=-3.602, λ=2.4907) ┠───■───┨ U3(θ=π/2, φ=-0.2573, λ=-π) ┠───■───↯─ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓ q1: ──┨ U3(θ=1.846, φ=-2.9209, λ=0.5375) ┠─┨╺╋╸┠─┨ U3(θ=0, φ=-0.19, λ=-0.19) ┠──┨╺╋╸┠─↯─ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛ ┏━━━━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ q0: ──┨ U3(θ=π/2, φ=0, λ=π) ┠─────────■───┨ U3(θ=2.273, φ=-1.8708, λ=0.7431) ┠─── ┗━━━━━━━━━━━━━━━━━━━━━┛ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ q1: ──┨ U3(θ=0, φ=0.358, λ=0.358) ┠─┨╺╋╸┠─┨ U3(θ=2.7317, φ=1.8583, λ=0.6685) ┠─── ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛