mindquantum.algorithm.compiler.kak_decompose
- mindquantum.algorithm.compiler.kak_decompose(gate: QuantumGate, return_u3: bool = True)[source]
KAK decomposition (CNOT basis) of an arbitrary two-qubit gate.
For more detail, please refer to An Introduction to Cartan’s KAK Decomposition for QC Programmers.
- Parameters
gate (
QuantumGate
) – 2-qubit quantum gate.return_u3 (bool) – return gates in form of
U3
ifTrue
, otherwise returnUnivMathGate
. Default:True
.
- Returns
Circuit
, including at most 3 CNOT gates and 6 single-qubit gates.
Examples
>>> 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) ┠─── ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛