mindquantum.algorithm.compiler.compile_circuit
- mindquantum.algorithm.compiler.compile_circuit(compiler: BasicCompilerRule, circ: Circuit)[source]
Directly compile a given circuit and return the result.
- Parameters
compiler (
BasicCompilerRule
) – compile rules.circ (
Circuit
) – the input quantum circuit.
- 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 ┠────■───── ┗━━━┛