def test_force_edge_active_move_calls_force_edge_active(): q00 = GridQubit(0, 0) q01 = GridQubit(0, 1) q10 = GridQubit(1, 0) q11 = GridQubit(1, 1) q02 = GridQubit(0, 2) q12 = GridQubit(1, 2) device = _create_device([q00, q01, q10, q11, q02, q12]) search = AnnealSequenceSearch(device, seed=0xF00D0008) with mock.patch.object(search, '_force_edge_active') as force_edge_active: solution = search._create_initial_solution() search._force_edge_active_move(solution) force_edge_active.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY) _, args, _ = force_edge_active.mock_calls[0] seqs, edge, _ = args # Verify that edge is not active edge, on some sequence. for seq in seqs: for i in range(1, len(seq)): assert not (seq[i - 1] == edge[0] and seq[i] == edge[1]) assert not (seq[i - 1] == edge[1] and seq[i] == edge[0]) # Verify that edge is a valid edge assert edge[0] in chip_as_adjacency_list(device)[edge[1]]
def test_force_edge_active_move_does_not_change_input(): q00 = GridQubit(0, 0) q01 = GridQubit(0, 1) q10 = GridQubit(1, 0) q11 = GridQubit(1, 1) search = AnnealSequenceSearch(_create_device([q00, q01, q10, q11]), seed=0xF00D0006) seqs, edges = search._create_initial_solution() seqs_copy, edges_copy = list(seqs), edges.copy() search._force_edge_active_move((seqs, edges)) assert seqs_copy == seqs assert edges_copy == edges
def test_force_edge_active_move_quits_when_no_free_edge(): q00 = GridQubit(0, 0) q01 = GridQubit(0, 1) search = AnnealSequenceSearch(_create_device([q00, q01]), seed=0xF00D0007) seqs, edges = search._create_initial_solution() assert search._force_edge_active_move((seqs, edges)) == (seqs, edges)