mindquantum.simulator.NoiseBackend
- class mindquantum.simulator.NoiseBackend(base_sim: str, n_qubits: int, adder: ChannelAdderBase, seed: int = None, dtype=None)[source]
Noise simulator backend based on channel adder.
- Parameters
base_sim (str) – The simulator that supported by MindQuantum.
n_qubits (int) – The qubit number of this noise simulator.
adder (
ChannelAdderBase
) – A channel adder that can transform a circuit to noise circuit.seed (int) – A random seed. Default:
None
.dtype (mindquantum.dtype) – The data type of simulator. If
None
, it will be mindquantum.complex128. Default:None
.
Examples
>>> from mindquantum.simulator import NoiseBackend, Simulator >>> from mindquantum.core.circuit import Circuit, MeasureAccepter, MixerAdder, BitFlipAdder >>> circ = Circuit().h(0).x(1, 0).measure_all() >>> circ ┏━━━┓ ┍━━━━━━┑ q0: ──┨ H ┠───■───┤ M q0 ├─── ┗━━━┛ ┃ ┕━━━━━━┙ ┏━┻━┓ ┍━━━━━━┑ q1: ────────┨╺╋╸┠─┤ M q1 ├─── ┗━━━┛ ┕━━━━━━┙ >>> adder = MixerAdder([ ... MeasureAccepter(), ... BitFlipAdder(0.2), ... ], add_after=False) >>> adder(circ) ┏━━━┓ ╔════════════╗ ┍━━━━━━┑ q0: ──┨ H ┠───■───╢ BFC(p=1/5) ╟─┤ M q0 ├─── ┗━━━┛ ┃ ╚════════════╝ ┕━━━━━━┙ ┏━┻━┓ ╔════════════╗ ┍━━━━━━┑ q1: ────────┨╺╋╸┠─╢ BFC(p=1/5) ╟─┤ M q1 ├─── ┗━━━┛ ╚════════════╝ ┕━━━━━━┙ >>> noise_sim = Simulator(NoiseBackend('mqvector', 2, adder=adder)) >>> noise_sim.sampling(circ,seed=42, shots=5000) shots: 5000 Keys: q1 q0│0.00 0.085 0.17 0.255 0.34 0.425 ───────────┼───────────┴───────────┴───────────┴───────────┴───────────┴ 00│▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ │ 01│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ │ 10│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ │ 11│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ │ {'00': 1701, '01': 796, '10': 804, '11': 1699}