mindquantum.algorithm.compiler.DecomposeU3

View Source On Gitee
class mindquantum.algorithm.compiler.DecomposeU3(method='standard')[source]

Decompose U3 gate into a sequence of Z-X-Z-X-Z rotations.

The decomposition follows one of two methods: 1. standard: U3(θ,φ,λ) = Rz(φ)Rx(-π/2)Rz(θ)Rx(π/2)Rz(λ) 2. alternative: U3(θ,φ,λ) = Rz(φ)Rx(π/2)Rz(π-θ)Rx(π/2)Rz(λ-π)

Parameters

method (str) – The decomposition method to use, either 'standard' or 'alternative'. Default: 'standard'

Examples

>>> 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)[source]

Execute U3 gate decomposition rule.

Parameters

dag_circuit (DAGCircuit) – DAG graph of quantum circuit.

Returns

bool, True if any decomposition was performed, False otherwise.