Пример #1
0
def test_aspen_qubit_positions_and_distance():
    """test AspenQubit 2D position and distance calculations"""
    qubit10 = AspenQubit(1, 0)
    assert qubit10.octagon == 1
    assert qubit10.octagon_position == 0
    assert qubit10.dimension == 2

    assert np.isclose(qubit10.x, 3 + 3 / sqrt(2))
    assert np.isclose(qubit10.y, 1 + sqrt(2))
    assert np.isclose(qubit10.distance(AspenQubit(0, 7)), 3 + 2 / sqrt(2))
    assert np.isclose(qubit10.distance(AspenQubit(1, 3)), 1 + sqrt(2))

    qubit15 = AspenQubit(1, 5)
    assert np.isclose(qubit15.x, (2 + sqrt(2)))

    qubit15 = AspenQubit(1, 1)
    assert np.isclose(qubit15.x, (2 + sqrt(2)) + 1 + sqrt(2))

    with patch('cirq_rigetti.AspenQubit.octagon_position',
               new_callable=PropertyMock) as mock_octagon_position:
        mock_octagon_position.return_value = 9
        invalid_qubit = AspenQubit(0, 0)
        with pytest.raises(ValueError):
            _ = invalid_qubit.x
        with pytest.raises(ValueError):
            _ = invalid_qubit.y

    with pytest.raises(TypeError):
        _ = qubit10.distance(OctagonalQubit(0))

    with pytest.raises(ValueError):
        _ = AspenQubit(1, 9)
Пример #2
0
def test_octagonal_position_validation():
    """test OctagonalQubit validates octagon position when initialized"""
    with pytest.raises(ValueError):
        _ = OctagonalQubit(8)
Пример #3
0
def test_octagonal_qubit_positions():
    """test OctagonalQubit 2D position and distance calculations"""
    qubit0 = OctagonalQubit(0)
    assert qubit0.octagon_position == 0
    assert qubit0.dimension == 2

    qubit5 = OctagonalQubit(5)
    assert qubit5.x == 0
    assert np.isclose(qubit5.y, 1 / sqrt(2))
    assert qubit5.z == 0

    qubit3 = OctagonalQubit(3)
    assert np.isclose(qubit3.x, 1 + 1 / sqrt(2))
    assert qubit3.y == 0
    assert qubit3.z == 0

    qubit2 = OctagonalQubit(2)
    assert np.isclose(qubit2.x, 1 + sqrt(2))
    assert np.isclose(qubit2.y, 1 / sqrt(2))
    assert qubit2.z == 0

    with patch('cirq_rigetti.OctagonalQubit.octagon_position',
               new_callable=PropertyMock) as mock_octagon_position:
        mock_octagon_position.return_value = 9
        invalid_qubit = OctagonalQubit(0)
        with pytest.raises(ValueError):
            _ = invalid_qubit.x
        with pytest.raises(ValueError):
            _ = invalid_qubit.y

    qubit0 = OctagonalQubit(0)
    assert np.isclose(qubit0.distance(OctagonalQubit(1)), 1)
    assert qubit0.distance(OctagonalQubit(7)) == 1

    with pytest.raises(TypeError):
        _ = qubit0.distance(AspenQubit(0, 0))
Пример #4
0
def test_octagonal_qubit_repr():
    """test OctagonalQubit.__repr__"""
    qubit5 = OctagonalQubit(5)
    assert "cirq_rigetti.OctagonalQubit(octagon_position=5)" == repr(qubit5)
Пример #5
0
def test_octagonal_qubit_index():
    """test that OctagonalQubit properly calculates index and uses it for comparison"""
    qubit0 = OctagonalQubit(0)
    assert qubit0.index == 0
    assert OctagonalQubit(1) > qubit0
Пример #6
0
    """test RigettiQCSAspenDevice topological nodes and edges"""
    device = RigettiQCSAspenDevice(isa=qcs_aspen8_isa)

    assert len(device.qubit_topology.nodes) == 32
    assert len(device.qubit_topology.edges) == 38


@pytest.mark.parametrize(
    'qubit',
    [
        cirq.GridQubit(0, 0),
        cirq.GridQubit(1, 1),
        cirq.LineQubit(30),
        cirq.NamedQubit('33'),
        AspenQubit(3, 6),
        OctagonalQubit(6),
    ],
)
def test_rigetti_qcs_aspen_device_valid_qubit(
        qubit: cirq.Qid, qcs_aspen8_isa: InstructionSetArchitecture):
    """test RigettiQCSAspenDevice throws no error on valid qubits or operations on those qubits"""
    device = RigettiQCSAspenDevice(isa=qcs_aspen8_isa)
    device.validate_qubit(qubit)
    device.validate_operation(cirq.I(qubit))


@pytest.mark.parametrize(
    'qubit',
    [
        cirq.GridQubit(2, 2),
        cirq.LineQubit(33),