mindquantum.algorithm.compiler.tensor_product_decompose
- mindquantum.algorithm.compiler.tensor_product_decompose(gate: QuantumGate, return_u3: bool = True)[源代码]
量比特量子门的张量直积分解。
- 参数:
gate (
QuantumGate
) - 一个两比特量子门。return_u3 (bool) - 如果为
True
,则返回U3
形式的分解,否则返回UnivMathGate
形式的分解。默认值:True
。
- 返回:
Circuit
,包含两个单比特门。
样例:
>>> import numpy as np >>> import mindquantum as mq >>> from mindquantum.algorithm.compiler.decompose import tensor_product_decompose >>> g = mq.UnivMathGate('XY', np.kron(mq.X.matrix(), mq.Y.matrix())).on([0, 1]) >>> print(mq.Circuit() + g) ┏━━━━┓ q0: ──┨ ┠─── ┃ ┃ ┃ XY ┃ q1: ──┨ ┠─── ┗━━━━┛ >>> circ_decomposed = tensor_product_decompose(g) >>> print(circ_decomposed) ┏━━━━━━━━━━━━━━━━━━━━━━━━┓ q0: ──┨ U3(θ=π, φ=π/2, λ=-π/2) ┠─── ┗━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━━━━━━━━━━━━━━━━━┓ q1: ──┨ U3(θ=π, φ=0, λ=0) ┠──────── ┗━━━━━━━━━━━━━━━━━━━┛