I'm trying to apply depolarization error on a 2-qubit circuit using the Qiskit Aer noise module. My question is how can I apply the depolarization error to each of the qubits in my circuit? Does the error also apply to 2-qubit gates?

From this tutorial, we can apply the 'same error to any occurrence of an instruction'. My understanding is if we apply the All-qubit quantum error, the same depolarization error will occur on each of the qubits: $$ \mathcal{E}(\rho) = \frac{pI}{2^n}\text{Tr}(\rho)+(1-p)\rho,\quad\text{where} \quad\rho \equiv\sum_ip_i|\psi_i\rangle\langle\psi_i|. $$ Thus the uniform X, Y, and Z errors are applied to each of them separately. The qiskit code is

# Create an empty noise model
noise_model = NoiseModel()

# Add depolarizing error to all single qubit u1, u2, u3 gates
error = depolarizing_error(0.05, 1)
noise_model.add_all_qubit_quantum_error(error, ['u1', 'u2', 'u3'])

# Print noise model info

However, as this post suggests, a two-qubit depolarizing error would apply one of IX, IY, IZ, XI, XX, XY, XZ, YI, YX, YY, YZ, ZI, ZX, ZY, or ZZ chosen uniformly at random. If we apply the code above on a 2-qubit circuit, are we really applying the error as we are expecting? Also, as specified in noise_model.add_all_qubit_quantum_error(error, ['u1', 'u2', 'u3']), if there's a CNOT gate on my circuit, will the depolarization error affect this 2-qubit gate?



1 Answer 1


If you like to add a 2-qubit error to CNOT gates, you have to create a depolarizing error with err = depolarizing_error(param, num_qubits=2) which you may add to your noise model by noise_model.add_all_qubit_quantum_error(err, 'cx').

If you take a look at the source you find that it creates the desired two qubit channel by

paulis = [Pauli("".join(tup)) for tup in it.product(['I', 'X', 'Y', 'Z'], repeat=num_qubits)]
return QuantumError(zip(paulis, probs))

EDIT: I don't know what you mean by "cu". To be honest, nobody knows all 2-qubit gates. You can create your own. A real quantum computer realizes only a few gates, typically 3 unitary gates and one cx gate. All other gates are then composed from these basis gates. So if you wish to simulate a noisy quantum computer, you have to transpile your circuit to the basis gates of the noise model. This can be done by transpile(circ, basis_gates) or directly by transpile(circ, backend), where backend may be a simulator with a noise model or much more simply a Fakebackend with a realistic noise model. That is, what happens if you want to run your circuit on a real quantum computer. It will be transferred to the basis gates of the computer, which will produce a noisy output (additive to the readout errors). You might want to study the qiskit documentation on Building Noise Models.

  • $\begingroup$ Thanks for the answer! If I want the 2-qubit error to be applied to any 2-qubit gate, should I use noise_model.add_all_qubit_quantum_error(err, 'cu') instead? (to get a more general error) $\endgroup$
    – IGY
    Commented Oct 27, 2022 at 13:40
  • $\begingroup$ u1, u2,u3, cx (CNOT) are typical basic gates. I have edited my original answer and hope that this clarifies the issue. $\endgroup$
    – siserman
    Commented Oct 29, 2022 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.