Beispiel #1
0
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)
Beispiel #2
0
def test_to_json():
    dev = PasqalDevice(qubits=[cirq.NamedQubit('q4')])
    d = dev._json_dict_()
    assert d == {"qubits": [cirq.NamedQubit('q4')]}
    vdev = PasqalVirtualDevice(control_radius=2, qubits=[TwoDQubit(0, 0)])
    d = vdev._json_dict_()
    assert d == {"control_radius": 2, "qubits": [cirq_pasqal.TwoDQubit(0, 0)]}
Beispiel #3
0
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
Beispiel #4
0
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) == []
Beispiel #5
0
def test_decompose_operation_deprecated():
    d = generic_device(3)
    with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
        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

    with cirq.testing.assert_deprecated('decompose', deadline='v0.15'):
        assert d.decompose_operation(op) == []
Beispiel #6
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)])"
    )
Beispiel #7
0
def test_distance():
    dev = square_virtual_device(control_r=1.0, 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.0)

    dev = PasqalVirtualDevice(control_radius=1.0, qubits=[cirq.LineQubit(0), cirq.LineQubit(1)])

    assert np.isclose(dev.distance(cirq.LineQubit(0), cirq.LineQubit(1)), 1.0)

    dev = PasqalVirtualDevice(
        control_radius=1.0, qubits=[cirq.GridQubit(0, 0), cirq.GridQubit(1, 0)]
    )

    assert np.isclose(dev.distance(cirq.GridQubit(0, 0), cirq.GridQubit(1, 0)), 1.0)
Beispiel #8
0
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
Beispiel #9
0
def test_qid_pairs_deprecated():
    dev = PasqalVirtualDevice(
        1,
        qubits=[
            ThreeDQubit(0, 0, 0),
            ThreeDQubit(1, 0, 0),
            ThreeDQubit(0, 1, 0),
            ThreeDQubit(1, 1, 0),
            ThreeDQubit(1, 1, 1),
        ],
    )
    with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=2):
        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
Beispiel #10
0
def square_virtual_device(control_r, num_qubits) -> PasqalVirtualDevice:
    return PasqalVirtualDevice(control_radius=control_r,
                               qubits=TwoDQubit.square(num_qubits))