spynnaker.pyNN.models.populations package

Module contents

A population is a group of neurons with the same neuron model and synaptic model, but possibly (usually!) varying connectivity and configuration parameters.

A population view is a subset of a population, created by slicing the population:

view = population[n:m]

An assembly is an agglomeration of populations and population views, created by adding them together:

assembly = population_1 + population_2

Note

sPyNNaker only has incomplete support for assemblies; do not use.

class spynnaker.pyNN.models.populations.Assembly(*populations, **kwargs)

Bases: Assembly

A group of neurons, may be heterogeneous, in contrast to a Population where all the neurons are of the same type.

Parameters:
  • populations (Population or PopulationView) – the populations or views to form the assembly out of

  • kwargs – may contain label (a string describing the assembly)

Create an Assembly of Populations and/or PopulationViews.

class spynnaker.pyNN.models.populations.IDMixin(parent, selector, label=None)

Bases: PopulationView

Parameters:
  • parent (Population or PopulationView) – the population or view to make the view from

  • vertex (PopulationApplicationVertex) – The actual underlying vertex

  • recorder (Recorder) – The recorder of the Population

  • selector (None or slice or int or list(bool) or list(int) or ndarray(bool) or ndarray(int)) –

    a slice or numpy mask array. The mask array should either be a boolean array (ideally) of the same size as the parent, or an integer array containing cell indices, i.e. if p.size == 5 then:

    PopulationView(p, array([False, False, True, False, True]))
    PopulationView(p, array([2, 4]))
    PopulationView(p, slice(2, 5, 2))
    

    will all create the same view.

  • label (str) – A label for the view

as_view()[source]

Return a PopulationView containing just this cell.

Return type:

PopulationView

get_initial_value(variable)[source]

Get the initial value of a state variable of the cell.

Parameters:

variable (str) – The name of the variable

Return type:

float

get_parameters()[source]

Return a dict of all cell parameters.

Return type:

dict(str, …)

property id
Return type:

int

property initial_values

A dict containing the initial values of the state variables.

Return type:

InitialValuesHolder

property local

Whether this cell is local to the current MPI node.

Return type:

bool

set_initial_value(variable, value)[source]

Set the initial value of a state variable of the cell.

Parameters:
  • variable (str) – The name of the variable

  • value (float) – The value of the variable

set_parameters(**parameters)[source]

Set cell parameters, given as a sequence of parameter=value arguments.

class spynnaker.pyNN.models.populations.Population(size, cellclass, cellparams=None, structure=None, initial_values=None, label=None, additional_parameters=None, **additional_kwargs)

Bases: PopulationBase

PyNN 0.9 population object.

Parameters:
  • size (int) – The number of neurons in the population

  • cellclass (type or AbstractPyNNModel) – The implementation of the individual neurons.

  • cellparams (dict(str,object) or None) – Parameters to pass to cellclass if it is a class to instantiate. Must be None if cellclass is an instantiated object.

  • structure (BaseStructure) –

  • initial_values (dict(str,float)) – Initial values of state variables

  • label (str) – A label for the population

  • additional_parameters (dict(str, ...)) – Additional parameters to pass to the vertex creation function.

  • additional_kwargs (dict(str, ...)) – A nicer way of allowing additional things

add_placement_constraint(x, y, p=None)[source]

Add a placement constraint.

Parameters:
  • x (int) – The x-coordinate of the placement constraint

  • y (int) – The y-coordinate of the placement constraint

  • p (int) – The processor ID of the placement constraint (optional)

Raises:
  • SimulatorRunningException – If sim.run is currently running

  • SimulatorNotSetupException – If called before sim.setup

  • SimulatorShutdownException – If called after sim.end

all()[source]

Iterator over cell IDs on all MPI nodes.

Return type:

iterable(IDMixin)

property all_cells
Return type:

list(IDMixin)

property annotations

The annotations given by the end user.

Return type:

dict(str, …)

can_record(variable)[source]

Determine whether variable can be recorded from this population.

Parameters:

variable (str) – The variable to answer the question about

Return type:

bool

property celltype

Implements the PyNN expected celltype property.

Returns:

The cell type this property has been set to

Return type:

AbstractPyNNModel

property conductance_based

Whether the population uses conductance inputs

Return type:

bool

static create(cellclass, cellparams=None, n=1)[source]

Pass through method to the constructor defined by PyNN. Create n cells all of the same type.

Parameters:
Returns:

A New Population

Return type:

Population

property current_values

Get the current values of the state variables.

Return type:

ParameterHolder

describe(template='population_default.txt', engine='default')[source]

Returns a human-readable description of the population.

The output may be customized by specifying a different template together with an associated template engine (see pyNN.descriptions).

If template is None, then a dictionary containing the template context will be returned.

Parameters:
  • template (str) – Template filename

  • engine (str or TemplateEngine or None) – Template substitution engine

Return type:

str or dict

find_units(variable)[source]

Get the units of a variable.

Parameters:

variable (str) – The name of the variable

Returns:

The units of the variable

Return type:

str

property first_id

The ID of the first member of the population.

Return type:

int

get(parameter_names, gather=True, simplify=True)[source]

Get the values of a parameter for every local cell in the population.

Parameters:
  • parameter_names (str or iterable(str)) – Name of parameter. This is either a single string or a list of strings

  • gather (bool) – pointless on sPyNNaker

  • simplify (bool) – ignored

Returns:

A single list of values (or possibly a single value) if paramter_names is a string, or a dict of these if parameter names is a list.

Return type:

ParameterHolder

get_data(variables='all', gather=True, clear=False, annotations=None)[source]

Return a Neo Block containing the data (spikes, state variables) recorded from the Assembly.

Parameters:
  • variables (str or list(str)) – either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

  • gather (bool) –

    Whether to collect data from all MPI nodes or just the current node.

    Note

    This is irrelevant on sPyNNaker, which always behaves as if this parameter is True.

  • clear (bool) – Whether recorded data will be deleted from the Assembly.

  • annotations (dict(str, ...)) – annotations to put on the neo block

Return type:

Block

Raises:

ConfigurationException – If the variable or variables have not been previously set to record.

get_spike_counts(gather=True)[source]

Return the number of spikes for each neuron.

Return type:

ndarray

id_to_index(id)[source]

Given the ID(s) of cell(s) in the Population, return its (their) index (order in the Population).

Defined by https://neuralensemble.org/docs/PyNN/reference/populations.html

Parameters:

id (int or iterable(int)) –

Return type:

int or iterable(int)

id_to_local_index(cell_id)[source]

Given the ID(s) of cell(s) in the Population, return its (their) index (order in the Population), counting only cells on the local MPI node.

Defined by https://neuralensemble.org/docs/PyNN/reference/populations.html

Parameters:

cell_id (int or iterable(int)) –

Return type:

int or iterable(int)

index_to_id(index)[source]

Given the index (order in the Population) of cell(s) in the Population, return their ID(s)

Parameters:

index (int or iterable(int)) –

Return type:

int or iterable(int)

property initial_values

The initial values of the state variables.

Note

These values will be the same as the values set with the last call to initialize rather than the actual initial values if this call has been made.

Return type:

ParameterHolder

initialize(**kwargs)[source]

Set initial values of state variables, e.g. the membrane potential. Values passed to initialize() may be:

  • single numeric values (all neurons set to the same value), or

  • RandomDistribution objects, or

  • lists / arrays of numbers of the same size as the population mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single number.

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.initialize(v=-70.0)
p.initialize(v=rand_distr, gsyn_exc=0.0)
p.initialize(v=lambda i: -65 + i / 10.0)
inject(current_source)[source]

Connect a current source to all cells in the Population.

Defined by https://neuralensemble.org/docs/PyNN/reference/populations.html

property label

The label of the population.

Return type:

str

property last_id

The ID of the last member of the population.

Return type:

int

property local_size

The number of local cells.

Defined by https://neuralensemble.org/docs/PyNN/reference/populations.html

property position_generator
Return type:

callable((int), ndarray)

property positions

The position array for structured populations.

Returns:

a 3xN array

Return type:

ndarray

record(variables, to_file=None, sampling_interval=None)[source]

Record the specified variable or variables for all cells in the Population or view.

Parameters:
  • variables (str or list(str)) – 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.

  • to_file (io or rawio or str) – a file to automatically record to (optional). write_data() will be automatically called when sim.end() is called.

  • sampling_interval (int) – a value in milliseconds, and an integer multiple of the simulation timestep.

sample(n, rng=None)[source]

Randomly sample n cells from the Population, and return a PopulationView object.

Parameters:
  • n (int) – The number of cells to put in the view.

  • rng (NumpyRNG) – The random number generator to use

Return type:

PopulationView

set(**parameters)[source]

Set one or more parameters for every cell in the population.

parameter can be a dict, in which case value should not be supplied, or a string giving the parameter name, in which case value is the parameter value. value can be a numeric value, or list of such (e.g. for setting spike times):

p._set("tau_m", 20.0).
p._set({'tau_m':20, 'v_rest':-65})
Parameters:
Raises:
  • SimulatorRunningException – If sim.run is currently running

  • SimulatorNotSetupException – If called before sim.setup

  • SimulatorShutdownException – If called after sim.end

set_max_atoms_per_core(max_atoms_per_core)[source]

Supports the setting of this population’s max atoms per dimension per core.

Parameters:

max_atoms_per_core (int) – the new value for the max atoms per dimension per core.

Raises:
  • SimulatorRunningException – If sim.run is currently running

  • SimulatorNotSetupException – If called before sim.setup

  • SimulatorShutdownException – If called after sim.end

set_state(**kwargs)[source]

Set current values of state variables, e.g. the membrane potential. Values passed to set_state() may be:

  • single numeric values (all neurons set to the same value), or

  • RandomDistribution objects, or

  • lists / arrays of numbers of the same size as the population mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single number.

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.set_state(v=-70.0)
p.set_state(v=rand_distr, gsyn_exc=0.0)
p.set_state(v=lambda i: -65 + i / 10.0)
property size

The number of neurons in the population.

Return type:

int

spinnaker_get_data(variable, as_matrix=False, view_indexes=None)[source]

Public accessor for getting data as a numpy array, instead of the Neo-based object

Parameters:
  • variable (str or list(str)) – a single variable name.

  • as_matrix (bool) – If set True the data is returned as a 2d matrix

  • view_indexes – The indexes for which data should be returned. If None, all data (view_index = data_indexes)

Returns:

array of the data

Return type:

ndarray

property structure

The structure for the population.

Return type:

BaseStructure or None

write_data(io, variables='all', gather=True, clear=False, annotations=None)[source]

Write recorded data to file, using one of the file formats supported by Neo.

Parameters:
  • io (neo.io.baseio.BaseIO or str) – a Neo IO instance, or a string for where to put a neo instance

  • variables (str or list(str)) – either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

  • gather (bool) –

    Whether to bring all relevant data together.

    Note

    SpiNNaker always gathers.

  • clear (bool) – clears the storage data if set to true after reading it back

  • annotations (dict(str, ...)) – annotations to put on the neo block

Raises:

ConfigurationException – If the variable or variables have not been previously set to record.

class spynnaker.pyNN.models.populations.PopulationBase

Bases: object

Shared methods between Populations and PopulationViews.

Mainly pass through and not implemented.

abstract property all_cells

An array containing the cell IDs of all neurons in the Population (all MPI nodes).

Return type:

list(int)

abstract get_data(variables='all', gather=True, clear=False, annotations=None)[source]

Return a Neo Block containing the data(spikes, state variables) recorded from the Population.

Parameters:
  • variables (str or list(str)) – Either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

  • gather (bool) –

    For parallel simulators, if this is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

    Note

    SpiNNaker always gathers.

  • clear (bool) – If this is True, recorded data will be deleted from the Population.

  • annotations (None or dict(str, ...)) – annotations to put on the neo block

Return type:

Block

abstract get_spike_counts(gather=True)[source]

Returns a dict containing the number of spikes for each neuron.

The dict keys are neuron IDs, not indices.

Parameters:

gather (bool) –

For parallel simulators, if this is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

Note

SpiNNaker always gathers.

Return type:

dict(int, int)

abstract inject(current_source)[source]

Connect a current source to all cells in the Population.

Parameters:

current_source (NeuronCurrentSource) –

is_local(id)[source]

Indicates whether the cell with the given ID exists on the local MPI node.

Return type:

bool

property local_cells

An array containing the cell IDs of those neurons in the Population that exist on the local MPI node.

Return type:

list(int)

property local_size

The number of cells in the population on the local MPI node.

Return type:

int

mean_spike_count(gather=True)[source]

Returns the mean number of spikes per neuron.

Parameters:

gather (bool) –

For parallel simulators, if this is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

Note

SpiNNaker always gathers.

Return type:

float

nearest(position)[source]

Return the neuron closest to the specified position.

Warning

Currently unimplemented.

property position_generator

Note

NO PyNN description of this method.

Warning

Currently unimplemented.

property positions

Note

NO PyNN description of this method.

Warning

Currently unimplemented.

Return type:

ndarray(tuple(float, float, float))

receptor_types()[source]

Note

NO PyNN description of this method.

Warning

Currently unimplemented.

abstract record(variables, to_file=None, sampling_interval=None)[source]

Record the specified variable or variables for all cells in the Population or view.

Parameters:
  • variables (str or list(str)) – 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.

  • to_file (io or rawio or str) – a file to automatically record to (optional). write_data() will be automatically called when end() is called.

  • sampling_interval (int) – a value in milliseconds, and an integer multiple of the simulation timestep.

save_positions(file)[source]

Save positions to file. The output format is index x y z

Warning

Currently unimplemented.

property structure

The spatial structure of the parent Population.

Warning

Currently unimplemented.

Return type:

BaseStructure

abstract write_data(io, variables='all', gather=True, clear=False, annotations=None)[source]

Write recorded data to file, using one of the file formats supported by Neo.

Parameters:
  • io (io or rawio or str) – a Neo IO instance, or a string for where to put a Neo instance

  • variables (str or list(str)) – either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

  • gather (bool) –

    For parallel simulators, if this is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node. This is pointless on sPyNNaker.

    Note

    SpiNNaker always gathers.

  • clear (bool) – clears the storage data if set to true after reading it back

  • annotations (None or dict(str, ...)) – annotations to put on the Neo block

class spynnaker.pyNN.models.populations.PopulationView(parent, selector, label=None)

Bases: PopulationBase

A view of a subset of neurons within a Population.

In most ways, Populations and PopulationViews have the same behaviour, i.e., they can be recorded, connected with Projections, etc. It should be noted that any changes to neurons in a PopulationView will be reflected in the parent Population and vice versa.

It is possible to have views of views.

Note

Selector to Id is actually handled by AbstractSized.

Parameters:
  • parent (Population or PopulationView) – the population or view to make the view from

  • vertex (PopulationApplicationVertex) – The actual underlying vertex

  • recorder (Recorder) – The recorder of the Population

  • selector (None or slice or int or list(bool) or list(int) or ndarray(bool) or ndarray(int)) –

    a slice or numpy mask array. The mask array should either be a boolean array (ideally) of the same size as the parent, or an integer array containing cell indices, i.e. if p.size == 5 then:

    PopulationView(p, array([False, False, True, False, True]))
    PopulationView(p, array([2, 4]))
    PopulationView(p, slice(2, 5, 2))
    

    will all create the same view.

  • label (str) – A label for the view

all()[source]

Iterator over cell IDs (on all MPI nodes).

Return type:

iterable(IDMixin)

property all_cells

An array containing the cell IDs of all neurons in the Population (all MPI nodes).

Return type:

list(IDMixin)

can_record(variable)[source]

Determine whether variable can be recorded from this population.

Return type:

bool

property celltype

The type of neurons making up the underlying Population.

Return type:

AbstractPyNNModel

property conductance_based

Whether the post-synaptic response is modelled as a change in conductance or a change in current.

Return type:

bool

property current_values

A dict containing the current values of the state variables.

Return type:

InitialValuesHolder

describe(template='populationview_default.txt', engine='default')[source]

Returns a human-readable description of the population view.

The output may be customized by specifying a different template together with an associated template engine (see pyNN.descriptions).

If template is None, then a dictionary containing the template context will be returned.

Parameters:
  • template (str) – Template filename

  • engine (str or TemplateEngine or None) – Template substitution engine

Return type:

str or dict

find_units(variable)[source]

Get the units of a variable

Warning

No PyNN description of this method.

Parameters:

variable (str) – The name of the variable

Returns:

The units of the variable

Return type:

str

get(parameter_names, gather=False, simplify=True)[source]

Get the values of the given parameters for every local cell in the population, or, if gather=True, for all cells in the population.

Values will be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Note

SpiNNaker always gathers.

Parameters:
Return type:

ParameterHolder

get_data(variables='all', gather=True, clear=False, annotations=None)[source]

Return a Neo Block containing the data(spikes, state variables) recorded from the Population.

Parameters:
  • variables (str or list(str)) – Either a single variable name or a list of variable names. Variables must have been previously recorded, otherwise an Exception will be raised.

  • gather (bool) –

    For parallel simulators, if gather is True, all data will be gathered to all nodes and the Neo Block will contain data from all nodes. Otherwise, the Neo Block will contain only data from the cells simulated on the local node.

    Note

    SpiNNaker always gathers.

  • clear (bool) – If True, recorded data will be deleted from the Population.

  • annotations (dict(str, ...)) – annotations to put on the neo block

Return type:

Block

Raises:

ConfigurationException – If the variable or variables have not been previously set to record.

get_spike_counts(gather=True)[source]

Returns a dict containing the number of spikes for each neuron.

The dict keys are neuron IDs, not indices.

Note

Implementation of this method is different to Population as the Populations uses PyNN 7 version of the get_spikes method which does not support indexes.

Parameters:

gather (bool) –

Note

SpiNNaker always gathers.

Return type:

dict(int,int)

property grandparent

The parent Population at the root of the tree (since the immediate parent may itself be a PopulationView).

The name “grandparent” is of course a little misleading, as it could be just the parent, or the great, great, great, …, grandparent.

Return type:

Population

id_to_index(id)[source]

Given the ID(s) of cell(s) in the PopulationView, return its / their index / indices(order in the PopulationView).

assert pv.id_to_index(pv[3]) == 3

Parameters:

id (int or list(int)) –

Return type:

int or list(int)

index_in_grandparent(indices)[source]

Given an array of indices, return the indices in the parent population at the root of the tree.

Parameters:

indices (list(int)) –

Return type:

list(int)

property initial_values

A dict containing the initial values of the state variables.

Return type:

InitialValuesHolder

initialize(**initial_values)[source]

Set initial values of state variables, e.g. the membrane potential. Values passed to initialize() may be:

  • single numeric values (all neurons set to the same value), or

  • RandomDistribution objects, or

  • lists / arrays of numbers of the same size as the population mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single number.

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, events per second).

Examples:

p.initialize(v=-70.0)
p.initialize(v=rand_distr, gsyn_exc=0.0)
p.initialize(v=lambda i: -65 + i / 10.0)
inject(current_source)[source]

Injects the specified current_source into this PopulationView.

Parameters:

current_source (AbstractCurrentSource) – the current source to be injected

property label

A label for the Population View.

Return type:

str

property mask

The selector mask that was used to create this view.

Return type:

None or slice or int or list(bool) or list(int) or ndarray(bool) or ndarray(int)

property parent

A reference to the parent Population (that this is a view of).

Return type:

Population

record(variables, to_file=None, sampling_interval=None)[source]

Record the specified variable or variables for all cells in the Population or view.

Parameters:
  • variables (str or list(str)) – either a single variable name, or a list of variable names, or all to record everything. For a given celltype class, celltype.recordable contains a list of variables that can be recorded for that celltype.

  • to_file (io or rawio or str) – If specified, should be a Neo IO instance and write_data() will be automatically called when sim.end() is called.

  • sampling_interval (int) – should be a value in milliseconds, and an integer multiple of the simulation timestep.

sample(n, rng=None)[source]

Randomly sample n cells from the Population view, and return a new PopulationView object.

Parameters:
  • n (int) – The number of cells to select

  • rng (NumpyRNG) – Random number generator

Return type:

PopulationView

set(**parameters)[source]

Set one or more parameters for every cell in the population. Values passed to set() may be:

  • single values,

  • RandomDistribution objects, or

  • lists / arrays of values of the same size as the population mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single value.

Here, a “single value” may be either a single number or a list / array of numbers (e.g. for spike times).

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, event per second).

Examples:

p.set(tau_m=20.0, v_rest=-65).
p.set(spike_times=[0.3, 0.7, 0.9, 1.4])
p.set(cm=rand_distr, tau_m=lambda i: 10 + i / 10.0)
set_state(**initial_values)[source]

Set current values of state variables, e.g. the membrane potential. Values passed to initialize() may be:

  • single numeric values (all neurons set to the same value), or

  • RandomDistribution objects, or

  • lists / arrays of numbers of the same size as the population mapping functions, where a mapping function accepts a single argument (the cell index) and returns a single number.

Values should be expressed in the standard PyNN units (i.e. millivolts, nanoamps, milliseconds, microsiemens, nanofarads, events per second).

Examples:

p.set_state(v=-70.0)
p.set_state(v=rand_distr, gsyn_exc=0.0)
p.set_state(v=lambda i: -65 + i / 10.0)
property size

The total number of neurons in the Population View.

Return type:

int

spinnaker_get_data(variable, as_matrix=False)[source]

Public accessor for getting data as a numpy array, instead of the Neo-based object

Parameters:
  • variable (str) – a single variable name

  • as_matrix (bool) – If set True the data is returned as a 2d matrix

Returns:

array of the data

Return type:

ndarray

spinnaker_get_spikes()[source]

Public accessor for getting spikes as a numpy array, instead of the Neo-based object

write_data(io, variables='all', gather=True, clear=False, annotations=None)[source]

Write recorded data to file, using one of the file formats supported by Neo.

Parameters:
  • io (neo.io.BaseIO or str) – a Neo IO instance or the name of a file to write

  • variables (str or list(str)) – either a single variable name or a list of variable names. These must have been previously recorded, otherwise an Exception will be raised.

  • gather (bool) –

    For parallel simulators, if this is True, all data will be gathered to the master node and a single output file created there. Otherwise, a file will be written on each node, containing only data from the cells simulated on that node.

    Note

    SpiNNaker always gathers.

  • clear (bool) – If this is True, recorded data will be deleted from the Population.

  • annotations (dict(str, ...)) – should be a dict containing simple data types such as numbers and strings. The contents will be written into the output data file as metadata.

Raises:

ConfigurationException – If the variable or variables have not been previously set to record.