Esempio n. 1
0
def get_machine():
    """ Get the SpiNNaker machine in use.

    :return: the machine object
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return globals_variables.get_simulator().machine
Esempio n. 2
0
def get_machine():
    """ Get the spinnaker machine in use
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(
            "You currently have not ran setup, please do so before calling "
            "get_machine")
    return globals_variables.get_simulator().machine
Esempio n. 3
0
def get_time_step():
    """ The integration time step

    :return: get the time step of the simulation (in ms)
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return float(__pynn["get_time_step"]()) / 1000.0
Esempio n. 4
0
def get_current_time():
    """ Gets the time within the simulation

    :return: returns the current time
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["get_current_time"]()
Esempio n. 5
0
def run_until(tstop):
    """ Run until a (simulation) time period has completed.

    :param tstop: the time to stop at (in milliseconds)
    :return: the actual simulation time that the simulation stopped at
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["run_until"](tstop)
Esempio n. 6
0
def get_max_delay():
    """ The maximum allowed synaptic delay; delays will be clamped to be at\
        most this.

    :return: returns the max delay of the simulation
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["get_max_delay"]()
Esempio n. 7
0
def initialize(cells, **initial_values):
    """ Sets cells to be initialised to the given values

    :param cells: the cells to change params on
    :param initial_values: the params and there values to change
    :rtype: None
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    pynn_common.initialize(cells, **initial_values)
Esempio n. 8
0
def run(simtime, callbacks=None):
    """ The run() function advances the simulation for a given number of \
        milliseconds, e.g.:

    :param simtime: time to run for (in milliseconds)
    :param callbacks: callbacks to run
    :return: the actual simulation time that the simulation stopped at
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["run"](simtime, callbacks=callbacks)
Esempio n. 9
0
def reset(annotations=None):
    """ Resets the simulation to t = 0

    :param annotations: the annotations to the data objects
    :rtype: None
    """
    if annotations is None:
        annotations = {}
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    __pynn["reset"](annotations)
Esempio n. 10
0
def rank():
    """ The MPI rank of the current node.

    .. note::
        Always 0 on SpiNNaker, whcih doesn't use MPI.

    :return: MPI rank
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["rank"]()
Esempio n. 11
0
def num_processes():
    """ The number of MPI processes.

    .. note::
        Always 1 on SpiNNaker, which doesn't use MPI.

    :return: the number of MPI processes
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["num_processes"]()
Esempio n. 12
0
def create(cellclass, cellparams=None, n=1):
    """ Builds a population with certain params

    :param cellclass: population class
    :param cellparams: population params.
    :param n: n neurons
    :rtype: None
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    __pynn["create"](cellclass, cellparams, n)
Esempio n. 13
0
def connect(pre, post, weight=0.0, delay=None, receptor_type=None, p=1,
            rng=None):
    """ Builds a projection

    :param pre: source pop
    :param post: destination pop
    :param weight: weight of the connections
    :param delay: the delay of the connections
    :param receptor_type: excitatory / inhibitatory
    :param p: probability
    :param rng: random number generator
    :rtype: None
    """
    # pylint: disable=too-many-arguments
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    __pynn["connect"](pre, post, weight, delay, receptor_type, p, rng)
Esempio n. 14
0
def record(variables, source, filename, sampling_interval=None,
           annotations=None):
    """ Sets variables to be recorded.

    :param variables: may be either a single variable name or a list of \
        variable names. For a given celltype class, celltype.recordable \
        contains a list of variables that can be recorded for that celltype.
    :param source: where to record from
    :param filename: file name to write data to
    :param sampling_interval: \
        how often to sample the recording, not  ignored so far
    :param annotations: the annotations to data writers
    :return: neo object
    """
    if not globals_variables.has_simulator():
        raise ConfigurationException(FAILED_STATE_MSG)
    return __pynn["record"](variables, source, filename, sampling_interval,
                            annotations)
Esempio n. 15
0
def setup(timestep=_pynn_control.DEFAULT_TIMESTEP,
          min_delay=_pynn_control.DEFAULT_MIN_DELAY,
          max_delay=_pynn_control.DEFAULT_MAX_DELAY,
          graph_label=None,
          database_socket_addresses=None,
          extra_algorithm_xml_paths=None,
          extra_mapping_inputs=None,
          extra_mapping_algorithms=None,
          extra_pre_run_algorithms=None,
          extra_post_run_algorithms=None,
          extra_load_algorithms=None,
          time_scale_factor=None,
          n_chips_required=None,
          n_boards_required=None,
          **extra_params):
    """ The main method needed to be called to make the PyNN 0.8 setup. Needs\
        to be called before any other function

    :param timestep: the time step of the simulations
    :param min_delay: the min delay of the simulation
    :param max_delay: the max delay of the simulation
    :param graph_label: the label for the graph
    :param database_socket_addresses: the sockets used by external devices\
        for the database notification protocol
    :param extra_algorithm_xml_paths: \
        list of paths to where other XML are located
    :param extra_mapping_inputs: other inputs used by the mapping process
    :param extra_mapping_algorithms: \
        other algorithms to be used by the mapping process
    :param extra_pre_run_algorithms: extra algorithms to use before a run
    :param extra_post_run_algorithms: extra algorithms to use after a run
    :param extra_load_algorithms: \
        extra algorithms to use within the loading phase
    :param time_scale_factor: multiplicative factor to the machine time step\
        (does not affect the neuron models accuracy)
    :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.
    :param extra_params: other stuff
    :return: rank thing
    :raises ConfigurationException if both n_chips_required and
        n_boards_required are used.
    """
    # pylint: disable=too-many-arguments, too-many-function-args
    if pynn8_syntax:
        # setup PyNN common stuff
        pynn_common.setup(timestep, min_delay, max_delay, **extra_params)
    else:
        # setup PyNN common stuff
        pynn_common.setup(timestep, min_delay, **extra_params)

    # create stuff simulator
    if globals_variables.has_simulator():
        # if already exists, kill and rebuild
        globals_variables.get_simulator().clear()

    # add default label if needed
    if graph_label is None:
        graph_label = "PyNN0.8_graph"

    # create the main object for all stuff related software
    SpiNNaker(database_socket_addresses=database_socket_addresses,
              extra_algorithm_xml_paths=extra_algorithm_xml_paths,
              extra_mapping_inputs=extra_mapping_inputs,
              extra_mapping_algorithms=extra_mapping_algorithms,
              extra_pre_run_algorithms=extra_pre_run_algorithms,
              extra_post_run_algorithms=extra_post_run_algorithms,
              extra_load_algorithms=extra_load_algorithms,
              time_scale_factor=time_scale_factor,
              timestep=timestep,
              min_delay=min_delay,
              max_delay=max_delay,
              graph_label=graph_label,
              n_chips_required=n_chips_required,
              n_boards_required=n_boards_required)

    # warn about kwargs arguments
    if extra_params:
        logger.warning(
            "Extra params {} have been applied to the setup "
            "command which we do not consider", extra_params)

    # get overloaded functions from PyNN in relation of our simulator object
    _create_overloaded_functions(globals_variables.get_simulator())

    return rank()
Esempio n. 16
0
def setup(timestep=_pynn_control.DEFAULT_TIMESTEP,
          min_delay=_pynn_control.DEFAULT_MIN_DELAY,
          max_delay=None,
          graph_label=None,
          database_socket_addresses=None,
          time_scale_factor=None,
          n_chips_required=None,
          n_boards_required=None,
          **extra_params):
    """ The main method needed to be called to make the PyNN 0.8 setup. Needs\
        to be called before any other function

    :param timestep:
        the time step of the simulations in micro seconds
        if None the cfg value is used
    :type timestep:
        float or None
    :param min_delay: the min delay of the simulation
    :type min_delay: float or str
    :param max_delay: Ignored and logs a warning if provided
    :type max_delay: float or str or None
    :param graph_label: the label for the graph
    :type graph_label: str or None
    :param database_socket_addresses: the sockets used by external devices
        for the database notification protocol
    :type database_socket_addresses:
        iterable(~spinn_utilities.socket_address.SocketAddress)
    :param time_scale_factor: multiplicative factor to the machine time step
        (does not affect the neuron models accuracy)
    :type time_scale_factor: int or None
    :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 extra_params: other keyword argumets used to configure PyNN
    :return: MPI rank (always 0 on SpiNNaker)
    :rtype: int
    :raises ConfigurationException: if both ``n_chips_required`` and
        ``n_boards_required`` are used.
    """
    # Check for "auto" values
    if timestep == "auto":
        timestep = SPYNNAKER_AUTO_TIMESTEP
    if min_delay == "auto":
        min_delay = timestep
    if max_delay:
        logger.warning(
            "max_delay is not supported by sPyNNaker so will be ignored")

    # pylint: disable=too-many-arguments, too-many-function-args
    # setup PyNN common stuff
    pynn_common.setup(timestep, min_delay, **extra_params)

    # create stuff simulator
    if globals_variables.has_simulator():
        logger.warning("Calling setup a second time causes the previous "
                       "simulator to be stopped and cleared.")
        # if already exists, kill and rebuild
        try:
            globals_variables.get_simulator().clear()
        except Exception:  # pylint: disable=broad-except
            logger.exception("Error forcing previous simulation to clear")

    # add default label if needed
    if graph_label is None:
        graph_label = "PyNN0.8_graph"

    # create the main object for all stuff related software
    SpiNNaker(database_socket_addresses=database_socket_addresses,
              time_scale_factor=time_scale_factor,
              timestep=timestep,
              min_delay=min_delay,
              graph_label=graph_label,
              n_chips_required=n_chips_required,
              n_boards_required=n_boards_required)

    # warn about kwargs arguments
    if extra_params:
        logger.warning(
            "Extra params {} have been applied to the setup "
            "command which we do not consider", extra_params)

    # get overloaded functions from PyNN in relation of our simulator object
    _create_overloaded_functions(globals_variables.get_simulator())

    return rank()