def test_minimal_sequence_search_does_not_use_used(): q00 = cirq.GridQubit(0, 0) q10 = cirq.GridQubit(1, 0) q20 = cirq.GridQubit(2, 0) q21 = cirq.GridQubit(2, 1) qubits = [q00, q10, q20, q21] search = greedy._PickFewestNeighbors(_create_device(qubits), q10) # + *-+ # # + assert search._choose_next_qubit(q10, {q00, q10}) == q20
def test_minimal_sequence_search_traverses_grid(): q00 = cirq.GridQubit(0, 0) q01 = cirq.GridQubit(0, 1) q11 = cirq.GridQubit(1, 1) q02 = cirq.GridQubit(0, 2) q03 = cirq.GridQubit(0, 3) q04 = cirq.GridQubit(0, 4) q14 = cirq.GridQubit(1, 4) q24 = cirq.GridQubit(2, 4) q05 = cirq.GridQubit(0, 5) qubits = [q00, q01, q11, q02, q03, q04, q05, q14, q24] device = _create_device(qubits) search = greedy._PickFewestNeighbors(device, q02) # (0,0)╌╌(0,1)╌╌START══(0,3)══(0,4)╌╌(0,5) # ╎ ║ # (1,1) (1,4) # ║ # (2,4) assert search._choose_next_qubit(q02, {q02}) == q03 assert search._choose_next_qubit(q03, {q02, q03}) == q04 assert search._choose_next_qubit(q04, {q02, q03, q04}) == q14 assert search._choose_next_qubit(q14, {q02, q03, q04, q14}) == q24 assert search._choose_next_qubit(q24, {q02, q03, q04, q14, q24}) is None # (0,0)╌╌(0,1)══(0,2)══(0,3)══(0,4)╌╌(0,5) # ║ ║ # (1,1) (1,4) # ║ # START assert search._choose_next_qubit(q24, {q24}) == q14 assert search._choose_next_qubit(q14, {q24, q14}) == q04 assert search._choose_next_qubit(q04, {q24, q14, q04}) == q03 assert search._choose_next_qubit(q03, {q24, q14, q04, q03}) == q02 assert search._choose_next_qubit(q02, {q24, q14, q04, q03, q02}) == q01 assert search._choose_next_qubit( q01, {q24, q14, q04, q03, q02, q01}) in [q00, q11] assert search._choose_next_qubit( q00, {q24, q14, q04, q03, q02, q01, q00}) is None assert search._choose_next_qubit( q11, {q24, q14, q04, q03, q02, q01, q11}) is None # START══(0,1)══(0,2)══(0,3)══(0,4)╌╌(0,5) # ║ # (1,4) # ║ # (2,4) qubits = [q00, q01, q02, q03, q04, q05, q14, q24] device = _create_device(qubits) method = greedy.GreedySequenceSearchStrategy('minimal_connectivity') assert method.place_line(device, 4) == (q00, q01, q02, q03) assert method.place_line(device, 7) == (q00, q01, q02, q03, q04, q14, q24) with pytest.raises(NotFoundError): _ = method.place_line(device, 8)
def test_minimal_sequence_search_returns_none_when_blocked(): q00 = cirq.GridQubit(0, 0) q10 = cirq.GridQubit(1, 0) qubits = [q00, q10] search = greedy._PickFewestNeighbors(_create_device(qubits), q10) assert search._choose_next_qubit(q10, {q00, q10}) is None
def test_minimal_sequence_search_returns_none_for_single_node(): q00 = cirq.GridQubit(0, 0) qubits = [q00] search = greedy._PickFewestNeighbors(_create_device(qubits), q00) assert search._choose_next_qubit(q00, {q00}) is None