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
- property initial_values¶
A dict containing the initial values of the state variables.
- Return type:
InitialValuesHolder
- 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 beNone
ifcellclass
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:
- Raises:
SimulatorRunningException – If sim.run is currently running
SimulatorNotSetupException – If called before sim.setup
SimulatorShutdownException – If called after sim.end
- property celltype¶
Implements the PyNN expected celltype property.
- Returns:
The cell type this property has been set to
- Return type:
- 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:
- property current_values¶
Get the current values of the state variables.
- Return type:
- 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
isNone
, then a dictionary containing the template context will be returned.
- get(parameter_names, gather=True, simplify=True)[source]¶
Get the values of a parameter for every local cell in the population.
- Parameters:
- 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:
- 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:
- Raises:
ConfigurationException – If the variable or variables have not been previously set to record.
- 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
- 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
- index_to_id(index)[source]¶
Given the index (order in the Population) of cell(s) in the Population, return their ID(s)
- 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:
- 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, orlists / 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 local_size¶
The number of local cells.
Defined by https://neuralensemble.org/docs/PyNN/reference/populations.html
- property positions¶
The position array for structured populations.
- Returns:
a 3xN array
- Return type:
- 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:
- Return type:
- set(**parameters)[source]¶
Set one or more parameters for every cell in the population.
parameter
can be a dict, in which casevalue
should not be supplied, or a string giving the parameter name, in which casevalue
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, orlists / 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)
- 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
- 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
Population
s andPopulationView
s.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).
- 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:
- 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:
- 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:
- property local_cells¶
An array containing the cell IDs of those neurons in the Population that exist on the local MPI node.
- 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:
- 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.
- 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:
- 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
- property all_cells¶
An array containing the cell IDs of all neurons in the Population (all MPI nodes).
- can_record(variable)[source]¶
Determine whether variable can be recorded from this population.
- Return type:
- property celltype¶
The type of neurons making up the underlying Population.
- Return type:
- property conductance_based¶
Whether the post-synaptic response is modelled as a change in conductance or a change in current.
- Return type:
- 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.
- find_units(variable)[source]¶
Get the units of a variable
Warning
No PyNN description of this method.
- 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.
- 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:
- 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.
- 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:
- 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.
- 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, orlists / 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 mask¶
The selector mask that was used to create this view.
- property parent¶
A reference to the parent Population (that this is a view of).
- Return type:
- 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:
- Return type:
- set(**parameters)[source]¶
Set one or more parameters for every cell in the population. Values passed to set() may be:
single values,
RandomDistribution
objects, orlists / 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, orlists / 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)
- spinnaker_get_data(variable, as_matrix=False)[source]¶
Public accessor for getting data as a numpy array, instead of the Neo-based object
- 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.