1# Copyright 2019 The Cirq Developers 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import pytest 16 17import cirq 18 19from cirq_aqt import AQTSimulator 20from cirq_aqt.aqt_device import get_aqt_device 21from cirq_aqt.aqt_device import AQTNoiseModel 22 23 24def test_simulator_no_circ(): 25 with pytest.raises(RuntimeError): 26 sim = AQTSimulator(num_qubits=1) 27 sim.simulate_samples(1) 28 29 30def test_ms_crosstalk_n_noise(): 31 num_qubits = 4 32 noise_mod = AQTNoiseModel() 33 device, qubits = get_aqt_device(num_qubits) 34 circuit = cirq.Circuit(device=device) 35 circuit.append(cirq.XX(qubits[1], qubits[2]) ** 0.5) 36 for moment in circuit.moments: 37 noisy_moment = noise_mod.noisy_moment(moment, qubits) 38 assert noisy_moment == [ 39 (cirq.XX ** 0.5).on(cirq.LineQubit(1), cirq.LineQubit(2)), 40 cirq.depolarize(p=0.01).on(cirq.LineQubit(1)), 41 cirq.depolarize(p=0.01).on(cirq.LineQubit(2)), 42 (cirq.XX ** 0.015).on(cirq.LineQubit(1), cirq.LineQubit(0)), 43 (cirq.XX ** 0.015).on(cirq.LineQubit(1), cirq.LineQubit(3)), 44 (cirq.XX ** 0.015).on(cirq.LineQubit(2), cirq.LineQubit(0)), 45 (cirq.XX ** 0.015).on(cirq.LineQubit(2), cirq.LineQubit(3)), 46 ] 47 48 49def test_x_crosstalk_n_noise(): 50 num_qubits = 4 51 noise_mod = AQTNoiseModel() 52 device, qubits = get_aqt_device(num_qubits) 53 circuit = cirq.Circuit(device=device) 54 circuit.append(cirq.Y(qubits[1]) ** 0.5) 55 circuit.append(cirq.Z(qubits[1]) ** 0.5) 56 circuit.append(cirq.X(qubits[1]) ** 0.5) 57 for moment in circuit.moments: 58 noisy_moment = noise_mod.noisy_moment(moment, qubits) 59 assert noisy_moment == [ 60 (cirq.X ** 0.5).on(cirq.LineQubit(1)), 61 cirq.depolarize(p=0.001).on(cirq.LineQubit(1)), 62 (cirq.X ** 0.015).on(cirq.LineQubit(0)), 63 (cirq.X ** 0.015).on(cirq.LineQubit(2)), 64 ] 65