def test_init_errors(): line = cirq.devices.LineQubit.range(3) with pytest.raises(TypeError, match="Unsupported qubit type"): PasqalDevice(qubits=line) with pytest.raises(ValueError, match="Too many qubits"): generic_device(101) with pytest.raises(TypeError, match="Unsupported qubit type"): PasqalVirtualDevice(control_radius=1.0, qubits=[cirq.NamedQubit('q0')]) with pytest.raises(TypeError, match="All qubits must be of same type."): PasqalVirtualDevice(control_radius=1.0, qubits=[TwoDQubit(0, 0), cirq.GridQubit(1, 0)]) with pytest.raises( ValueError, match="Control_radius needs to be a non-negative float"): square_virtual_device(control_r=-1.0, num_qubits=2) with pytest.raises( ValueError, match="Control_radius cannot be larger than " "3 times the minimal distance between qubits.", ): square_virtual_device(control_r=11.0, num_qubits=2)
def test_value_equal(): dev = PasqalDevice(qubits=[cirq.NamedQubit('q1')]) assert PasqalDevice(qubits=[cirq.NamedQubit('q1')]) == dev dev = PasqalVirtualDevice(control_radius=1.0, qubits=[TwoDQubit(0, 0)]) assert PasqalVirtualDevice(control_radius=1.0, qubits=[TwoDQubit(0, 0)]) == dev
def test_decompose_operation(): d = generic_device(3) for op in d.decompose_operation((cirq.CCZ**1.5).on(*(d.qubit_list()))): d.validate_operation(op) p_qubits = [cirq.LineQubit(3), cirq.LineQubit(4)] d = PasqalVirtualDevice(1.0, p_qubits) op = (cirq.ops.CNOT).on(*(d.qubit_list()))**2 assert d.decompose_operation(op) == []
def test_to_json(): dev = PasqalDevice(qubits=[cirq.NamedQubit('q4')]) d = dev._json_dict_() assert d == { "cirq_type": "PasqalDevice", "qubits": [cirq.NamedQubit('q4')] } vdev = PasqalVirtualDevice(control_radius=2, qubits=[TwoDQubit(0, 0)]) d = vdev._json_dict_() assert d == { "cirq_type": "PasqalVirtualDevice", "control_radius": 2, "qubits": [cirq.pasqal.TwoDQubit(0, 0)], }
def test_repr(): assert repr(generic_device(1)) == ( "pasqal.PasqalDevice(qubits=[cirq.NamedQubit('q0')])") dev = PasqalVirtualDevice(control_radius=1.0, qubits=[TwoDQubit(0, 0)]) assert repr(dev) == ( "pasqal.PasqalVirtualDevice(control_radius=1.0, qubits=[pasqal.TwoDQubit(0, 0)])" )
def test_distance(): dev = square_virtual_device(control_r=1., num_qubits=2) with pytest.raises(ValueError, match="Qubit not part of the device."): dev.distance(TwoDQubit(0, 0), TwoDQubit(2, 2)) assert np.isclose(dev.distance(TwoDQubit(0, 0), TwoDQubit(1, 0)), 1.) dev = PasqalVirtualDevice(control_radius=1., qubits=[cirq.LineQubit(0), cirq.LineQubit(1)]) assert np.isclose(dev.distance(cirq.LineQubit(0), cirq.LineQubit(1)), 1.) dev = PasqalVirtualDevice( control_radius=1., qubits=[cirq.GridQubit(0, 0), cirq.GridQubit(1, 0)]) assert np.isclose(dev.distance(cirq.GridQubit(0, 0), cirq.GridQubit(1, 0)), 1.)
def test_qid_pairs(): dev = PasqalVirtualDevice( 1, qubits=[ ThreeDQubit(0, 0, 0), ThreeDQubit(1, 0, 0), ThreeDQubit(0, 1, 0), ThreeDQubit(1, 1, 0), ThreeDQubit(1, 1, 1), ], ) assert len(dev.qid_pairs()) == 5 dev1 = PasqalVirtualDevice( 5, qubits=[ TwoDQubit(0, 0), TwoDQubit(3, 2), TwoDQubit(3, 4), TwoDQubit(3, 6), ], ) assert len(dev1.qid_pairs()) == 5
def square_virtual_device(control_r, num_qubits) -> PasqalVirtualDevice: return PasqalVirtualDevice(control_radius=control_r, qubits=TwoDQubit.square(num_qubits))