pytrax/__RandomWalk__.py
def run(self, nt=1000, nw=1, same_start=False, stride=1, num_proc=1):
        r'''
        Main run loop over nt timesteps and nw walkers.
        same_start starts all the walkers at the same spot if True and at
        different ones if False.

        Parameters
        ----------
        nt: int (default = 1000)
            the number of timesteps to run the simulation for
        nw: int (default = 1)
            he vector of the next move to be made by the walker
        same_start: bool
            determines whether to start all the walkers at the same coordinate
        stride: int
            save coordinate data every stride number of timesteps
        num_proc: int (default 1, None - uses half available)
            number of concurrent processes to start running. Please make sure
            that the run method is c a __main__ method when using
            multiprocessing.
        '''
        self.nt = int(nt)
        self.nw = int(nw)
        self.stride = stride
        record_t = int(self.nt/stride)
        # Get starts
        walkers = self._get_starts(same_start)
        if self.seed:
            # Generate a seed for each timestep
            np.random.seed(1)
            self.seeds = np.random.randint(0, self.nw, self.nt)
        real_coords = np.ndarray([record_t, self.nw, self.dim], dtype=int)
        # Default to run in parallel with half the number of available procs
        if num_proc is None:
            num_proc = int(os.cpu_count()/2)
        if num_proc > 1 and self.nw >= num_proc:
            # Run in parallel over multiple CPUs
            batches = self._chunk_walkers(walkers, num_proc)
            pool = ProcessPoolExecutor(max_workers=num_proc)
            mapped_coords = list(pool.map(self._run_walk, batches))
            pool.shutdown()
            del pool
            # Put coords back together
            si = 0
            for mc in mapped_coords:
                mnw = np.shape(mc)[1]
                real_coords[:, si: si + mnw, :] = mc.copy()
                si = si + mnw
        else:
            # Run in serial
            real_coords = np.asarray(self._run_walk(walkers.tolist()))

        self.real_coords = real_coords
r'''
        Main run loop over nt timesteps and nw walkers.
        same_start starts all the walkers at the same spot if True and at
        different ones if False.

        Parameters
        ----------
        nt: int (default = 1000)
            the number of timesteps to run the simulation for
        nw: int (default = 1)
            he vector of the next move to be made by the walker
        same_start: bool
            determines whether to start all the walkers at the same coordinate
        stride: int
            save coordinate data every stride number of timesteps
        num_proc: int (default 1, None - uses half available)
            number of concurrent processes to start running. Please make sure
            that the run method is c a __main__ method when using
            multiprocessing.
        
r'''
Main run loop over nt timesteps and nw walkers.
same_start starts all the walkers at the same spot if True and at
different ones if False.

Parameters

int (default = 1000)
the number of timesteps to run the simulation for
nw: int (default = 1)
he vector of the next move to be made by the walker
same_start: bool
determines whether to start all the walkers at the same coordinate
stride: int
save coordinate data every stride number of timesteps
num_proc: int (default 1, None - uses half available)
number of concurrent processes to start running. Please make sure
that the run method is c a __main__ method when using
multiprocessing.
r ' ' ' Main run loop over nt timesteps and nw walkers . same_start starts all the walkers at the same spot if True and at different ones if False . Parameters int ( default = 1000 ) the number of timesteps to run the simulation for nw : int ( default = 1 ) he vector of the next move to be made by the walker same_start : bool determines whether to start all the walkers at the same coordinate stride : int save coordinate data every stride number of timesteps num_proc : int ( default 1 None - uses half available ) number of concurrent processes to start running . Please make sure that the run method is c a __main__ method when using multiprocessing .
def run(self, nt=1000, nw=1, same_start=False, stride=1, num_proc=1):
        self.nt = int(nt)
        self.nw = int(nw)
        self.stride = stride
        record_t = int(self.nt/stride)
        walkers = self._get_starts(same_start)
        if self.seed:
            np.random.seed(1)
            self.seeds = np.random.randint(0, self.nw, self.nt)
        real_coords = np.ndarray([record_t, self.nw, self.dim], dtype=int)
        if num_proc is None:
            num_proc = int(os.cpu_count()/2)
        if num_proc > 1 and self.nw >= num_proc:
            batches = self._chunk_walkers(walkers, num_proc)
            pool = ProcessPoolExecutor(max_workers=num_proc)
            mapped_coords = list(pool.map(self._run_walk, batches))
            pool.shutdown()
            del pool
            si = 0
            for mc in mapped_coords:
                mnw = np.shape(mc)[1]
                real_coords[:, si: si + mnw, :] = mc.copy()
                si = si + mnw
        else:
            real_coords = np.asarray(self._run_walk(walkers.tolist()))
        self.real_coords = real_coords
def run ( self , nt = 1000 , nw = 1 , same_start = False , stride = 1 , num_proc = 1 ) : self . nt = int ( nt ) self . nw = int ( nw ) self . stride = stride record_t = int ( self . nt / stride ) walkers = self . _get_starts ( same_start ) if self . seed : np . random . seed ( 1 ) self . seeds = np . random . randint ( 0 , self . nw , self . nt ) real_coords = np . ndarray ( [ record_t , self . nw , self . dim ] , dtype = int ) if num_proc is None : num_proc = int ( os . cpu_count ( ) / 2 ) if num_proc > 1 and self . nw >= num_proc : batches = self . _chunk_walkers ( walkers , num_proc ) pool = ProcessPoolExecutor ( max_workers = num_proc ) mapped_coords = list ( pool . map ( self . _run_walk , batches ) ) pool . shutdown ( ) del pool si = 0 for mc in mapped_coords : mnw = np . shape ( mc ) [ 1 ] real_coords [ : , si : si + mnw , : ] = mc . copy ( ) si = si + mnw else : real_coords = np . asarray ( self . _run_walk ( walkers . tolist ( ) ) ) self . real_coords = real_coords
r'''
Main run loop over nt timesteps and nw walkers.
r ' ' ' Main run loop over nt timesteps and nw walkers .
r'''
        Main run loop over nt timesteps and nw walkers.
        same_start starts all the walkers at the same spot if True and at
        different ones if False.

        Parameters
        ----------
        nt: int (default = 1000)
            the number of timesteps to run the simulation for
        nw: int (default = 1)
            he vector of the next move to be made by the walker
        same_start: bool
            determines whether to start all the walkers at the same coordinate
        stride: int
            save coordinate data every stride number of timesteps
        num_proc: int (default 1, None - uses half available)
            number of concurrent processes to start running. Please make sure
            that the run method is c a __main__ method when using
            multiprocessing.
        ''' # Get starts # Generate a seed for each timestep # Default to run in parallel with half the number of available procs # Run in parallel over multiple CPUs # Put coords back together # Run in serial
self
nt
nw
same_start
stride
num_proc