mindquantum.algorithm.compiler.tensor_product_decompose

View Source On Gitee
mindquantum.algorithm.compiler.tensor_product_decompose(gate: QuantumGate, return_u3: bool = True)[source]

Tensor product decomposition of a 2-qubit gate.

Parameters
  • gate (QuantumGate) – 2-qubit gate composed by tensor product.

  • return_u3 (bool) – return gates in form of U3 if True, otherwise return UnivMathGate. Default: True.

Returns

Circuit, including two single-qubit gates.

Examples

>>> 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) ┠────────
      ┗━━━━━━━━━━━━━━━━━━━┛