def test_readout_noise_after_moment(): program = cirq.Circuit() qubits = cirq.LineQubit.range(3) program.append([ cirq.H(qubits[0]), cirq.CNOT(qubits[0], qubits[1]), cirq.CNOT(qubits[1], qubits[2]) ]) program.append( [ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2'), ], strategy=cirq.InsertStrategy.NEW_THEN_INLINE, ) # Use noise model to generate circuit depol_noise = ccn.DepolarizingNoiseModel(depol_prob=0.01) readout_noise = ccn.ReadoutNoiseModel(bitflip_prob=0.05) noisy_circuit = cirq.Circuit(depol_noise.noisy_moments(program, qubits)) noisy_circuit = cirq.Circuit( readout_noise.noisy_moments(noisy_circuit, qubits)) # Insert channels explicitly true_noisy_program = cirq.Circuit() true_noisy_program.append([cirq.H(qubits[0])]) true_noisy_program.append( [ cirq.DepolarizingChannel(0.01).on(q).with_tags(ops.VirtualTag()) for q in qubits ], strategy=cirq.InsertStrategy.NEW_THEN_INLINE, ) true_noisy_program.append([cirq.CNOT(qubits[0], qubits[1])]) true_noisy_program.append( [ cirq.DepolarizingChannel(0.01).on(q).with_tags(ops.VirtualTag()) for q in qubits ], strategy=cirq.InsertStrategy.NEW_THEN_INLINE, ) true_noisy_program.append([cirq.CNOT(qubits[1], qubits[2])]) true_noisy_program.append( [ cirq.DepolarizingChannel(0.01).on(q).with_tags(ops.VirtualTag()) for q in qubits ], strategy=cirq.InsertStrategy.NEW_THEN_INLINE, ) true_noisy_program.append([ cirq.BitFlipChannel(0.05).on(q).with_tags(ops.VirtualTag()) for q in qubits ]) true_noisy_program.append([ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2'), ]) assert_equivalent_op_tree(true_noisy_program, noisy_circuit)
def test_readout_noise_no_prepend(): noise_model = ccn.ReadoutNoiseModel(bitflip_prob=0.005, prepend=False) qubits = cirq.LineQubit.range(2) moment = cirq.Moment([cirq.measure(*qubits, key="meas")]) noisy_mom = noise_model.noisy_moment(moment, system_qubits=qubits) assert len(noisy_mom) == 2 assert noisy_mom[0] == moment for g in noisy_mom[1]: assert isinstance(g.gate, cirq.BitFlipChannel)