def place_line(self, device: 'cirq_google.GridDevice', length: int) -> GridQubitLineTuple: """Runs line sequence search. Args: device: Chip description. length: Required line length. Returns: Linear sequences found on the chip. Raises: ValueError: If search algorithm passed on initialization is not recognized. """ if not device.metadata.qubit_set: return GridQubitLineTuple() start: GridQubit = cast(GridQubit, min(device.metadata.qubit_set)) sequences: List[LineSequence] = [] greedy_search: Dict[str, List[GreedySequenceSearch]] = { 'minimal_connectivity': [_PickFewestNeighbors(device, start)], 'largest_area': [_PickLargestArea(device, start)], 'best': [_PickFewestNeighbors(device, start), _PickLargestArea(device, start)], } algos = greedy_search.get(self.algorithm) if algos is None: raise ValueError(f"Unknown greedy search algorithm {self.algorithm}") for algorithm in algos: sequences.append(algorithm.get_or_search()) return GridQubitLineTuple.best_of(sequences, length)
def place_line(self, device: 'cirq_google.XmonDevice', length: int) -> GridQubitLineTuple: """Runs line sequence search. Args: device: Chip description. length: Required line length. Returns: List of linear sequences on the chip found by simulated annealing method. """ seqs = AnnealSequenceSearch(device, self.seed).search(self.trace_func) return GridQubitLineTuple.best_of(seqs, length)
def test_best_of_gets_longest_needs_minimum(): q00 = cirq.GridQubit(0, 0) q01 = cirq.GridQubit(0, 1) assert GridQubitLineTuple.best_of([[]], 0) == () assert GridQubitLineTuple.best_of([[], [q00]], 0) == () assert GridQubitLineTuple.best_of([[q00], []], 0) == () assert GridQubitLineTuple.best_of([[], [q00]], 1) == (q00, ) assert GridQubitLineTuple.best_of([[q00], []], 1) == (q00, ) assert GridQubitLineTuple.best_of([[q00, q01], [q00]], 1) == (q00, ) assert GridQubitLineTuple.best_of([[q00, q01], [q00]], 2) == (q00, q01) assert GridQubitLineTuple.best_of([[q00, q01]], 2) == (q00, q01) assert GridQubitLineTuple.best_of([], 0) == () with pytest.raises(NotFoundError): _ = GridQubitLineTuple.best_of([[]], 1) with pytest.raises(NotFoundError): _ = GridQubitLineTuple.best_of([[q00]], 2)