def _layout_and_route_passmanager(self, initial_layout): """Return a passmanager for a full layout and routing. We use a factory to remove potential statefulness of passes. """ layout_and_route = [SetLayout(initial_layout), FullAncillaAllocation(self.coupling_map), EnlargeWithAncilla(), ApplyLayout(), self.routing_pass] pm = PassManager(layout_and_route) return pm
def __init__( self, coupling_map, objective="depth", backend_prop=None, time_limit=30, threads=None, max_swaps_inbetween_layers=None, ): """BIPMapping initializer. Args: coupling_map (CouplingMap): Directed graph represented a coupling map. objective (str): Type of objective function: * ``'error_rate'``: [NotImplemented] Predicted error rate of the circuit * ``'depth'``: [Default] Depth (number of time-steps) of the circuit * ``'balanced'``: [NotImplemented] Weighted sum of ``'error_rate'`` and ``'depth'`` backend_prop (BackendProperties): Backend properties object time_limit (float): Time limit for solving BIP in seconds threads (int): Number of threads to be allowed for CPLEX to solve BIP max_swaps_inbetween_layers (int): Number of swaps allowed in between layers. If None, automatically set. Large value could decrease the probability to build infeasible BIP problem but also could reduce the chance of finding a feasible solution within the ``time_limit``. Raises: MissingOptionalLibraryError: if cplex or docplex are not installed. """ if not HAS_DOCPLEX or not HAS_CPLEX: raise MissingOptionalLibraryError( libname="bip-mapper", name="BIP-based mapping pass", pip_install="pip install 'qiskit-terra[bip-mapper]'", ) super().__init__() self.coupling_map = copy.deepcopy( coupling_map) # save a copy to modify if self.coupling_map is not None: self.coupling_map.make_symmetric() self.objective = objective self.backend_prop = backend_prop self.time_limit = time_limit self.threads = threads self.max_swaps_inbetween_layers = max_swaps_inbetween_layers # ensure the number of virtual and physical qubits are the same self.requires.append(TrivialLayout(self.coupling_map)) self.requires.append(FullAncillaAllocation(self.coupling_map)) self.requires.append(EnlargeWithAncilla())