Пример #1
0
def test_qubit_id_accepted_using_add_edge():
    m = Matching()
    m.add_edge(0, 1, qubit_id=0)
    m.add_edge(1, 2, qubit_id={1, 2})
    es = list(m.edges())
    expected_edges = [
        (0, 1, {'fault_ids': {0}, 'weight': 1.0, 'error_probability': -1.0}),
        (1, 2, {'fault_ids': {1, 2}, 'weight': 1.0, 'error_probability': -1.0})
    ]
    assert es == expected_edges
Пример #2
0
def test_add_edge():
    m = Matching()
    m.add_edge(0, 1)
    m.add_edge(1, 2)
    assert m.num_nodes == 3
    assert m.num_edges == 2

    m = Matching()
    m.add_edge(0, 1, weight=0.123, error_probability=0.6)
    m.add_edge(1, 2, weight=0.6, error_probability=0.3, fault_ids=0)
    m.add_edge(2, 3, weight=0.01, error_probability=0.5, fault_ids={1, 2})
    expected = [(0, 1, {'fault_ids': set(), 'weight': 0.123, 'error_probability': 0.6}),
                (1, 2, {'fault_ids': {0}, 'weight': 0.6, 'error_probability': 0.3}),
                (2, 3, {'fault_ids': {1, 2}, 'weight': 0.01, 'error_probability': 0.5})]
    assert m.edges() == expected
Пример #3
0
def test_isolated_negative_weight(nn):
    m = Matching()
    m.add_edge(0, 1, 0, 1)
    m.add_edge(1, 2, 1, -10)
    m.add_edge(2, 3, 2, 1)
    m.add_edge(3, 0, 3, 1)
    c, w = m.decode([0, 1, 1, 0], return_weight=True, num_neighbours=nn)
    assert np.array_equal(c, np.array([0, 1, 0, 0]))
    assert w == -10
Пример #4
0
def test_negative_weight_repetition_code(nn):
    m = Matching()
    m.add_edge(0, 1, 0, -1)
    m.add_edge(1, 2, 1, -1)
    m.add_edge(2, 3, 2, -1)
    m.add_edge(3, 4, 3, -1)
    m.add_edge(4, 5, 4, -1)
    m.add_edge(5, 0, 5, -1)
    c, w = m.decode([0, 1, 1, 0, 0, 0], return_weight=True, num_neighbours=nn)
    assert np.array_equal(c, np.array([1, 0, 1, 1, 1, 1]))
    assert w == -5
Пример #5
0
def test_negative_weight_edge_returned():
    m = Matching()
    m.add_edge(0, 1, weight=0.5, error_probability=0.3)
    m.add_edge(1, 2, weight=0.5, error_probability=0.3, fault_ids=0)
    m.add_edge(2, 3, weight=-0.5, error_probability=0.7, fault_ids={1, 2})
    expected = [(0, 1, {
        'fault_ids': set(),
        'weight': 0.5,
        'error_probability': 0.3
    }), (1, 2, {
        'fault_ids': {0},
        'weight': 0.5,
        'error_probability': 0.3
    }), (2, 3, {
        'fault_ids': {1, 2},
        'weight': -0.5,
        'error_probability': 0.7
    })]
    assert m.edges() == expected
Пример #6
0
def test_add_edge_raises_value_error_if_qubit_id_and_fault_ids_both_supplied():
    with pytest.raises(ValueError):
        m = Matching()
        m.add_edge(0, 1, qubit_id=0, fault_ids=0)
        m.add_edge(1, 2, qubit_id=1, fault_ids=1)