def test_noise_from_metrics_unsupported(): # Attempt to generate a damping noise model (not yet supported). calibration = cirq.google.Calibration(_CALIBRATION_DATA) with pytest.raises(NotImplementedError, match='Gate damping is not yet supported.'): simple_noise_from_calibration_metrics(calibration=calibration, damping_noise=True)
def test_per_qubit_readout_error_from_data(): # Generate the readout error noise model from calibration data. calibration = cirq.google.Calibration(_CALIBRATION_DATA) noise_model = simple_noise_from_calibration_metrics( calibration=calibration, readout_error_noise=True) # Create the circuit and apply the noise model. qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)] program = cirq.Circuit( cirq.Moment([cirq.H(qubits[0])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]), cirq.Moment([ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2') ])) noisy_circuit = cirq.Circuit(noise_model.noisy_moments(program, qubits)) # Insert channels explicitly to construct expected output. expected_program = cirq.Circuit( cirq.Moment([cirq.H(qubits[0])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]), cirq.Moment([ cirq.BitFlipChannel(0.004).on(qubits[0]), cirq.BitFlipChannel(0.005).on(qubits[1]), cirq.BitFlipChannel(0.006).on(qubits[2]) ]), cirq.Moment([ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2') ])) _assert_equivalent_op_tree(expected_program, noisy_circuit)
def test_per_qubit_readout_decay_from_data(): # Generate the readout decay noise model from calibration data. calibration = cirq.google.Calibration(_CALIBRATION_DATA) noise_model = simple_noise_from_calibration_metrics( calibration=calibration, readout_decay_noise=True) # Create the circuit and apply the noise model. qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)] program = cirq.Circuit( cirq.Moment([cirq.H(qubits[0])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]), cirq.Moment([ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2') ])) noisy_circuit = cirq.Circuit(noise_model.noisy_moments(program, qubits)) # Insert channels explicitly to construct expected output. decay_prob = [1 - exp(-1 / 0.007), 1 - exp(-1 / 0.008), 1 - exp(-1 / 0.009)] expected_program = cirq.Circuit( cirq.Moment([cirq.H(qubits[0])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]), cirq.Moment([ cirq.AmplitudeDampingChannel(decay_prob[i]).on(qubits[i]) for i in range(3) ]), cirq.Moment([ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2') ])) _assert_equivalent_op_tree(expected_program, noisy_circuit)
def test_per_qubit_depol_noise_from_data(): # Generate the depolarization noise model from calibration data. calibration = cirq.google.Calibration(_CALIBRATION_DATA) noise_model = simple_noise_from_calibration_metrics(calibration=calibration, depol_noise=True) # Create the circuit and apply the noise model. qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)] program = cirq.Circuit( cirq.Moment([cirq.H(qubits[0])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]), cirq.Moment([cirq.Z(qubits[1]).with_tags(ops.VirtualTag())]), cirq.Moment( [ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2'), ] ), ) noisy_circuit = cirq.Circuit(noise_model.noisy_moments(program, qubits)) # Insert channels explicitly to construct expected output. expected_program = cirq.Circuit( cirq.Moment([cirq.H(qubits[0])]), cirq.Moment([cirq.DepolarizingChannel(DEPOL_001).on(qubits[0])]), cirq.Moment([cirq.CNOT(qubits[0], qubits[1])]), cirq.Moment( [ cirq.DepolarizingChannel(DEPOL_001).on(qubits[0]), cirq.DepolarizingChannel(DEPOL_002).on(qubits[1]), ] ), cirq.Moment([cirq.CNOT(qubits[0], qubits[2])]), cirq.Moment( [ cirq.DepolarizingChannel(DEPOL_001).on(qubits[0]), cirq.DepolarizingChannel(DEPOL_003).on(qubits[2]), ] ), cirq.Moment([cirq.Z(qubits[1]).with_tags(ops.VirtualTag())]), cirq.Moment( [ cirq.measure(qubits[0], key='q0'), cirq.measure(qubits[1], key='q1'), cirq.measure(qubits[2], key='q2'), ] ), ) _assert_equivalent_op_tree(expected_program, noisy_circuit)
def test_noise_from_metrics_requires_type(): # Attempt to generate a noise model without specifying a noise type. calibration = cirq.google.Calibration(_CALIBRATION_DATA) with pytest.raises(ValueError, match='At least one error type must be specified.'): simple_noise_from_calibration_metrics(calibration=calibration)