Exemple #1
0
def setup(hostname=None,
          graph_label=None,
          model_binary_module=None,
          model_binary_folder=None,
          database_socket_addresses=None,
          user_dsg_algorithm=None,
          n_chips_required=None,
          extra_pre_run_algorithms=None,
          extra_post_run_algorithms=None,
          time_scale_factor=None,
          machine_time_step=None):
    """

    :param hostname:\
        the hostname of the SpiNNaker machine to operate on\
        (over rides the machine_name from the cfg file).
    :type hostname: str
    :param graph_label:\
        a human readable label for the graph (used mainly in reports)
    :type graph_label: str
    :param model_binary_module:\
        the module where the binary files can be found for the c code that is \
        being used in this application; mutually exclusive with the \
        model_binary_folder.
    :type model_binary_module: python module
    :param model_binary_folder:\
        the folder where the binary files can be found for the c code that is\
        being used in this application; mutually exclusive with the\
        model_binary_module.
    :type model_binary_folder: str
    :param database_socket_addresses:\
        set of SocketAddresses that need to be added for the database\
        notification functionality. This are over and above the ones used by\
        the LiveEventConnection
    :type database_socket_addresses: list of SocketAddresses
    :param user_dsg_algorithm:\
        an algorithm used for generating the application data which is loaded\
        onto the machine. if not set, will use the data specification language\
        algorithm required for the type of graph being used.
    :type user_dsg_algorithm: str
    :param n_chips_required:\
        if you need to be allocated a machine (for spalloc) before building\
        your graph, then fill this in with a general idea of the number of\
        chips you need so that the spalloc system can allocate you a machine\
        big enough for your needs.
    :type n_chips_required: int or None
    :param extra_pre_run_algorithms:\
        algorithms which need to be ran after mapping and loading has occurred\
        but before the system has ran. These are plugged directly into the\
        work flow management.
    :type extra_post_run_algorithms: list of str
    :param extra_post_run_algorithms:\
        algorithms which need to be ran after the simulation has ran. These\
        could be post processing of generated data on the machine for example.
    :type extra_pre_run_algorithms: list of str
    """
    global _none_labelled_vertex_count
    global _none_labelled_edge_count

    logger.info("SpiNNaker graph front end (c) {}, "
                "University of Manchester".format(__version_year__))
    parent_dir = os.path.split(os.path.split(gfe_file.__file__)[0])[0]
    logger.info(
        "Release version {}({}) - {} {}. Installed in folder {}".format(
            __version__, __version_name__, __version_month__, __version_year__,
            parent_dir))

    # add the directories where the binaries are located
    executable_finder = ExecutableFinder()
    if model_binary_module is not None:
        executable_finder.add_path(
            os.path.dirname(model_binary_module.__file__))
    elif model_binary_folder is not None:
        executable_finder.add_path(model_binary_folder)
    else:
        file_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
        executable_finder.add_path(file_dir)

    # set up the spinnaker object
    SpiNNaker(host_name=hostname,
              graph_label=graph_label,
              executable_finder=executable_finder,
              database_socket_addresses=database_socket_addresses,
              dsg_algorithm=user_dsg_algorithm,
              n_chips_required=n_chips_required,
              extra_pre_run_algorithms=extra_pre_run_algorithms,
              extra_post_run_algorithms=extra_post_run_algorithms,
              machine_time_step=machine_time_step,
              time_scale_factor=time_scale_factor)
def setup(hostname=None,
          graph_label=None,
          model_binary_module=None,
          model_binary_folder=None,
          database_socket_addresses=(),
          user_dsg_algorithm=None,
          n_chips_required=None,
          n_boards_required=None,
          extra_pre_run_algorithms=(),
          extra_post_run_algorithms=(),
          time_scale_factor=None,
          machine_time_step=None):
    """ Set up a graph, ready to have vertices and edges added to it, and the\
        simulator engine that will execute the graph.

    .. note::
        This must be called *before* the other functions in this API.

    :param str hostname:
        the hostname of the SpiNNaker machine to operate on
        (overrides the ``machine_name`` from the cfg file).
    :param str graph_label:
        a human readable label for the graph (used mainly in reports)
    :param ~types.ModuleType model_binary_module:
        the Python module where the binary files (``.aplx``) can be found for
        the compiled C code that is being used in this application; mutually
        exclusive with the ``model_binary_folder``.
    :param str model_binary_folder:
        the folder where the binary files can be found for the c code that is
        being used in this application; mutually exclusive with the
        ``model_binary_module``.
    :param database_socket_addresses:
        set of SocketAddresses to be added for the database notification
        system. These are over and above the ones used by the
        :py:class:`~spinn_front_end_common.utilities.connections.LiveEventConnection`
    :type database_socket_addresses:
        ~collections.abc.Iterable(~spinn_utilities.socket_address.SocketAddress)
    :param str user_dsg_algorithm:
        an algorithm used for generating the application data which is loaded
        onto the machine. If not set, will use the data specification language
        algorithm required for the type of graph being used.
    :param n_chips_required:
        Deprecated! Use ``n_boards_required`` instead.
        Must be ``None`` if ``n_boards_required`` specified.
    :type n_chips_required: int or None
    :param n_boards_required:
        if you need to be allocated a machine (for spalloc) before building
        your graph, then fill this in with a general idea of the number of
        boards you need so that the spalloc system can allocate you a machine
        big enough for your needs.
    :type n_boards_required: int or None
    :param ~collections.abc.Iterable(str) extra_pre_run_algorithms:
        algorithms which need to be ran after mapping and loading has occurred
        but before the system has ran. These are plugged directly into the
        work flow management.
    :param ~collections.abc.Iterable(str) extra_post_run_algorithms:
        algorithms which need to be ran after the simulation has ran. These
        could be post processing of generated data on the machine for example.
    :raise ~spinn_front_end_common.utilities.exceptions.ConfigurationException:
        if mutually exclusive options are given.
    """
    # pylint: disable=redefined-outer-name
    logger.info("SpiNNaker graph front end (c) {}, University of Manchester",
                __version_year__)
    parent_dir = os.path.split(os.path.split(gfe_file.__file__)[0])[0]
    logger.info("Release version {}({}) - {} {}. Installed in folder {}",
                __version__, __version_name__, __version_month__,
                __version_year__, parent_dir)

    # add the directories where the binaries are located
    executable_finder = ExecutableFinder()
    if model_binary_module is not None:
        executable_finder.add_path(
            os.path.dirname(model_binary_module.__file__))
    elif model_binary_folder is not None:
        executable_finder.add_path(model_binary_folder)
    else:
        file_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
        executable_finder.add_path(file_dir)

    # set up the spinnaker object; after this, _sim() returns this object
    SpiNNaker(host_name=hostname,
              graph_label=graph_label,
              executable_finder=executable_finder,
              database_socket_addresses=database_socket_addresses,
              dsg_algorithm=user_dsg_algorithm,
              n_chips_required=n_chips_required,
              n_boards_required=n_boards_required,
              extra_pre_run_algorithms=extra_pre_run_algorithms,
              extra_post_run_algorithms=extra_post_run_algorithms,
              machine_time_step=machine_time_step,
              time_scale_factor=time_scale_factor)
Exemple #3
0
    def __init__(
            self, network, dt=constants.DEFAULT_DT,
            time_scale=constants.DEFAULT_TIME_SCALE,
            host_name=None, graph_label=None,
            database_socket_addresses=None, dsg_algorithm=None,
            n_chips_required=None, extra_pre_run_algorithms=None,
            extra_post_run_algorithms=None, decoder_cache=NoDecoderCache(),
            function_of_time_nodes=None,
            function_of_time_nodes_time_period=None):
        """Create a new Simulator with the given network.
        
        :param time_scale: Scaling factor to apply to the simulation, e.g.,\
            a value of `0.5` will cause the simulation to run at twice \
            real-time.
        :type time_scale: float
        :param host_name: Hostname of the SpiNNaker machine to use; if None\  
            then the machine specified in the config file will be used.
        :type host_name: basestring or None
        :param dt: The length of a simulator timestep, in seconds.
        :type dt: float
        :param graph_label: human readable graph label
        :type graph_label: basestring
        :param database_socket_addresses:
        :type database_socket_addresses:
        :param dsg_algorithm:
        :type dsg_algorithm:
        :param n_chips_required:
        :type n_chips_required:
        :param extra_post_run_algorithms:
        :type extra_post_run_algorithms:
        :param extra_pre_run_algorithms:
        :type extra_pre_run_algorithms:
        values
        :rtype None
        """
        self._nengo_object_to_data_map = dict()
        self._profiled_nengo_object_to_data_map = dict()
        self._nengo_to_app_graph_map = None
        self._app_graph_to_nengo_operator_map = None
        self._nengo_app_machine_graph_mapper = None

        executable_finder = ExecutableFinder()
        executable_finder.add_path(os.path.dirname(binaries.__file__))

        # Calculate the machine timestep, this is measured in microseconds
        # (hence the 1e6 scaling factor).
        machine_time_step = (
            int((dt / time_scale) *
                constants.SECONDS_TO_MICRO_SECONDS_CONVERTER))

        xml_paths = list()
        xml_paths.append(os.path.join(os.path.dirname(
            overridden_mapping_algorithms.__file__),
            self.NENGO_ALGORITHM_XML_FILE_NAME))

        SpiNNaker.__init__(
            self, executable_finder, host_name=host_name,
            graph_label=graph_label,
            database_socket_addresses=database_socket_addresses,
            dsg_algorithm=dsg_algorithm,
            n_chips_required=n_chips_required,
            extra_pre_run_algorithms=extra_pre_run_algorithms,
            extra_post_run_algorithms=extra_post_run_algorithms,
            time_scale_factor=time_scale,
            default_config_paths=[(
                os.path.join(os.path.dirname(__file__),
                             self.CONFIG_FILE_NAME))],
            machine_time_step=machine_time_step,
            extra_xml_paths=xml_paths,
            chip_id_allocator="NengoMallocBasedChipIDAllocator")

        # only add the sdram edge allocator if not using a virtual board
        extra_mapping_algorithms = list()
        if not helpful_functions.read_config_boolean(
                self.config, "Machine", "virtual_board"):
            extra_mapping_algorithms.append(
                "NengoSDRAMOutgoingPartitionAllocator")

        if function_of_time_nodes is None:
            function_of_time_nodes = list()
        if function_of_time_nodes_time_period is None:
            function_of_time_nodes_time_period = list()

        # update the main flow with new algorithms and params
        self.extend_extra_mapping_algorithms(extra_mapping_algorithms)
        self.update_extra_inputs(
            {"UserCreateDatabaseFlag": True,
             'DefaultNotifyHostName': self.config.get_str(
                "Database", "notify_hostname"),
             'NengoNodesAsFunctionOfTime': function_of_time_nodes,
             'NengoNodesAsFunctionOfTimeTimePeriod':
                 function_of_time_nodes_time_period,
             'NengoModel': network,
             'NengoDecoderCache': decoder_cache,
             "NengoNodeIOSetting": self.config.get("Simulator", "node_io"),
             "NengoEnsembleProfile":
                 self.config.getboolean("Ensemble", "profile"),
             "NengoEnsembleProfileNumSamples":
                 helpful_functions.read_config_int(
                     self.config, "Ensemble", "profile_num_samples"),
             "NengoRandomNumberGeneratorSeed":
                helpful_functions.read_config_int(
                    self.config, "Simulator", "global_seed"),
             "NengoUtiliseExtraCoreForProbes":
                self.config.getboolean(
                    "Node", "utilise_extra_core_for_probes"),
             "MachineTimeStepInSeconds": dt,
             "ReceiveBufferPort": helpful_functions.read_config_int(
                self.config, "Buffers", "receive_buffer_port"),
             "ReceiveBufferHost": self.config.get(
                 "Buffers", "receive_buffer_host"),
             "MinBufferSize": self.config.getint(
                 "Buffers", "minimum_buffer_sdram"),
             "MaxSinkBuffingSize": self.config.getint(
                 "Buffers", "sink_vertex_max_sdram_for_buffing"),
             "UsingAutoPauseAndResume": self.config.getboolean(
                 "Buffers", "use_auto_pause_and_resume"),
             "TimeBetweenRequests": self.config.getint(
                 "Buffers", "time_between_requests"),
             "BufferSizeBeforeReceive": self.config.getint(
                 "Buffers", "buffer_size_before_receive"),
             "SpikeBufferMaxSize": self.config.getint(
                "Buffers", "spike_buffer_size"),
             "VariableBufferMaxSize": self.config.getint(
                "Buffers", "variable_buffer_size")})

        # build app graph, machine graph, as the main tools expect an
        # application / machine graph level, and cannot go from random to app
        #  graph.
        nengo_app_graph_generator = NengoApplicationGraphGenerator()

        (self._nengo_operator_graph, host_network,
         self._nengo_to_app_graph_map, self._app_graph_to_nengo_operator_map,
         random_number_generator) = \
            nengo_app_graph_generator(
            self._extra_inputs["NengoModel"], self.machine_time_step,
            self._extra_inputs["NengoRandomNumberGeneratorSeed"],
            self._extra_inputs["NengoDecoderCache"],
            self._extra_inputs["NengoUtiliseExtraCoreForProbes"],
            self._extra_inputs["NengoNodesAsFunctionOfTime"],
            self._extra_inputs["NengoNodesAsFunctionOfTimeTimePeriod"],
            self.config.getboolean("Node", "optimise_utilise_interposers"),
            self._print_timings, self._do_timings, self._xml_paths,
            self._pacman_executor_provenance_path,
            self._extra_inputs["NengoEnsembleProfile"],
            self._extra_inputs["NengoEnsembleProfileNumSamples"],
            self._extra_inputs["ReceiveBufferPort"],
            self._extra_inputs["ReceiveBufferHost"],
            self._extra_inputs["MinBufferSize"],
            self._extra_inputs["MaxSinkBuffingSize"],
            self._extra_inputs["UsingAutoPauseAndResume"],
            self._extra_inputs["TimeBetweenRequests"],
            self._extra_inputs["BufferSizeBeforeReceive"],
            self._extra_inputs["SpikeBufferMaxSize"],
            self._extra_inputs["VariableBufferMaxSize"],
            self._extra_inputs["MachineTimeStepInSeconds"])

        # add the extra outputs as new inputs
        self.update_extra_inputs(
            {"NengoHostGraph": host_network,
             "NengoGraphToAppGraphMap": self._nengo_to_app_graph_map,
             "AppGraphToNengoOperatorMap":
                 self._app_graph_to_nengo_operator_map,
             "NengoRandomNumberGenerator": random_number_generator,
             "NengoOperatorGraph": self._nengo_operator_graph})