mindquantum.algorithm.compiler.DecomposeU3
- class mindquantum.algorithm.compiler.DecomposeU3(method='standard')[源代码]
将U3门分解为Z-X-Z-X-Z旋转序列。
分解可以遵循以下两种方法之一:
标准方法: U3(θ,φ,λ) = Rz(φ)Rx(-π/2)Rz(θ)Rx(π/2)Rz(λ)
替代方法: U3(θ,φ,λ) = Rz(φ)Rx(π/2)Rz(π-θ)Rx(π/2)Rz(λ-π)
- 参数:
method (str) - 使用的分解方法,可选'standard'或'alternative'。默认值:'standard'。
样例:
>>> from mindquantum.algorithm.compiler import DecomposeU3, DAGCircuit >>> from mindquantum.core import gates as G >>> from mindquantum.core.circuit import Circuit >>> circ = Circuit([G.U3('theta', 'phi', 'lambda').on(0)]) >>> circ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ q0: ──┨ U3(θ=theta, φ=phi, λ=lambda) ┠─── ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ >>> dag_circ = DAGCircuit(circ) >>> # Use standard decomposition method >>> compiler = DecomposeU3() >>> compiler.do(dag_circ) >>> dag_circ.to_circuit() ┏━━━━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━━━┓ ┏━━━━━━━━━━┓ ┏━━━━━━━━━┓ q0: ──┨ RZ(lambda) ┠─┨ RX(π/2) ┠─┨ RZ(theta) ┠─┨ RX(-π/2) ┠─┨ RZ(phi) ┠─── ┗━━━━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━━━┛ ┗━━━━━━━━━━┛ ┗━━━━━━━━━┛ >>> # Use alternative decomposition method >>> compiler = DecomposeU3(method='alternative') >>> compiler.do(dag_circ) >>> dag_circ.to_circuit() ┏━━━━━━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ q0: ──┨ RZ(lambda-π) ┠─┨ RX(π/2) ┠─┨ RZ(-theta + π) ┠─┨ RX(π/2) ┠─┨ RZ(phi) ┠─── ┗━━━━━━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛
- do(dag_circuit: DAGCircuit)[源代码]
执行U3门分解规则。
- 参数:
dag_circuit (
DAGCircuit
) - 量子线路的DAG图。
- 返回:
bool,如果执行了任何分解操作则返回True,否则返回False。