mindquantum.algorithm.compiler.BasicDecompose

View Source On Gitee
class mindquantum.algorithm.compiler.BasicDecompose(prefer_u3=False)[source]

Decompose gate into a simple gate set.

This decompose rule decompose multiple control gate, customized matrix gate and rotation gate with multi pauli word.

Parameters

prefer_u3 (bool) – whether prefer to use U3 gate to decompose gate. Default: False.

Examples

>>> from mindquantum.algorithm.compiler import BasicDecompose, DAGCircuit
>>> from mindquantum.core import gates as G
>>> from mindquantum.core.circuit import Circuit
>>> circ = Circuit([G.Rxx('a').on([0, 1]), G.X(0, [1, 2])])
>>> circ
      ┏━━━━━━━━┓ ┏━━━┓
q0: ──┨        ┠─┨╺╋╸┠───
      ┃        ┃ ┗━┳━┛
      ┃ Rxx(a) ┃   ┃
q1: ──┨        ┠───■─────
      ┗━━━━━━━━┛   ┃

q2: ───────────────■─────
>>> dag_circ = DAGCircuit(circ)
>>> compiler = BasicDecompose()
>>> compiler.do(dag_circ)
>>> dag_circ.to_circuit()
      ┏━━━┓                       ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━━┓
q0: ──┨ H ┠───■───────────────■───┨ H ┠─┨ H ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠─┨ T ┠─┨╺╋╸┠─┨ T† ┠─↯─
      ┗━━━┛   ┃               ┃   ┗━━━┛ ┗━━━┛ ┗━┳━┛ ┗━━━━┛ ┗━┳━┛ ┗━━━┛ ┗━┳━┛ ┗━━━━┛
      ┏━━━┓ ┏━┻━┓ ┏━━━━━━━┓ ┏━┻━┓ ┏━━━┓         ┃            ┃           ┃
q1: ──┨ H ┠─┨╺╋╸┠─┨ RZ(a) ┠─┨╺╋╸┠─┨ H ┠─────────■────────────╂───────────■──────────↯─
      ┗━━━┛ ┗━━━┛ ┗━━━━━━━┛ ┗━━━┛ ┗━━━┛                      ┃

q2: ─────────────────────────────────────────────────────────■──────────────────────↯─
      ┏━━━┓ ┏━━━┓ ┏━━━┓
q0: ──┨╺╋╸┠─┨ T ┠─┨ H ┠────────────────
      ┗━┳━┛ ┗━━━┛ ┗━━━┛
        ┃   ┏━━━┓ ┏━━━┓ ┏━━━━┓ ┏━━━┓
q1: ────╂───┨ T ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠───
        ┃   ┗━━━┛ ┗━┳━┛ ┗━━━━┛ ┗━┳━┛
        ┃           ┃   ┏━━━┓    ┃
q2: ────■───────────■───┨ T ┠────■─────
                        ┗━━━┛
do(dag_circuit: DAGCircuit)[source]

Do control decompose rule and multi qubit gate decomposition.

Parameters

dag_circuit (DAGCircuit) – The DAG graph of quantum circuit.