def test_full_factory(self): coupling = CouplingMap.from_full(4) edges = coupling.get_edges() expected = [ (0, 1), (0, 2), (0, 3), (1, 0), (1, 2), (1, 3), (2, 0), (2, 1), (2, 3), (3, 0), (3, 1), (3, 2), ] self.assertEqual(set(edges), set(expected))
def __init__( self, coupling_map: CouplingMap, from_layout: Union[Layout, str], to_layout: Union[Layout, str], seed: Union[int, np.random.default_rng] = None, trials=4, ): """LayoutTransformation initializer. Args: coupling_map (CouplingMap): Directed graph representing a coupling map. from_layout (Union[Layout, str]): The starting layout of qubits onto physical qubits. If the type is str, look up `property_set` when this pass runs. to_layout (Union[Layout, str]): The final layout of qubits on physical qubits. If the type is str, look up `property_set` when this pass runs. seed (Union[int, np.random.default_rng]): Seed to use for random trials. trials (int): How many randomized trials to perform, taking the best circuit as output. """ super().__init__() self.from_layout = from_layout self.to_layout = to_layout if coupling_map: self.coupling_map = coupling_map graph = coupling_map.graph.to_undirected() else: self.coupling_map = CouplingMap.from_full(len(to_layout)) graph = self.coupling_map.graph.to_undirected() self.token_swapper = ApproximateTokenSwapper(graph, seed) self.trials = trials