mindquantum.algorithm.compiler.GateReplacer
- class mindquantum.algorithm.compiler.GateReplacer(ori_example_gate: BasicGate, wanted_example_circ: Circuit)[source]
Replace given gate with given circuit.
- Parameters
Examples
>>> from mindquantum.algorithm.compiler import GateReplacer, compile_circuit >>> from mindquantum.core.circuit import Circuit >>> from mindquantum.core.gates import X >>> circ = Circuit().x(1, 0).h(1).x(1, 2) >>> circ q0: ────■───────────────── ┃ ┏━┻━┓ ┏━━━┓ ┏━━━┓ q1: ──┨╺╋╸┠─┨ H ┠─┨╺╋╸┠─── ┗━━━┛ ┗━━━┛ ┗━┳━┛ ┃ q2: ────────────────■───── >>> equivalent_cnot = Circuit().h(0).z(0, 1).h(0) >>> equivalent_cnot ┏━━━┓ ┏━━━┓ ┏━━━┓ q0: ──┨ H ┠─┨ Z ┠─┨ H ┠─── ┗━━━┛ ┗━┳━┛ ┗━━━┛ ┃ q1: ──────────■─────────── >>> compiler = GateReplacer(X.on(0, 1), equivalent_cnot) >>> compiler GateReplacer< ┏━━━┓ q0: ──┨╺╋╸┠─── ┗━┳━┛ ┃ q1: ────■───── -> ┏━━━┓ ┏━━━┓ ┏━━━┓ q0: ──┨ H ┠─┨ Z ┠─┨ H ┠─── ┗━━━┛ ┗━┳━┛ ┗━━━┛ ┃ q1: ──────────■─────────── > >>> compile_circuit(compiler, circ) q0: ──────────■─────────────────────────────────── ┃ ┏━━━┓ ┏━┻━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ ┏━━━┓ q1: ──┨ H ┠─┨ Z ┠─┨ H ┠─┨ H ┠─┨ H ┠─┨ Z ┠─┨ H ┠─── ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━┳━┛ ┗━━━┛ ┃ q2: ──────────────────────────────────■───────────
- do(dag_circuit: DAGCircuit)[source]
Do gate replacer rule.
- Parameters
dag_circuit (
DAGCircuit
) – The DAG of quantum circuit you want to compile.