stim_noise#
- stim_noise(stim_name, *parameters_and_qubits, pauli_string=None)[source]#
Applies a
StimNoiseGateto the given qubits.For a list of supported error instructions, please check Stims gate reference.
Some of the most common errors are listed below:
Name
Description
DEPOLARIZE1Single qubit depolarizing noise. This channel applies one of the Pauli errors X, Y, Z with probability \(p/3\).
DEPOLARIZE2Two qubit depolarizing noise. This channel applies one of the 15 non-identity two-qubit Pauli errors (IX, IY, …, ZZ) with probability \(p/15\).
X_ERRORSingle qubit Pauli-X error (Bit flip). Applies X with probability \(p\).
Y_ERRORSingle qubit Pauli-Y error. Applies Y with probability \(p\).
Z_ERRORSingle qubit Pauli-Z error (Phase flip). Applies Z with probability \(p\).
PAULI_CHANNEL_1Custom single qubit Pauli channel. Takes 3 arguments (px, py, pz) specifying the probabilities of applying X, Y, and Z errors respectively.
PAULI_CHANNEL_2Custom two qubit Pauli channel. Takes 15 arguments specifying the probabilities of applying each of the 15 non-identity two-qubit Pauli errors.
E(orCORRELATED_ERROR)Correlated Pauli error on multiple qubits (requires
pauli_stringargument). Applies the specified Pauli string with probability \(p\).ELSE_CORRELATED_ERRORSimilar to
CORRELATED_ERRORbut only applies if the previous error instruction did NOT apply an error. This allows constructing more complex conditional error models.Warning
Every noisy operation described here behaves as a purely unitary identity gate, unless the compilation target is indeed Stim (see
to_stim()). This means for instance thatto_qiskit()converts the noisy operations to trivial identity gates. The same applies to the behavior of the Qrisp simulator. In other words - the noisy operations will only behave noisy if pushed through the Stim compiler.- Parameters:
- stim_namestr
The name of the Stim error gate (e.g.
DEPOLARIZE1,X_ERROR,CORRELATED_ERROR).- *parametersfloat
The parameters of the error channel (e.g. error probability). Further details about the semantics of the parameters can be found in the Stims gate reference.
- *qubitsQubit
The qubits to apply the error channel to.
- pauli_stringstr, optional
A string of Pauli operators (e.g.
XX,IZ,Y) characterizing the error. This is required for correlated errors (e.g.E,CORRELATED_ERROR).
Examples
We construct a noisy Bell-pair using the
extract_stim()decorator.from qrisp import * from qrisp.misc.stim_tools import stim_noise @extract_stim def generate_noisy_bell_pair(): qv = QuantumVariable(2) h(qv[0]) cx(qv[0], qv[1]) # Add single qubit noise stim_noise("X_ERROR", 0.1, qv[0]) stim_noise("X_ERROR", 0.1, qv[1]) # Add correlated multi-qubit noise stim_noise("E", 0.1, qv[0], qv[1], pauli_string = "XX") return measure(qv) # Generate result indices and stim circuit res_indices, stim_circuit = generate_noisy_bell_pair() # Compile sampler and sample sampler = stim_circuit.compile_sampler() all_samples = sampler.sample(1000) # Extract results through slicing samples = all_samples[:, res_indices] print(samples) # Yields: # array([[False, True], # [False, True], # [ True, True], # ..., # [ True, True], # [ True, True], # [False, False]], shape=(1000, 2))