Example #1
0
    def do_work(self):
        """
        Work method.

        This method is repeatedly executed by the Worker instance after the
        instance receives a 'start' control message and until it receives a 'stop'
        control message.
        """

        # If the debug flag is set, don't catch exceptions so that
        # errors will lead to visible failures:
        if self.debug:

            # Run the processing step:
            self.run_step()

            # Synchronize:
            self._sync()
        else:

            # Run the processing step:
            catch_exception(self.run_step, self.log_info)

            # Synchronize:
            catch_exception(self._sync, self.log_info)
Example #2
0
    def do_work(self):
        """
        Work method.

        This method is repeatedly executed by the Worker instance after the
        instance receives a 'start' control message and until it receives a 'stop'
        control message.
        """

        # If the debug flag is set, don't catch exceptions so that
        # errors will lead to visible failures:
        if self.debug:

            # Run the processing step:
            self.run_step()

            # Synchronize:
            self._sync()
        else:

            # Run the processing step:
            catch_exception(self.run_step, self.log_info)

            # Synchronize:
            catch_exception(self._sync, self.log_info)
Example #3
0
    def main_run(self):
        self.running = True
        curr_steps = 0
        while curr_steps < self._steps:
            self.logger.info('execution step: %s' % curr_steps)
            # If the debug flag is set, don't catch exceptions so that
            # errors will lead to visible failures:
            if self.debug:

                # Get transmitted input data for processing:
                self._get_in_data()

                # Run the processing step:
                self.run_step()

                # Stage generated output data for transmission to other
                # modules:
                self._put_out_data()

                # Synchronize:
                self._sync()

            else:

                # Get transmitted input data for processing:
                catch_exception(self._get_in_data, self.logger.info)

                # Run the processing step:
                catch_exception(self.run_step, self.logger.info)

                # Stage generated output data for transmission to other
                # modules:
                catch_exception(self._put_out_data, self.logger.info)

                # Synchronize:
                catch_exception(self._sync, self.logger.info)

            # Exit run loop when a quit signal has been received:
            if not self.running:
                self.logger.info('run loop stopped')
                break

            curr_steps += 1
Example #4
0
    def main_run(self):
        self.running = True
        curr_steps = 0
        while curr_steps < self._steps:
            self.logger.info('execution step: %s' % curr_steps)
            # If the debug flag is set, don't catch exceptions so that
            # errors will lead to visible failures:
            if self.debug:

                # Get transmitted input data for processing:
                self._get_in_data()

                # Run the processing step:
                self.run_step()

                # Stage generated output data for transmission to other
                # modules:
                self._put_out_data()

                # Synchronize:
                self._sync()

            else:

                # Get transmitted input data for processing:
                catch_exception(self._get_in_data, self.logger.info)

                # Run the processing step:
                catch_exception(self.run_step, self.logger.info)

                # Stage generated output data for transmission to other
                # modules:
                catch_exception(self._put_out_data, self.logger.info)

                # Synchronize:
                catch_exception(self._sync, self.logger.info)

            # Exit run loop when a quit signal has been received:
            if not self.running:
                self.logger.info('run loop stopped')
                break

            curr_steps += 1
Example #5
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.log_info('starting')
        with IgnoreKeyboardInterrupt():

            # Initialize environment:
            self._init_net()
            
            # Initialize _out_port_dict and _in_port_dict attributes:
            self._init_port_dicts()

            # Initialize Buffer for incoming data.  Dict used to store the
            # incoming data keyed by the source module id.  Each value is a
            # queue buferring the received data:
            self._in_data = {k: collections.deque() for k in self._in_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            self.steps = 0
            if self.time_sync:
                self.sock_time.send(msgpack.packb((self.id, self.steps, 'start',
                                                   time.time())))
                self.log_info('sent start time to master')

            # Counter for number of steps between synchronizations:
            steps_since_sync = 0
            while self.steps < self.max_steps:
                self.log_info('execution step: %s/%s' % (self.steps, self.max_steps))

                # If the debug flag is set, don't catch exceptions so that
                # errors will lead to visible failures:
                if self.debug:

                    # Run the processing step:
                    self.run_step()

                    # Do post-processing:
                    self.post_run_step()

                    # Synchronize:
                    if steps_since_sync == self.sync_period:
                        self._sync()
                        steps_since_sync = 0
                    else:
                        self.log_info('skipping sync (%s/%s)' % \
                                      (steps_since_sync, self.sync_period))
                        steps_since_sync += 1

                else:

                    # Run the processing step:
                    catch_exception(self.run_step, self.log_info)

                    # Do post processing:
                    catch_exception(self.post_run_step, self.log_info)

                    # Synchronize:
                    if steps_since_sync == self.sync_period:
                        catch_exception(self._sync, self.log_info)
                        steps_since_sync = 0
                    else:
                        self.log_info('skipping sync (%s/%s)' % \
                                      (steps_since_sync, self.sync_period))
                        steps_since_sync += 1

                # Exit run loop when a quit signal has been received:
                if not self.running:
                    self.log_info('run loop stopped')
                    break

                self.steps += 1
            if self.time_sync:
                self.sock_time.send(msgpack.packb((self.id, self.steps, 'stop',
                                                   time.time())))
                self.log_info('sent stop time to master')
            self.log_info('maximum number of steps reached')

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.log_info('sent to manager: %s' % ack)
                
        self.log_info('exiting')
Example #6
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.logger.info('starting')
        with IgnoreKeyboardInterrupt():

            # Initialize environment:
            self._init_net()

            # Initialize Buffer for incoming data.
            # Dict used to store the incoming data keyed by the source module id.
            # Each value is a queue buferring the received data
            self._in_data = {k:collections.deque() for k in self.in_ids}

            # Extract indices of source ports for all modules receiving output
            # once so that they don't need to be repeatedly extracted during the
            # emulation:
            self._out_idx_dict = \
              {out_id:self._conn_dict[out_id].src_idx(self.id, out_id) for \
               out_id in self.out_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            curr_steps = 0
            while curr_steps < self._steps:
                self.logger.info('execution step: %s' % curr_steps)

                # Clear data structures for passing data to and from the
                # run_step method:
                in_dict = {}
                out = []

                # Get input data:
                catch_exception(self._get_in_data,self.logger.info,in_dict)

                # Run the processing step:
                catch_exception(self.run_step,self.logger.info,in_dict, out)

                # Prepare the generated data for output:
                catch_exception(self._put_out_data,self.logger.info,out)

                # Synchronize:
                catch_exception(self._sync,self.logger.info)

                # Exit run loop when a quit message has been received:
                if not self.running:
                    self.logger.info('run loop stopped')
                    break

                curr_steps += 1

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.logger.info('sent to manager: %s' % ack)

        self.logger.info('exiting')
Example #7
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.logger.info('starting')
        with IgnoreKeyboardInterrupt():

            # Initialize environment:
            self._init_net()
            self._init_gpu()

            # Extract indices of source ports for all modules receiving output
            # once so that they don't need to be repeatedly extracted during the
            # simulation:
            self._out_idx_dict['gpot'] = \
              {out_id:self._conn_dict[out_id].src_idx(self.id, out_id, 'gpot') for \
               out_id in self.out_ids}
            self._out_idx_dict['spike'] = \
              {out_id:self._conn_dict[out_id].src_idx(self.id, out_id, 'spike') for \
               out_id in self.out_ids}

            # Initialize Buffer for incoming data.
            # Dict used to store the incoming data keyed by the source module id.
            # Each value is a queue buferring the received data
            self._in_data = {k: collections.deque() for k in self.in_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            curr_steps = 0
            while curr_steps < self._steps:
                self.logger.info('execution step: %s' % curr_steps)

                # Clear data structures for passing data to and from the
                # run_step method:
                in_gpot_dict = {}
                in_spike_dict = {}
                out_gpot = []
                out_spike = []

                # If the debug flag is set, don't catch exceptions so that
                # errors will lead to visible failures:
                if self.debug:

                    # Get transmitted input data for processing:
                    self._get_in_data(in_gpot_dict, in_spike_dict)

                    # Run the processing step:
                    self.run_step(in_gpot_dict, in_spike_dict, out_gpot,
                                  out_spike)

                    # Stage generated output data for transmission to other
                    # modules:
                    self._put_out_data(out_gpot, out_spike)

                    # Synchronize:
                    self._sync()

                else:

                    # Get transmitted input data for processing:
                    catch_exception(self._get_in_data, self.logger.info,
                                    in_gpot_dict, in_spike_dict)

                    # Run the processing step:
                    catch_exception(self.run_step, self.logger.info,
                                    in_gpot_dict, in_spike_dict, out_gpot,
                                    out_spike)

                    # Stage generated output data for transmission to other
                    # modules:
                    catch_exception(self._put_out_data, self.logger.info,
                                    out_gpot, out_spike)

                    # Synchronize:
                    catch_exception(self._sync, self.logger.info)

                # Exit run loop when a quit signal has been received:
                if not self.running:
                    self.logger.info('run loop stopped')
                    break

                curr_steps += 1

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.logger.info('sent to manager: %s' % ack)

        self.logger.info('exiting')
Example #8
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.logger.info('starting')
        with IgnoreKeyboardInterrupt():
            # Initialize environment:
            self._init_net()

            # Initialize _out_port_dict and _in_port_dict attributes:
            self._init_port_dicts()

            # Initialize Buffer for incoming data.  Dict used to store the
            # incoming data keyed by the source module id.  Each value is a
            # queue buferring the received data:
            self._in_data = {k: collections.deque() for k in self._in_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            curr_steps = 0
            while curr_steps < self._steps:
                self.logger.info('execution step: %s' % curr_steps)
                # If the debug flag is set, don't catch exceptions so that
                # errors will lead to visible failures:
                if self.debug:

                    # Get transmitted input data for processing:
                    self._get_in_data()

                    # Run the processing step:
                    self.run_step()

                    # Stage generated output data for transmission to other
                    # modules:
                    self._put_out_data()

                    # Synchronize:
                    self._sync()

                else:

                    # Get transmitted input data for processing:
                    catch_exception(self._get_in_data, self.logger.info)

                    # Run the processing step:
                    catch_exception(self.run_step, self.logger.info)

                    # Stage generated output data for transmission to other
                    # modules:
                    catch_exception(self._put_out_data, self.logger.info)

                    # Synchronize:
                    catch_exception(self._sync, self.logger.info)

                # Exit run loop when a quit signal has been received:
                if not self.running:
                    self.logger.info('run loop stopped')
                    break

                curr_steps += 1

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.logger.info('sent to manager: %s' % ack)

        self.logger.info('exiting')
Example #9
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.logger.info('starting')
        with IgnoreKeyboardInterrupt():
            # Initialize environment:
            self._init_net()
            
            # Initialize _out_port_dict and _in_port_dict attributes:
            self._init_port_dicts()

            
            # Initialize Buffer for incoming data.  Dict used to store the
            # incoming data keyed by the source module id.  Each value is a
            # queue buferring the received data:
            self._in_data = {k: collections.deque() for k in self._in_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            curr_steps = 0
            while curr_steps < self._steps:
                self.logger.info('execution step: %s' % curr_steps)
                # If the debug flag is set, don't catch exceptions so that
                # errors will lead to visible failures:
                if self.debug:

                    # Get transmitted input data for processing:
                    self._get_in_data()

                    # Run the processing step:
                    self.run_step()

                    # Stage generated output data for transmission to other
                    # modules:
                    self._put_out_data()

                    # Synchronize:
                    self._sync()

                else:

                    # Get transmitted input data for processing:
                    catch_exception(self._get_in_data, self.logger.info)

                    # Run the processing step:
                    catch_exception(self.run_step, self.logger.info)

                    # Stage generated output data for transmission to other
                    # modules:
                    catch_exception(self._put_out_data, self.logger.info)

                    # Synchronize:
                    catch_exception(self._sync, self.logger.info)

                # Exit run loop when a quit signal has been received:
                if not self.running:
                    self.logger.info('run loop stopped')
                    break

                curr_steps += 1

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.logger.info('sent to manager: %s' % ack)
                
        self.logger.info('exiting')
Example #10
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.logger.info('starting')
        with IgnoreKeyboardInterrupt():

            # Initialize environment:
            self._init_net()
            self._init_gpu()

            # Extract indices of source ports for all modules receiving output
            # once so that they don't need to be repeatedly extracted during the
            # simulation:
            self._out_idx_dict['gpot'] = \
              {out_id:self._conn_dict[out_id].src_idx(self.id, out_id, 'gpot') for \
               out_id in self.out_ids}
            self._out_idx_dict['spike'] = \
              {out_id:self._conn_dict[out_id].src_idx(self.id, out_id, 'spike') for \
               out_id in self.out_ids}

            # Initialize Buffer for incoming data.
            # Dict used to store the incoming data keyed by the source module id.
            # Each value is a queue buferring the received data
            self._in_data = {k:collections.deque() for k in self.in_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            curr_steps = 0
            while curr_steps < self._steps:
                self.logger.info('execution step: %s' % curr_steps)

                # Clear data structures for passing data to and from the
                # run_step method:                
                in_gpot_dict = {}
                in_spike_dict = {}
                out_gpot = []
                out_spike = []

                # If the debug flag is set, don't catch exceptions so that
                # errors will lead to visible failures:
                if self.debug:

                    # Get transmitted input data for processing:
                    self._get_in_data(in_gpot_dict, in_spike_dict)

                    # Run the processing step:
                    self.run_step(in_gpot_dict, in_spike_dict,
                                  out_gpot, out_spike)

                    # Stage generated output data for transmission to other
                    # modules:
                    self._put_out_data(out_gpot, out_spike)

                    # Synchronize:
                    self._sync()

                else:

                    # Get transmitted input data for processing:
                    catch_exception(self._get_in_data, self.logger.info,
                                    in_gpot_dict, in_spike_dict)

                    # Run the processing step:
                    catch_exception(self.run_step, self.logger.info,
                                    in_gpot_dict, in_spike_dict,
                                    out_gpot, out_spike)

                    # Stage generated output data for transmission to other
                    # modules:
                    catch_exception(self._put_out_data, self.logger.info,
                                    out_gpot, out_spike)

                    # Synchronize:
                    catch_exception(self._sync, self.logger.info)

                # Exit run loop when a quit signal has been received:
                if not self.running:
                    self.logger.info('run loop stopped')
                    break

                curr_steps += 1

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.logger.info('sent to manager: %s' % ack)
                
        self.logger.info('exiting')
Example #11
0
    def run(self):
        """
        Body of process.
        """

        # Don't allow keyboard interruption of process:
        self.logger.info('starting')
        with IgnoreKeyboardInterrupt():

            # Initialize environment:
            self._init_net()

            # Initialize Buffer for incoming data.
            # Dict used to store the incoming data keyed by the source module id.
            # Each value is a queue buferring the received data
            self._in_data = {k:collections.deque() for k in self.in_ids}

            # Extract indices of source ports for all modules receiving output
            # once so that they don't need to be repeatedly extracted during the
            # emulation:
            self._out_idx_dict = \
              {out_id:self._conn_dict[out_id].src_idx(self.id, out_id) for \
               out_id in self.out_ids}

            # Perform any pre-emulation operations:
            self.pre_run()

            self.running = True
            curr_steps = 0
            while curr_steps < self._steps:
                self.logger.info('execution step: %s' % curr_steps)

                # Clear data structures for passing data to and from the
                # run_step method:
                in_dict = {}
                out = []

                # Get input data:
                catch_exception(self._get_in_data,self.logger.info,in_dict)

                # Run the processing step:
                catch_exception(self.run_step,self.logger.info,in_dict, out)

                # Prepare the generated data for output:
                catch_exception(self._put_out_data,self.logger.info,out)

                # Synchronize:
                catch_exception(self._sync,self.logger.info)

                # Exit run loop when a quit message has been received:
                if not self.running:
                    self.logger.info('run loop stopped')
                    break

                curr_steps += 1

            # Perform any post-emulation operations:
            self.post_run()

            # Shut down the control handler and inform the manager that the
            # module has shut down:
            self._ctrl_stream_shutdown()
            ack = 'shutdown'
            self.sock_ctrl.send(ack)
            self.logger.info('sent to manager: %s' % ack)

        self.logger.info('exiting')