mindquantum.core.circuit.QubitIDConstrain#
- class mindquantum.core.circuit.QubitIDConstrain(qubit_ids: int | List[int], add_after: bool = True)#
Select gate with qubit id in given list.
- Parameters:
qubit_ids (Union[int, List[int]]) – The qubit id list you want to select.
add_after (bool) – Whether add channel after gate or before gate. Default:
True.
Examples
>>> from mindquantum.core.circuit import MixerAdder, BitFlipAdder, QubitIDConstrain, Circuit >>> circ = Circuit().h(0).h(1).h(2).x(1, 0).x(2, 1) >>> circ ┏━━━┓ q0: ──┨ H ┠───■─────────── ┗━━━┛ ┃ ┏━━━┓ ┏━┻━┓ q1: ──┨ H ┠─┨╺╋╸┠───■───── ┗━━━┛ ┗━━━┛ ┃ ┏━━━┓ ┏━┻━┓ q2: ──┨ H ┠───────┨╺╋╸┠─── ┗━━━┛ ┗━━━┛ >>> adder = MixerAdder([ ... QubitIDConstrain([0, 1]), ... BitFlipAdder(0.1), ... ]) >>> adder(circ) ┏━━━┓ ╔═════════════╗ ╔═════════════╗ q0: ──┨ H ┠─╢ BFC(p=1/10) ╟───■───╢ BFC(p=1/10) ╟───────── ┗━━━┛ ╚═════════════╝ ┃ ╚═════════════╝ ┏━━━┓ ╔═════════════╗ ┏━┻━┓ ╔═════════════╗ q1: ──┨ H ┠─╢ BFC(p=1/10) ╟─┨╺╋╸┠─╢ BFC(p=1/10) ╟───■───── ┗━━━┛ ╚═════════════╝ ┗━━━┛ ╚═════════════╝ ┃ ┏━━━┓ ┏━┻━┓ q2: ──┨ H ┠───────────────────────────────────────┨╺╋╸┠─── ┗━━━┛ ┗━━━┛