mindquantum.algorithm.compiler.compile_circuit

View Source On Gitee
mindquantum.algorithm.compiler.compile_circuit(compiler: BasicCompilerRule, circ: Circuit)[source]

Directly compile a given circuit and return the result.

Parameters
Returns

Circuit, the final circuit compiled by given compiler.

Examples

>>> from mindquantum.algorithm.compiler import compile_circuit, BasicDecompose
>>> 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: ───────────────■─────
>>> compile_circuit(BasicDecompose(), circ)
      ┏━━━┓                       ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━━┓ ┏━━━┓
q0: ──┨ H ┠───■───────────────■───┨ H ┠─┨ H ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠─┨ T ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠─↯─
      ┗━━━┛   ┃               ┃   ┗━━━┛ ┗━━━┛ ┗━┳━┛ ┗━━━━┛ ┗━┳━┛ ┗━━━┛ ┗━┳━┛ ┗━━━━┛ ┗━┳━┛
      ┏━━━┓ ┏━┻━┓ ┏━━━━━━━┓ ┏━┻━┓ ┏━━━┓         ┃            ┃           ┃            ┃
q1: ──┨ H ┠─┨╺╋╸┠─┨ RZ(a) ┠─┨╺╋╸┠─┨ H ┠─────────■────────────╂───────────■────────────╂───↯─
      ┗━━━┛ ┗━━━┛ ┗━━━━━━━┛ ┗━━━┛ ┗━━━┛                      ┃                        ┃
                                                             ┃                        ┃
q2: ─────────────────────────────────────────────────────────■────────────────────────■───↯─
      ┏━━━┓ ┏━━━┓
q0: ──┨ T ┠─┨ H ┠────────────────
      ┗━━━┛ ┗━━━┛
      ┏━━━┓ ┏━━━┓ ┏━━━━┓ ┏━━━┓
q1: ──┨ T ┠─┨╺╋╸┠─┨ T† ┠─┨╺╋╸┠───
      ┗━━━┛ ┗━┳━┛ ┗━━━━┛ ┗━┳━┛
              ┃   ┏━━━┓    ┃
q2: ──────────■───┨ T ┠────■─────
                  ┗━━━┛