I have two questions about error channels used in Cirq to model noise quantum circuits. The first one is that for the deplorizing error model, one common setting is to set larger error rates for two-qubit gates, such as the CNOT gate, and lower error rates for sigle-qubit gates. How can one achieve that using Cirq?

The second question is after constructing a specific quantum circuit. How to combine two types of error models in the Noise class? Though the offical document have discussed combine multiple errors, but the errors added in the process of constructing the quantum circuits, which are not often the case, especially when one use specific circuit module provided by some pakages.


1 Answer 1


The way to do this is to use the cirq.NoiseModel class. For your example, you would want to implement a class that sub-classes this class and implements the noisy_operation method:

import cirq

class MyNoiseModel(cirq.NoiseModel):

    def __init__(self, one_qubit_error_rate, two_qubit_error_rate):
        self._one_qubit_error_rate = one_qubit_error_rate
        self._two_qubit_error_rate = two_qubit_error_rate

    def noisy_operation(self, op):        
        n_qubits = len(op.qubits)
        if n_qubits > 2:
            return op
        error_rate = self._one_qubit_error_rate if n_qubits == 1 else self._two_qubit_error_rate
        depolarize_channel = cirq.depolarize(error_rate, n_qubits=n_qubits)
        return [op, depolarize_channel.on(*op.qubits)]

The noisy_operation method takes an operator, which is the operator to which noise is being added, and then can return anything that can be flattened to a list of operators, here we return the original operation followed by an appropriate depolarizing operation.

Then you can use your noise model in simulation like

noise_model = MyNoiseModel(one_qubit_error_rate=0.01, two_qubit_error_rate=0.1)
sim = cirq.Simulator(noise=noise_model)

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit([cirq.H(q0), cirq.CX(q0, q1), cirq.measure(q0, q1)])
sim.run(circuit, repetitions=10)

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.