qiskit/transpiler/passes/mapping/stochastic_swap.py
def run(self, dag):
        """
        Run the StochasticSwap pass on `dag`.

        Args:
            dag (DAGCircuit): DAG to map.

        Returns:
            DAGCircuit: A mapped DAG.

        Raises:
            TranspilerError: if the coupling map or the layout are not
            compatible with the DAG
        """

        if self.initial_layout is None:
            if self.property_set["layout"]:
                self.initial_layout = self.property_set["layout"]
            else:
                self.initial_layout = Layout.generate_trivial_layout(*dag.qregs.values())

        if len(dag.qubits()) != len(self.initial_layout):
            raise TranspilerError('The layout does not match the amount of qubits in the DAG')

        if len(self.coupling_map.physical_qubits) != len(self.initial_layout):
            raise TranspilerError(
                "Mappers require to have the layout to be the same size as the coupling map")

        self.input_layout = self.initial_layout.copy()

        self.qregs = dag.qregs
        if self.seed is None:
            self.seed = np.random.randint(0, np.iinfo(np.int32).max)
        self.rng = np.random.RandomState(self.seed)
        logger.debug("StochasticSwap RandomState seeded with seed=%s", self.seed)

        new_dag = self._mapper(dag, self.coupling_map, trials=self.trials)
        # self.property_set["layout"] = self.initial_layout
        return new_dag
def run(self, dag):
        if self.initial_layout is None:
            if self.property_set["layout"]:
                self.initial_layout = self.property_set["layout"]
            else:
                self.initial_layout = Layout.generate_trivial_layout(*dag.qregs.values())

        if len(dag.qubits()) != len(self.initial_layout):
            raise TranspilerError('The layout does not match the amount of qubits in the DAG')

        if len(self.coupling_map.physical_qubits) != len(self.initial_layout):
            raise TranspilerError(
                "Mappers require to have the layout to be the same size as the coupling map")

        self.input_layout = self.initial_layout.copy()

        self.qregs = dag.qregs
        if self.seed is None:
            self.seed = np.random.randint(0, np.iinfo(np.int32).max)
        self.rng = np.random.RandomState(self.seed)
        logger.debug("StochasticSwap RandomState seeded with seed=%s", self.seed)

        new_dag = self._mapper(dag, self.coupling_map, trials=self.trials)
        # self.property_set["layout"] = self.initial_layout
        return new_dag
def run ( self , dag ) : if self . initial_layout is None : if self . property_set [ "layout" ] : self . initial_layout = self . property_set [ "layout" ] else : self . initial_layout = Layout . generate_trivial_layout ( * dag . qregs . values ( ) ) if len ( dag . qubits ( ) ) != len ( self . initial_layout ) : raise TranspilerError ( 'The layout does not match the amount of qubits in the DAG' ) if len ( self . coupling_map . physical_qubits ) != len ( self . initial_layout ) : raise TranspilerError ( "Mappers require to have the layout to be the same size as the coupling map" ) self . input_layout = self . initial_layout . copy ( ) self . qregs = dag . qregs if self . seed is None : self . seed = np . random . randint ( 0 , np . iinfo ( np . int32 ) . max ) self . rng = np . random . RandomState ( self . seed ) logger . debug ( "StochasticSwap RandomState seeded with seed=%s" , self . seed ) new_dag = self . _mapper ( dag , self . coupling_map , trials = self . trials ) # self.property_set["layout"] = self.initial_layout return new_dag
Run the StochasticSwap pass on `dag`.

        Args:
            dag (DAGCircuit): DAG to map.

        Returns:
            DAGCircuit: A mapped DAG.

        Raises:
            TranspilerError: if the coupling map or the layout are not
            compatible with the DAG
Run the StochasticSwap pass on dag .