Ejemplo n.º 1
0
def test_normalize_edge_normalizes():
    q00, q01 = GridQubit(0, 0), GridQubit(0, 1)
    q10, q11 = GridQubit(1, 0), GridQubit(1, 1)
    search = AnnealSequenceSearch(_create_device([]), seed=0xF00D0012)

    assert search._normalize_edge((q00, q01)) == (q00, q01)
    assert search._normalize_edge((q01, q00)) == (q00, q01)

    assert search._normalize_edge((q01, q10)) == (q01, q10)
    assert search._normalize_edge((q10, q01)) == (q01, q10)

    assert search._normalize_edge((q00, q11)) == (q00, q11)
    assert search._normalize_edge((q11, q00)) == (q00, q11)
Ejemplo n.º 2
0
def _verify_valid_state(qubits: List[GridQubit], state: _STATE):
    seqs, edges = state
    search = AnnealSequenceSearch(_create_device(qubits), seed=0xF00D0014)
    c_adj = chip_as_adjacency_list(_create_device(qubits))

    # Check if every edge is normalized
    for e in edges:
        assert search._normalize_edge(e) == e

    # Check if every edge is valid
    for n0, n1 in edges:
        assert n0 in c_adj[n1]

    # Check if every edge is present
    for n0 in c_adj:
        for n1 in c_adj[n0]:
            assert (n0, n1) in edges or (n1, n0) in edges
            assert (n0, n1) in edges or (n1, n0) in edges

    c_set = set(qubits)

    # Check if every node in the sequences appears exactly once
    for seq in seqs:
        for n in seq:
            c_set.remove(n)

    # Check that no node is missing
    assert not c_set