Exemple #1
0
    def run(self,
            dt,
            tf,
            t0=0.,
            distributed_configuration=utilities.NullObject()):
        '''Main iteration control loop for simulation
        
        The time step selection must be approximately of the same order as dv
        for the internal populations, if the 'approx' time stepping method is
        selected.
        
        Parameters
        ----------
        t0 : float (default=0.)
            Network start time (unit=seconds), passed to initialize call.
        tf : float (default=.1)
            Network end time (unit=seconds).
        dt : float (default=0.001)
            Time step (unit=seconds).
        '''

        self.distributed_configuration = distributed_configuration
        self.firing_rate_organizer = FiringRateOrganizer(
            self.distributed_configuration)

        self.dt = dt
        self.t0 = t0

        # Initialize:
        start_time = time.time()
        self.tf = tf
        self.ti = 0

        self.distributed_configuration.initialize(self.ti)

        # Initialize populations:
        for gid, p in enumerate(self.population_list):
            p.initialize()
            self.firing_rate_organizer.push(self.ti, gid, p.curr_firing_rate)

        self.distributed_configuration.update(
            self.ti,
            self.firing_rate_organizer.firing_rate_dict_internal[self.ti])

        for p in self.population_list:
            if isinstance(p, InternalPopulation):
                p.initialize_total_input_dict()

        # Initialize connections:
        for c in self.connection_list:
            c.initialize()
        self.initialization_time = time.time() - start_time

        # Run
        start_time = time.time()
        while self.t < self.tf:
            self.update()

        self.run_time = time.time() - start_time

        self.distributed_configuration.finalize()

        self.run_callback(self)
Exemple #2
0
    def _run(self, dt, tf, t0=0., synchronization_harness=None):
        '''Main iteration control loop for simulation
        
        The time step selection must be approximately of the same order as dv
        for the internal populations, if the 'approx' time stepping method is
        selected.
        
        Parameters
        ----------
        t0 : float (default=0.)
            Network start time (unit=seconds), passed to initialize call.
        tf : float (default=.1)
            Network end time (unit=seconds).
        dt : float (default=0.001)
            Time step (unit=seconds).
        '''

        if synchronization_harness is None:
            self.synchronization_harness = utilities.DefaultSynchronizationHarness(
            )
        else:
            self.synchronization_harness = synchronization_harness
        self.firing_rate_organizer = FiringRateOrganizer(
            self.synchronization_harness)

        self.dt = dt
        self.t0 = t0

        if not self.progress is None: self.progress.set_network(self)

        # Initialize:
        start_time = time.time()
        self.tf = tf
        self.ti = 0

        if not self.progress is None: self.progress.initialize()
        self.synchronization_harness.initialize(self.ti)

        # Initialize populations:
        for gid, p in enumerate(self.population_list):
            p.initialize()

            if self.synchronization_harness.gid_to_rank(gid) == self.rank:
                self.firing_rate_organizer.push(self.ti, gid,
                                                p.curr_firing_rate)

        self.synchronization_harness.update(
            self.ti,
            self.firing_rate_organizer.firing_rate_dict_internal.setdefault(
                self.ti, {}))

        # Initialize connections:
        for c in self.connection_list:
            c.initialize()

        for p in self.population_list:
            try:
                p.initialize_total_input_dict()
            except AttributeError:
                pass

        self.initialization_time = time.time() - start_time

        # Run
        start_time = time.time()
        while self.t < self.tf:
            self.update()

        self.run_time = time.time() - start_time

        self.synchronization_harness.finalize()
        self.shutdown()

        self.run_callback(self)