spynnaker8.models.populations package

Module contents

class spynnaker8.models.populations.Assembly(*populations, **kwargs)[source]

Bases: pyNN.common.populations.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 spynnaker8.models.populations.IDMixin(population, id)[source]

Bases: object

Instead of storing IDs as integers, we store them as ID objects, which allows a syntax like:

p[3,4].tau_m = 20.0

where p is a Population object.

Parameters:
as_view()[source]

Return a PopulationView containing just this cell.

Return type:PopulationView
celltype
Return type:AbstractPyNNModel
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, ..)
id
Return type:int
inject(current_source)[source]

Inject current from a current source object into the cell.

Parameters:current_source (NeuronCurrentSource) –
is_standard_cell
Return type:bool
local

Whether this cell is local to the current MPI node.

Return type:bool
position

Return the cell position in 3D space. Cell positions are stored in an array in the parent Population, if any, or within the ID object otherwise. Positions are generated the first time they are requested and then cached.

Return type:ndarray
record(variables, to_file=None, sampling_interval=None)[source]

Record the given variable(s) of this cell.

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) – If specified, should be a Neo IO instance and write_data() will be automatically called when end() is called.
  • sampling_interval (int) – should be a value in milliseconds, and an integer multiple of the simulation timestep.
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 spynnaker8.models.populations.Population(size, cellclass, cellparams=None, structure=None, initial_values=None, label=None, constraints=None, additional_parameters=None)[source]

Bases: spynnaker.pyNN.models.pynn_population_common.PyNNPopulationCommon, spynnaker8.models.recorder.Recorder, spynnaker8.models.populations.population_base.PopulationBase

PyNN 0.8/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) – Parameters to pass to cellclass if it is a class to instantiate.
  • structure (BaseStructure) –
  • initial_values (dict(str,float)) – Initial values of state variables
  • label (str) – A label for the population
  • constraints (list(AbstractConstraint)) – Any constraints on how the population is deployed to SpiNNaker.
  • additional_parameters (dict(str, ..)) – Additional parameters to pass to the vertex creation function.
all()[source]

Iterator over cell IDs on all MPI nodes.

Return type:iterable(IDMixin)
all_cells
Return type:list(IDMixin)
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
celltype

Implements the PyNN expected celltype property

Returns:The celltype this property has been set to
Return type:AbstractPyNNModel
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. Returns a Population object.

Parameters:
  • cellclass (type or AbstractPyNNModel) – see Population.__init__()
  • cellparams (dict(str, ..)) – see Population.__init__()
  • n (int) – see Population.__init__() (size parameter)
Returns:

A New Population

Return type:

Population

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
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

get_data_by_indexes(variables, indexes, 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.
  • indexes (list(int)) – List of neuron indexes to include in the data. Clearly only neurons recording will actually have any data. If None will be taken as all recording as in get_data()
  • clear (bool) – Whether recorded data will be deleted.
  • annotations (dict(str, ..)) – annotations to put on the neo block
Return type:

Block

get_initial_value(variable, selector=None)[source]

See AbstractPopulationInitializable.get_initial_value()

get_initial_values(selector=None)[source]

See AbstractPopulationInitializable.get_initial_values()

get_spike_counts(gather=True)[source]

Return the number of spikes for each neuron.

Return type:ndarray
initial_values
Return type:dict
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)
position_generator
Return type:callable((int), ndarray)
positions

Return the position array for structured populations.

Returns:a 2D array, one row per cell. Each row is three long, for X,Y,Z
Return type:ndarray
record(variables, to_file=None, sampling_interval=None, indexes=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.
  • indexes (None or list(int)) – The indexes of neurons to record from. This is non-standard PyNN and equivalent to creating a view with these indexes and asking the View to record.
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 parameters of this population.

Parameters:parameters – The parameters to set.
set_initial_value(variable, value, selector=None)[source]

See AbstractPopulationInitializable.set_initial_value()

spinnaker_get_data(variable)[source]

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

Parameters:variable (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.
Returns:array of the data
Return type:ndarray
tset(**kwargs)[source]

Warning

Deprecated. Use set(parametername=value_array) instead.

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) –

    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
class spynnaker8.models.populations.PopulationBase[source]

Bases: object

Shared methods between Populations and PopulationViews.

Mainly pass through and not implemented

all_cells

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

Return type:list(int)
getSpikes(*args, **kwargs)[source]

Warning

Deprecated. Use get_data(‘spikes’) instead.

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
get_gsyn(*args, **kwargs)[source]

Warning

Deprecated. Use get_data([‘gsyn_exc’, ‘gsyn_inh’]) instead.

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)
get_v(*args, **kwargs)[source]

Warning

Deprecated. Use get_data(‘v’) instead.

inject(current_source)[source]

Connect a current source to all cells in the Population.

Warning

Currently unimplemented.

Parameters:current_source (pyNN.neuron.standardmodels.electrodes.NeuronCurrentSource) –
is_local(id)[source]

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

Return type:bool
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)
local_size

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

Return type:int
meanSpikeCount(*args, **kwargs)[source]

Warning

Deprecated. Use mean_spike_count() instead.

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.

position_generator

Note

NO PyNN description of this method.

Warning

Currently unimplemented.

positions

Note

NO PyNN description of this method.

Warning

Currently unimplemented.

Return type:ndarray(tuple(float, float, float))
printSpikes(filename, gather=True)[source]

Warning

Deprecated. Use write_data(file, ‘spikes’) instead.

Note

Method signature is the PyNN0.7 one

print_gsyn(filename, gather=True)[source]

Warning

Deprecated. Use write_data(file, [‘gsyn_exc’, ‘gsyn_inh’]) instead.

Note

Method signature is the PyNN0.7 one

print_v(filename, gather=True)[source]

Warning

Deprecated. Use write_data(file, ‘v’) instead.

Note

Method signature is the PyNN0.7 one

receptor_types()[source]

Note

NO PyNN description of this method.

Warning

Currently unimplemented.

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.
record_gsyn(sampling_interval=1, to_file=None)[source]

Warning

Deprecated. Use record([‘gsyn_exc’, ‘gsyn_inh’]) instead.

Note

Method signature is the PyNN 0.7 one with the extra non-PyNN sampling_interval and indexes

record_v(sampling_interval=1, to_file=None)[source]

Warning

Deprecated. Use record(‘v’) instead.

Note

Method signature is the PyNN 0.7 one with the extra non-PyNN sampling_interval and indexes

rset(*args, **kwargs)[source]

Warning

Deprecated. Use set(parametername=rand_distr) instead.

save_positions(file)[source]

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

Warning

Currently unimplemented.

structure

The spatial structure of the parent Population.

Warning

Currently unimplemented.

Return type:BaseStructure
tset(**kwargs)[source]

Warning

Deprecated. Use set(parametername=value_array) instead.

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 spynnaker8.models.populations.PopulationView(parent, selector, label=None)[source]

Bases: spynnaker8.models.populations.population_base.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
  • 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
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
celltype

The type of neurons making up the underlying Population.

Return type:AbstractPyNNModel
conductance_based

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

Return type:bool
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).

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

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.

Note

SpiNNaker always gathers.

Return type:dict(int,int)
grandparent

Returns 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

index_in_grandparent(indices)[source]

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

initial_values

A dict containing the initial values of the state variables.

Return type:dict(str, ..)
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, 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)
label

A label for the Population View.

Return type:str
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)
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)
size

The total number of neurons in the Population View.

Return type:int
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
  • 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.