mindquantum.core.circuit.QubitNumberConstrain

View Source On Gitee
class mindquantum.core.circuit.QubitNumberConstrain(n_qubits: int, with_ctrl: bool = True, add_after: bool = True)[source]

Only add noise channel for n_qubits quantum gate.

Parameters
  • n_qubits (int) – The number qubit of quantum gate.

  • with_ctrl (bool) – Whether control qubits also contribute to n_qubits or not. Default: True.

  • add_after (bool) – Whether add channel after gate or before gate. Default: True.

Examples

>>> from mindquantum.core.circuit import QubitNumberConstrain, Circuit, BitFlipAdder, MixerAdder
>>> circ = Circuit().h(0).x(1, 0)
>>> circ
      ┏━━━┓
q0: ──┨ H ┠───■─────
      ┗━━━┛   ┃
            ┏━┻━┓
q1: ────────┨╺╋╸┠───
            ┗━━━┛
>>> adder = MixerAdder([
...     QubitNumberConstrain(2),
...     BitFlipAdder(0.1)
... ])
>>> adder(circ)
      ┏━━━┓       ╔═════════════╗
q0: ──┨ H ┠───■───╢ BFC(p=1/10) ╟───
      ┗━━━┛   ┃   ╚═════════════╝
            ┏━┻━┓ ╔═════════════╗
q1: ────────┨╺╋╸┠─╢ BFC(p=1/10) ╟───
            ┗━━━┛ ╚═════════════╝