PyNN API version 0.7¶
Simulation setup and control¶
setup(timestep=0.1, min_delay=0.1, max_delay=10.0, **extra_params)¶
Should be called at the very beginning of a script. extra_params contains any keyword arguments that are required by a given simulator but not by others.
end(compatible_output=True)¶
Do any necessary cleaning up before exiting.
run(simtime)¶
Run the simulation for simtime ms.
run()
may be called multiple times during a simulation.
In between calls to run()
it is possible to retrieve data
and modify neuron/synapse parameters. Some backends allow modification of
the network structure. run(x + y)
is equivalent to run(x)
followed by run(y)
. If you wish to reset the simulation state to
the initial conditions (time t = 0
), use the reset()
function.
reset()¶
Reset the time to zero, neuron membrane potentials and synaptic weights to their initial values, and delete any recorded data. The network structure is not changed, nor is the specification of which neurons to record from.
get_time_step()¶
Return the integration time step.
get_current_time()¶
Return the current time in the simulation.
get_min_delay()¶
Return the minimum allowed synaptic delay.
get_max_delay()¶
Return the maximum allowed synaptic delay.
rank()¶
Return the MPI rank of the current node.
num_processes()¶
Return the number of MPI processes.
Object-oriented interface for creating and recording networks¶
Population¶
An array of neurons all of the same type. ‘Population’ is used as a generic term intended to include layers, columns, nuclei, etc., of cells.
__add__(self, other)
A Population/PopulationView can be added to another Population, PopulationView or Assembly, returning an Assembly.
__getitem__(self, index)
Return either a single cell (ID object) from the Population, if index is an integer, or a subset of the cells (PopulationView object), if index is a slice or array.
Note that __getitem__ is called when using [] access, e.g.
p = Population(...)
p[2] is equivalent to p.__getitem__(2).
p[3:6] is equivalent to p.__getitem__(slice(3, 6))
__init__(self, size, cellclass, cellparams=None, structure=None, label=None)
Create a population of neurons all of the same type. size - number of cells in the Population. For backwards-compatibility,
n may also be a tuple giving the dimensions of a grid, e.g. n=(10,10) is equivalent to n=100 with structure=Grid2D()
cellclass should either be a standardized cell class (a class inheriting from common.standardmodels.StandardCellType) or a string giving the name of the simulator-specific model that makes up the population. cellparams should be a dict which is passed to the neuron model
constructor
structure should be a Structure instance. label is an optional name for the population.
__iter__(self)
Iterator over cell ids on the local node.
__len__(self)
Return the total number of cells in the population (all nodes).
all(self)
Iterator over cell ids on all nodes.
can_record(self, variable)
Determine whether variable can be recorded from this population.
describe(self, template=’population_default.txt’, engine=’default’)
Returns a human-readable description of the population.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context
will be returned.
get(self, parameter_name, gather=False)
Get the values of a parameter for every local cell in the population.
getSpikes(self, gather=True, compatible_output=True)
Return a 2-column numpy array containing cell ids and spike times for recorded cells. Useful for small populations, for example for single neuron Monte-Carlo.
get_gsyn(self, gather=True, compatible_output=True)
Return a 4-column numpy array containing cell ids, times and excitatory and inhibitory synaptic conductances for recorded cells.
get_spike_counts(self, gather=True)
Returns the number of spikes for each neuron.
get_v(self, gather=True, compatible_output=True)
Return a 3-column numpy array containing cell ids, times and Vm for recorded cells.
id_to_index(self, id)
Given the ID(s) of cell(s) in the Population, return its (their) index (order in the Population).
>>> assert p.id_to_index(p[5]) == 5
>>> assert p.id_to_index(p.index([1,2,3])) == [1,2,3]
id_to_local_index(self, id)
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.
initialize(self, variable, value)
Set the initial value of one of the state variables of the neurons in this population.
- value may either be a numeric value (all neurons set to the same
- value) or a RandomDistribution object (each neuron gets a different value)
inject(self, current_source)
Connect a current source to all cells in the Population.
is_local(self, id)
Determine whether the cell with the given ID exists on the local MPI node.
meanSpikeCount(self, gather=True)
Returns the mean number of spikes per neuron.
nearest(self, position)
Return the neuron closest to the specified position.
printSpikes(self, file, gather=True, compatible_output=True)
Write spike times to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “spiketime cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). This allows easy plotting of a ‘raster’ plot of spiketimes, with one line for each cell. The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the spike files. For parallel simulators, if gather 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 the cells simulated on that node.
print_gsyn(self, file, gather=True, compatible_output=True)
Write synaptic conductance traces to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “g_exc g_inh cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the voltage files.
print_v(self, file, gather=True, compatible_output=True)
Write membrane potential traces to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “v cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the voltage files. For parallel simulators, if gather 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 the cells simulated on that node.
randomInit(self, rand_distr)
Set initial membrane potentials for all the cells in the population to random values.
record(self, to_file=True)
Record spikes from all cells in the Population.
record_gsyn(self, to_file=True)
Record synaptic conductances for all cells in the Population.
record_v(self, to_file=True)
Record the membrane potential for all cells in the Population.
rset(self, parametername, rand_distr)
‘Random’ set. Set the value of parametername to a value taken from rand_distr, which should be a RandomDistribution object.
sample(self, n, rng=None)
Randomly sample n cells from the Population, and return a PopulationView object.
save_positions(self, file)
Save positions to file. The output format is id x y z
set(self, param, val=None)
Set one or more parameters for every cell in the population.
param can be a dict, in which case val should not be supplied, or a string giving the parameter name, in which case val is the parameter value. val can be a numeric value, or list of such (e.g. for setting spike times).
- e.g. p.set(“tau_m”,20.0).
- p.set({‘tau_m’:20,’v_rest’:-65})
tset(self, parametername, value_array)
‘Topographic’ set. Set the value of parametername to the values in value_array, which must have the same dimensions as the Population.
PopulationView¶
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.
__add__(self, other)
A Population/PopulationView can be added to another Population, PopulationView or Assembly, returning an Assembly.
__getitem__(self, index)
Return either a single cell (ID object) from the Population, if index is an integer, or a subset of the cells (PopulationView object), if index is a slice or array.
Note that __getitem__ is called when using [] access, e.g.
p = Population(...)
p[2] is equivalent to p.__getitem__(2).
p[3:6] is equivalent to p.__getitem__(slice(3, 6))
__init__(self, parent, selector, label=None)
Create a view of a subset of neurons within a parent Population or PopulationView.
- selector - a slice or numpy mask array. The mask array should either be
a boolean array of the same size as the parent, or an integer array containing cell indices, i.e. if p.size == 5,
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.
__iter__(self)
Iterator over cell ids on the local node.
__len__(self)
Return the total number of cells in the population (all nodes).
all(self)
Iterator over cell ids on all nodes.
can_record(self, variable)
Determine whether variable can be recorded from this population.
describe(self, template=’populationview_default.txt’, engine=’default’)
Returns a human-readable description of the population view.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context
will be returned.
get(self, parameter_name, gather=False)
Get the values of a parameter for every local cell in the population.
getSpikes(self, gather=True, compatible_output=True)
Return a 2-column numpy array containing cell ids and spike times for recorded cells. Useful for small populations, for example for single neuron Monte-Carlo.
get_gsyn(self, gather=True, compatible_output=True)
Return a 4-column numpy array containing cell ids, times and excitatory and inhibitory synaptic conductances for recorded cells.
get_spike_counts(self, gather=True)
Returns the number of spikes for each neuron.
get_v(self, gather=True, compatible_output=True)
Return a 3-column numpy array containing cell ids, times and Vm for recorded cells.
id_to_index(self, id)
Given the ID(s) of cell(s) in the PopulationView, return its/their index/indices (order in the PopulationView).
>>> assert id_to_index(p.index(5)) == 5
>>> assert id_to_index(p.index([1,2,3])) == [1,2,3]
initialize(self, variable, value)
Set initial values of state variables, e.g. the membrane potential. value may either be a numeric value (all neurons set to the same
value) or a RandomDistribution object (each neuron gets a different value)
inject(self, current_source)
Connect a current source to all cells in the Population.
is_local(self, id)
Determine whether the cell with the given ID exists on the local MPI node.
meanSpikeCount(self, gather=True)
Returns the mean number of spikes per neuron.
nearest(self, position)
Return the neuron closest to the specified position.
printSpikes(self, file, gather=True, compatible_output=True)
Write spike times to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “spiketime cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). This allows easy plotting of a ‘raster’ plot of spiketimes, with one line for each cell. The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the spike files. For parallel simulators, if gather 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 the cells simulated on that node.
print_gsyn(self, file, gather=True, compatible_output=True)
Write synaptic conductance traces to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “g_exc g_inh cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the voltage files.
print_v(self, file, gather=True, compatible_output=True)
Write membrane potential traces to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “v cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the voltage files. For parallel simulators, if gather 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 the cells simulated on that node.
randomInit(self, rand_distr)
Set initial membrane potentials for all the cells in the population to random values.
record(self, to_file=True)
Record spikes from all cells in the Population.
record_gsyn(self, to_file=True)
Record synaptic conductances for all cells in the Population.
record_v(self, to_file=True)
Record the membrane potential for all cells in the Population.
rset(self, parametername, rand_distr)
‘Random’ set. Set the value of parametername to a value taken from rand_distr, which should be a RandomDistribution object.
sample(self, n, rng=None)
Randomly sample n cells from the Population, and return a PopulationView object.
save_positions(self, file)
Save positions to file. The output format is id x y z
set(self, param, val=None)
Set one or more parameters for every cell in the population. param can be a dict, in which case val should not be supplied, or a string giving the parameter name, in which case val is the parameter value. val can be a numeric value, or list of such (e.g. for setting spike times).
- e.g. p.set(“tau_m”,20.0).
- p.set({‘tau_m’:20,’v_rest’:-65})
tset(self, parametername, value_array)
‘Topographic’ set. Set the value of parametername to the values in value_array, which must have the same dimensions as the Population.
Assembly¶
A group of neurons, may be heterogeneous, in contrast to a Population where all the neurons are of the same type.
__add__(self, other)
An Assembly may be added to a Population, PopulationView or Assembly with the ‘+’ operator, returning a new Assembly, e.g.:
a2 = a1 + p
__getitem__(self, index)
Where index is an integer, return an ID. Where index is a slice, list or numpy array, return a new Assembly
consisting of appropriate populations and (possibly newly created) population views.
__iadd__(self, other)
A Population, PopulationView or Assembly may be added to an existing Assembly using the ‘+=’ operator, e.g.:
a += p
__init__(self, *populations, **kwargs)
Create an Assembly of Populations and/or PopulationViews.
kwargs may contain a keyword argument ‘label’.
__iter__(self)
Iterator over cells in all populations within the Assembly, for cells on the local MPI node.
__len__(self)
Return the total number of cells in the population (all nodes).
describe(self, template=’assembly_default.txt’, engine=’default’)
Returns a human-readable description of the assembly.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context
will be returned.
get_gsyn(self, gather=True, compatible_output=True)
Return a 4-column numpy array containing cell ids, times and excitatory and inhibitory synaptic conductances for recorded cells.
get_population(self, label)
Return the Population/PopulationView from within the Assembly that has the given label. If no such Population exists, raise KeyError.
get_spike_counts(self, gather=True)
Returns the number of spikes for each neuron.
get_v(self, gather=True, compatible_output=True)
Return a 3-column numpy array containing cell ids, times and Vm for recorded cells.
id_to_index(self, id)
Given the ID(s) of cell(s) in the Assembly, return its (their) index (order in the Assembly).
>>> assert p.id_to_index(p[5]) == 5
>>> assert p.id_to_index(p.index([1,2,3])) == [1,2,3]
initialize(self, variable, value)
Set the initial value of one of the state variables of the neurons in this assembly. value` may either be a numeric value (all neurons set to the same value) or a !!RandomDistribution object (each neuron gets a different value)
inject(self, current_source)
Connect a current source to all cells in the Assembly.
meanSpikeCount(self, gather=True)
Returns the mean number of spikes per neuron.
printSpikes(self, file, gather=True, compatible_output=True)
Write spike times to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “spiketime cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). This allows easy plotting of a ‘raster’ plot of spiketimes, with one line for each cell. The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the spike files. For parallel simulators, if gather 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 the cells simulated on that node.
print_gsyn(self, file, gather=True, compatible_output=True)
Write synaptic conductance traces to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “g_exc g_inh cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the voltage files.
print_v(self, file, gather=True, compatible_output=True)
Write membrane potential traces to file. file should be either a filename or a PyNN File object. If compatible_output is True, the format is “v cell_id”, where cell_id is the index of the cell counting along rows and down columns (and the extension of that for 3-D). The timestep, first id, last id, and number of data points per cell are written in a header, indicated by a ‘#’ at the beginning of the line. If compatible_output is False, the raw format produced by the simulator is used. This may be faster, since it avoids any post-processing of the voltage files. For parallel simulators, if gather 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 the cells simulated on that node.
record(self, to_file=True)
Record spikes from all cells in the Assembly.
record_gsyn(self, to_file=True)
Record synaptic conductances from all cells in the Assembly.
record_v(self, to_file=True)
Record the membrane potential from all cells in the Assembly.
save_positions(self, file)
Save positions to file. The output format is id x y z
Classes for defining spatial structure¶
Space¶
Class representing a space within distances can be calculated. The space is Cartesian, may be 1-, 2- or 3-dimensional, and may have periodic boundaries in any of the dimensions.
__init__(self, axes=None, scale_factor=1.0, offset=0.0, periodic_boundaries=None)
- axes – if not supplied, then the 3D distance is calculated. If supplied,
- axes should be a string containing the axes to be used, e.g. ‘x’, or ‘yz’. axes=’xyz’ is the same as axes=None.
- scale_factor – it may be that the pre and post populations use
- different units for position, e.g. degrees and µm. In this case, scale_factor can be specified, which is applied to the positions in the post-synaptic population.
- offset – if the origins of the coordinate systems of the pre- and post-
- synaptic populations are different, offset can be used to adjust for this difference. The offset is applied before any scaling.
- periodic_boundaries – either None, or a tuple giving the boundaries
- for each dimension, e.g. ((x_min, x_max), None, (z_min, z_max)).
distance_generator(self, f, g)
Return a function that calculates the distance matrix as a function of indices i,j, given two functions f(i) and g(j) that return coordinates.
distances(self, A, B, expand=False)
Calculate the distance matrix between two sets of coordinates, given the topology of the current space. From http://projects.scipy.org/pipermail/numpy-discussion/2007-April/027203.html
Line¶
Represents a structure with neurons distributed evenly on a straight line.
__eq__(self, other)
__init__(self, dx=1.0, x0=0.0, y0=0.0, z0=0.0)
describe(self, template=’structure_default.txt’, engine=’default’)
Returns a human-readable description of the network structure.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context will be returned.
generate_positions(self, n)
get_parameters(self)
Grid2D¶
Represents a structure with neurons distributed on a 2D grid.
__eq__(self, other)
__init__(self, aspect_ratio=1.0, dx=1.0, dy=1.0, x0=0.0, y0=0.0, z=0, fill_order=’sequential’)
- aspect_ratio - ratio of the number of grid points per side (not the ratio
- of the side lengths, unless dx == dy)
calculate_size(self, n)
describe(self, template=’structure_default.txt’, engine=’default’)
Returns a human-readable description of the network structure.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context will be returned.
generate_positions(self, n)
get_parameters(self)
Grid3D¶
Represents a structure with neurons distributed on a 3D grid.
__eq__(self, other)
__init__(self, aspect_ratioXY=1.0, aspect_ratioXZ=1.0, dx=1.0, dy=1.0, dz=1.0, x0=0.0, y0=0.0, z0=0, fill_order=’sequential’)
If fill_order is ‘sequential’, the z-index will be filled first, then y then x, i.e. the first cell will be at (0,0,0) (given default values for the other arguments), the second at (0,0,1), etc.
calculate_size(self, n)
describe(self, template=’structure_default.txt’, engine=’default’)
Returns a human-readable description of the network structure.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context will be returned.
generate_positions(self, n)
get_parameters(self)
RandomStructure¶
Represents a structure with neurons distributed randomly within a given volume.
__eq__(self, other)
__init__(self, boundary, origin=(0.0, 0.0, 0.0), rng=None)
boundary - a subclass of Shape origin - a coordinate tuple (x,y,z)
describe(self, template=’structure_default.txt’, engine=’default’)
Returns a human-readable description of the network structure.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context will be returned.
generate_positions(self, n)
get_parameters(self)
Cuboid¶
Represents a cuboidal volume within which neurons may be distributed.
__init__(self, width, height, depth)
height: extent in y direction width: extent in x direction depth: extent in z direction
sample(self, n, rng)
Sphere¶
Represents a spherical volume within which neurons may be distributed.
__init__(self, radius)
sample(self, n, rng)
Object-oriented interface for connecting populations of neurons¶
Projection¶
A container for all the connections of a given type (same synapse type and plasticity mechanisms) between two populations, together with methods to set parameters of those connections, including of plasticity mechanisms.
__getitem__(self, i)
Return the `i`th connection within the Projection.
__init__(self, presynaptic_population, postsynaptic_population, method, source=None, target=None, synapse_dynamics=None, label=None, rng=None)
presynaptic_population and postsynaptic_population - Population objects.
- source - string specifying which attribute of the presynaptic cell
- signals action potentials
- target - string specifying which synapse on the postsynaptic cell to
- connect to
If source and/or target are not given, default values are used.
- method - a Connector object, encapsulating the algorithm to use for
- connecting the neurons.
synapse_dynamics - a SynapseDynamics object specifying which synaptic plasticity mechanisms to use.
rng - specify an RNG object to be used by the Connector.
__len__(self)
Return the total number of local connections.
describe(self, template=’projection_default.txt’, engine=’default’)
Returns a human-readable description of the projection.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context
will be returned.
getDelays(self, format=’list’, gather=True)
Get synaptic delays for all connections in this Projection. Possible formats are: a list of length equal to the number of connections in the projection, a 2D delay array (with NaN for non-existent connections).
getSynapseDynamics(self, parameter_name, format=’list’, gather=True)
Get parameters of the dynamic synapses for all connections in this Projection.
getWeights(self, format=’list’, gather=True)
Get synaptic weights for all connections in this Projection. Possible formats are: a list of length equal to the number of connections in the projection, a 2D weight array (with NaN for non-existent connections). Note that for the array format, if there is more than one connection between two cells, the summed weight will be given.
printWeights(self, file, format=’list’, gather=True)
Print synaptic weights to file. In the array format, zeros are printed for non-existent connections.
randomizeDelays(self, rand_distr)
Set weights to random values taken from rand_distr.
randomizeSynapseDynamics(self, param, rand_distr)
Set parameters of the synapse dynamics to values taken from rand_distr
randomizeWeights(self, rand_distr)
Set weights to random values taken from rand_distr.
saveConnections(self, file, gather=True, compatible_output=True)
Save connections to file in a format suitable for reading in with a FromFileConnector.
setDelays(self, d)
d can be a single number, in which case all delays are set to this value, or a list/1D array of length equal to the number of connections in the projection, or a 2D array with the same dimensions as the connectivity matrix (as returned by getDelays(format=’array’)).
setSynapseDynamics(self, param, value)
Set parameters of the dynamic synapses for all connections in this projection.
setWeights(self, w)
w can be a single number, in which case all weights are set to this value, or a list/1D array of length equal to the number of connections in the projection, or a 2D array with the same dimensions as the connectivity matrix (as returned by getWeights(format=’array’)). Weights should be in nA for current-based and µS for conductance-based synapses.
size(self, gather=True)
- Return the total number of connections.
- only local connections, if gather is False,
- all connections, if gather is True (default)
weightHistogram(self, min=None, max=None, nbins=10)
Return a histogram of synaptic weights. If min and max are not given, the minimum and maximum weights are calculated automatically.
AllToAllConnector¶
Connects all cells in the presynaptic population to all cells in the postsynaptic population.
__init__(self, allow_self_connections=True, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x62749f0>, safe=True, verbose=False)
Create a new connector.
- allow_self_connections – if the connector is used to connect a
- Population to itself, this flag determines whether a neuron is allowed to connect to itself, or only to other neurons in the Population.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
- space – a Space object, needed if you wish to specify distance-
- dependent weights or delays
OneToOneConnector¶
Where the pre- and postsynaptic populations have the same size, connect cell i in the presynaptic population to cell i in the postsynaptic population for all i.
__init__(self, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x17d30e50>, safe=True, verbose=False)
Create a new connector.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
FixedProbabilityConnector¶
For each pair of pre-post cells, the connection probability is constant.
__init__(self, p_connect, allow_self_connections=True, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x5912970>, safe=True, verbose=False)
Create a new connector.
- p_connect – a float between zero and one. Each potential connection
- is created with this probability.
- allow_self_connections – if the connector is used to connect a
- Population to itself, this flag determines whether a neuron is allowed to connect to itself, or only to other neurons in the Population.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
- space – a Space object, needed if you wish to specify distance-
- dependent weights or delays
DistanceDependentProbabilityConnector¶
For each pair of pre-post cells, the connection probability depends on distance.
__init__(self, d_expression, allow_self_connections=True, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x58ae570>, safe=True, verbose=False, n_connections=None)
Create a new connector.
- d_expression – the right-hand side of a valid python expression for
- probability, involving ‘d’, e.g. “exp(-abs(d))”, or “d<3”
n_connections – The number of efferent synaptic connections per neuron.
space – a Space object.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created, or a DistanceDependence object. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
FixedNumberPreConnector¶
Each post-synaptic neuron is connected to exactly n pre-synaptic neurons chosen at random.
If n is less than the size of the pre-synaptic population, there are no multiple connections, i.e., no instances of the same pair of neurons being multiply connected. If n is greater than the size of the pre-synaptic population, all possible single connections are made before starting to add duplicate connections.
__init__(self, n, allow_self_connections=True, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x17d30e10>, safe=True, verbose=False)
Create a new connector.
- n – either a positive integer, or a RandomDistribution that produces
- positive integers. If n is a RandomDistribution, then the number of pre-synaptic neurons is drawn from this distribution for each post-synaptic neuron.
- allow_self_connections – if the connector is used to connect a
- Population to itself, this flag determines whether a neuron is allowed to connect to itself, or only to other neurons in the Population.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
FixedNumberPostConnector¶
Each pre-synaptic neuron is connected to exactly n post-synaptic neurons chosen at random.
If n is less than the size of the post-synaptic population, there are no multiple connections, i.e., no instances of the same pair of neurons being multiply connected. If n is greater than the size of the post-synaptic population, all possible single connections are made before starting to add duplicate connections.
__init__(self, n, allow_self_connections=True, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x58aead0>, safe=True, verbose=False)
Create a new connector.
- n – either a positive integer, or a RandomDistribution that produces
- positive integers. If n is a RandomDistribution, then the number of post-synaptic neurons is drawn from this distribution for each pre-synaptic neuron.
- allow_self_connections – if the connector is used to connect a
- Population to itself, this flag determines whether a neuron is allowed to connect to itself, or only to other neurons in the Population.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
FromListConnector¶
Make connections according to a list.
__init__(self, conn_list, safe=True, verbose=False)
Create a new connector.
- conn_list – a list of tuples, one tuple for each connection. Each
- tuple should contain:
- (pre_idx, post_idx, weight, delay)
where pre_idx is the index (i.e. order in the Population, not the ID) of the presynaptic neuron, and post_idx is the index of the postsynaptic neuron.
FromFileConnector¶
Make connections according to a list read from a file.
__init__(self, file, distributed=False, safe=True, verbose=False)
Create a new connector.
- file – file object containing a list of connections, in
- the format required by FromListConnector.
- distributed – if this is True, then each node will read connections
- from a file called filename.x, where x is the MPI rank. This speeds up loading connections for distributed simulations.
SmallWorldConnector¶
For each pair of pre-post cells, the connection probability depends on distance.
__init__(self, degree, rewiring, allow_self_connections=True, weights=0.0, delays=None, space=<pyNN.space.Space object at 0x17d30e90>, safe=True, verbose=False)
Create a new connector.
degree – the region lenght where nodes will be connected locally
rewiring – the probability of rewiring each eadges
space – a Space object.
- allow_self_connections – if the connector is used to connect a
- Population to itself, this flag determines whether a neuron is allowed to connect to itself, or only to other neurons in the Population.
- weights – may either be a float, a RandomDistribution object, a list/
- 1D array with at least as many items as connections to be created, or a DistanceDependence object. Units nA.
- delays – as weights. If None, all synaptic delays will be set
- to the global minimum delay.
Procedural interface for creating, connecting and recording networks¶
create(cellclass, cellparams=None, n=1)¶
Create n cells all of the same type. If n > 1, return a list of cell ids/references. If n==1, return just the single id.
connect(source, target, weight=0.0, delay=None, synapse_type=None, p=1, rng=None)¶
Connect a source of spikes to a synaptic target. source and target can both be individual cells or lists of cells, in which case all possible connections are made with probability p, using either the random number generator supplied, or the default rng otherwise. Weights should be in nA or µS.
set(cells, param, val=None)¶
Set one or more parameters of an individual cell or list of cells. param can be a dict, in which case val should not be supplied, or a string giving the parameter name, in which case val is the parameter value.
initialize(cells, variable, value)¶
record(source, filename)¶
Record spikes to a file. source can be an individual cell, a Population, PopulationView or Assembly.
record(source, filename)¶
Record membrane potential to a file. source can be an individual cell, a Population, PopulationView or Assembly.
record(source, filename)¶
Record synaptic conductances to a file. source can be an individual cell, a Population, PopulationView or Assembly.
Standard neuron models¶
IF_curr_exp¶
Leaky integrate and fire model with fixed threshold and decaying-exponential post-synaptic current. (Separate synaptic currents for excitatory and inhibitory synapses.
__init__(self, parameters)
default_parameters = {
‘tau_refrac’: | 0.1 |
‘v_thresh’: | -50.0 |
‘tau_m’: | 20.0 |
‘tau_syn_E’: | 5.0 |
‘v_rest’: | -65.0 |
‘cm’: | 1.0 |
‘v_reset’: | -65.0 |
‘tau_syn_I’: | 5.0 |
‘i_offset’: | 0.0 |
}
IF_curr_alpha¶
Leaky integrate and fire model with fixed threshold and alpha-function- shaped post-synaptic current.
__init__(self, parameters)
default_parameters = {
‘tau_refrac’: | 0.1 |
‘v_thresh’: | -50.0 |
‘tau_m’: | 20.0 |
‘tau_syn_E’: | 0.5 |
‘v_rest’: | -65.0 |
‘cm’: | 1.0 |
‘v_reset’: | -65.0 |
‘tau_syn_I’: | 0.5 |
‘i_offset’: | 0.0 |
}
IF_cond_exp¶
Leaky integrate and fire model with fixed threshold and exponentially-decaying post-synaptic conductance.
__init__(self, parameters)
default_parameters = {
‘tau_refrac’: | 0.1 |
‘cm’: | 1.0 |
‘tau_syn_E’: | 5.0 |
‘v_rest’: | -65.0 |
‘tau_syn_I’: | 5.0 |
‘tau_m’: | 20.0 |
‘e_rev_E’: | 0.0 |
‘i_offset’: | 0.0 |
‘e_rev_I’: | -70.0 |
‘v_thresh’: | -50.0 |
‘v_reset’: | -65.0 |
}
IF_cond_alpha¶
Leaky integrate and fire model with fixed threshold and alpha-function- shaped post-synaptic conductance.
__init__(self, parameters)
default_parameters = {
‘tau_refrac’: | 0.1 |
‘cm’: | 1.0 |
‘tau_syn_E’: | 0.3 |
‘v_rest’: | -65.0 |
‘tau_syn_I’: | 0.5 |
‘tau_m’: | 20.0 |
‘e_rev_E’: | 0.0 |
‘i_offset’: | 0.0 |
‘e_rev_I’: | -70.0 |
‘v_thresh’: | -50.0 |
‘v_reset’: | -65.0 |
}
EIF_cond_exp_isfa_ista¶
Exponential integrate and fire neuron with spike triggered and sub-threshold adaptation currents (isfa, ista reps.) according to:
Brette R and Gerstner W (2005) Adaptive Exponential Integrate-and-Fire Model as an Effective Description of Neuronal Activity. J Neurophysiol 94:3637-3642 See also: IF_cond_exp_gsfa_grr
__init__(self, parameters)
default_parameters = {
‘tau_refrac’: | 0.1 |
‘a’: | 4.0 |
‘tau_m’: | 9.3667 |
‘e_rev_E’: | 0.0 |
‘i_offset’: | 0.0 |
‘cm’: | 0.281 |
‘delta_T’: | 2.0 |
‘e_rev_I’: | -80.0 |
‘v_thresh’: | -50.4 |
‘b’: | 0.0805 |
‘tau_syn_E’: | 5.0 |
‘v_reset’: | -70.6 |
‘v_spike’: | -40.0 |
‘tau_syn_I’: | 5.0 |
‘tau_w’: | 144.0 |
‘v_rest’: | -70.6 |
}
EIF_cond_alpha_isfa_ista¶
Exponential integrate and fire neuron with spike triggered and sub-threshold adaptation currents (isfa, ista reps.) according to:
Brette R and Gerstner W (2005) Adaptive Exponential Integrate-and-Fire Model as an Effective Description of Neuronal Activity. J Neurophysiol 94:3637-3642 See also: IF_cond_exp_gsfa_grr
__init__(self, parameters)
default_parameters = {
‘tau_refrac’: | 0.1 |
‘a’: | 4.0 |
‘tau_m’: | 9.3667 |
‘e_rev_E’: | 0.0 |
‘i_offset’: | 0.0 |
‘cm’: | 0.281 |
‘delta_T’: | 2.0 |
‘e_rev_I’: | -80.0 |
‘v_thresh’: | -50.4 |
‘b’: | 0.0805 |
‘tau_syn_E’: | 5.0 |
‘v_reset’: | -70.6 |
‘v_spike’: | -40.0 |
‘tau_syn_I’: | 5.0 |
‘tau_w’: | 144.0 |
‘v_rest’: | -70.6 |
}
IF_facets_hardware1¶
Leaky integrate and fire model with conductance-based synapses and fixed threshold as it is resembled by the FACETS Hardware Stage 1. For further details regarding the hardware model see the FACETS-internal Wiki: https://facets.kip.uni-heidelberg.de/private/wiki/index.php/WP7_NNM
__init__(self, parameters)
default_parameters = {
‘g_leak’: | 40.0 |
‘e_rev_I’: | -80.0 |
‘v_thresh’: | -55.0 |
‘tau_syn_E’: | 30.0 |
‘v_rest’: | -65.0 |
‘tau_syn_I’: | 30.0 |
‘v_reset’: | -80.0 |
}
HH_cond_exp¶
Single-compartment Hodgkin-Huxley model.
__init__(self, parameters)
default_parameters = {
‘gbar_K’: | 6.0 |
‘cm’: | 0.2 |
‘e_rev_Na’: | 50.0 |
‘tau_syn_E’: | 0.2 |
‘tau_syn_I’: | 2.0 |
‘i_offset’: | 0.0 |
‘g_leak’: | 0.01 |
‘e_rev_E’: | 0.0 |
‘gbar_Na’: | 20.0 |
‘e_rev_leak’: | -65.0 |
‘e_rev_I’: | -80.0 |
‘e_rev_K’: | -90.0 |
‘v_offset’: | -63.0 |
}
SpikeSourcePoisson¶
Spike source, generating spikes according to a Poisson process.
__init__(self, parameters)
default_parameters = {
‘duration’: | 10000000000.0 |
‘start’: | 0.0 |
‘rate’: | 1.0 |
}
SpikeSourceArray¶
Spike source generating spikes at the times given in the spike_times array.
__init__(self, parameters)
default_parameters = {
‘spike_times’: | [] |
}
Specification of synaptic plasticity¶
SynapseDynamics¶
For specifying synapse short-term (faciliation, depression) and long-term (STDP) plasticity. To be passed as the synapse_dynamics argument to Projection.__init__() or connect().
__init__(self, fast=None, slow=None)
Create a new specification for a dynamic synapse, combining a fast component (short-term facilitation/depression) and a slow component (long-term potentiation/depression).
describe(self, template=’synapsedynamics_default.txt’, engine=’default’)
Returns a human-readable description of the synapse dynamics.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context will be returned.
STDPMechanism¶
Specification of STDP models.
__init__(self, timing_dependence=None, weight_dependence=None, voltage_dependence=None, dendritic_delay_fraction=1.0)
describe(self, template=’stdpmechanism_default.txt’, engine=’default’)
Returns a human-readable description of the STDP mechanism.
The output may be customized by specifying a different template
togther with an associated template engine (see pyNN.descriptions
).
If template is None, then a dictionary containing the template context will be returned.
TsodyksMarkramMechanism¶
__init__(self, U=0.5, tau_rec=100.0, tau_facil=0.0, u0=0.0, x0=1.0, y0=0.0)
AdditiveWeightDependence¶
The amplitude of the weight change is fixed for depression (A_minus) and for potentiation (A_plus). If the new weight would be less than w_min it is set to w_min. If it would be greater than w_max it is set to w_max.
__init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01)
MultiplicativeWeightDependence¶
The amplitude of the weight change depends on the current weight. For depression, Dw propto w-w_min For potentiation, Dw propto w_max-w
__init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01)
AdditivePotentiationMultiplicativeDepression¶
The amplitude of the weight change depends on the current weight for depression (Dw propto w-w_min) and is fixed for potentiation.
__init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01)
GutigWeightDependence¶
The amplitude of the weight change depends on the current weight. For depression, Dw propto w-w_min For potentiation, Dw propto w_max-w
__init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01, mu_plus=0.5, mu_minus=0.5)
SpikePairRule¶
__init__(self, tau_plus=20.0, tau_minus=20.0)
Current injection¶
DCSource¶
Source producing a single pulse of current of constant amplitude.
__init__(self, amplitude=1.0, start=0.0, stop=None)
Construct the current source.
Arguments:
start – onset time of pulse in ms
stop – end of pulse in ms
amplitude – pulse amplitude in nA
inject_into(self, cell_list)
Inject this current source into some cells.
StepCurrentSource¶
A step-wise time-varying current source.
__init__(self, times, amplitudes)
Construct the current source.
Arguments:
times – list/array of times at which the injected current changes.
- amplitudes – list/array of current amplitudes to be injected at the
- times specified in times.
The injected current will be zero up until the first time in times. The current will continue at the final value in amplitudes until the end of the simulation.
inject_into(self, cell_list)
Inject this current source into some cells.
ACSource¶
Source producing a single pulse of current of constant amplitude.
__init__(self, amplitude=1.0, offset=0.0, frequency=10, phase=0.0, start=0.0, stop=None)
Construct the current source.
Arguments:
start – onset time of pulse in ms
stop – end of pulse in ms
amplitude – pulse amplitude in nA
sine_amp – sine amplitude in nA
frequency – frequency in Hz
phase – phase in degree
inject_into(self, cell_list)
Inject this current source into some cells.
NoisyCurrentSource¶
- A Gaussian “white” noise current source. The current amplitude changes at fixed
- intervals, with the new value drawn from a Gaussian distribution.
__init__(self, mean, stdev, dt=None, start=0.0, stop=None, rng=None)
Construct the current source.
Required arguments:
mean – mean current amplitude in nA
stdev – standard deviation of the current amplitude in nA
Optional arguments:
- dt – interval between updates of the current amplitude. Must be
- a multiple of the simulation time step. If not specified, the simulation time step will be used.
- start – onset of the current injection in ms. If not specified, the
- current will begin at the start of the simulation.
- stop – end of the current injection in ms. If not specified, the
- current will continue until the end of the simulation.
- rng – an RNG object from the pyNN.random module. For speed,
- this should be a NativeRNG instance (uses the simulator’s internal random number generator). For reproducibility across simulators, use one of the other RNG types. If not specified, a NumpyRNG is used.
inject_into(self, cell_list)
Inject this current source into some cells.
File formats¶
BaseFile¶
Base class for PyNN File classes.
__init__(self, filename, mode=’r’)
Open a file with the given filename and mode.
close(self)
Close the file.
get_metadata(self)
Read metadata from the file and return a dict.
read(self)
Read data from the file and return a NumPy array.
rename(self, filename)
write(self, data, metadata)
Write data and metadata to file. data should be a NumPy array, metadata should be a dictionary.
StandardTextFile¶
Data and metadata is written as text. Metadata is written at the top of the file, with each line preceded by “#”. Data is written with one data point per line.
PickleFile¶
Data and metadata are pickled and saved to file.
NumpyBinaryFile¶
Data and metadata are saved in .npz format, which is a zipped archive of arrays.
HDF5ArrayFile¶
Data are saved as an array within a node named “data”. Metadata are saved as attributes of this node.
Exceptions¶
InvalidParameterValueError¶
Inappropriate parameter value
NonExistentParameterError¶
Model parameter does not exist.
InvalidDimensionsError¶
Argument has inappropriate shape/dimensions.
ConnectionError¶
Attempt to create an invalid connection or access a non-existent connection.
InvalidModelError¶
Attempt to use a non-existent model type.
RoundingWarning¶
The argument has been rounded to a lower level of precision by the simulator.
NothingToWriteError¶
There is no data available to write.
InvalidWeightError¶
Invalid value for the synaptic weight.
NotLocalError¶
Attempt to access a cell or connection that does not exist on this node (but exists elsewhere).
RecordingError¶
Attempt to record a variable that does not exist for this cell type.
The random module¶
NumpyRNG¶
Wrapper for the numpy.random.RandomState class (Mersenne Twister PRNG).
__getattr__(self, name)
This is to give the PyNN RNGs the same methods as the wrapped RNGs (numpy.random.RandomState or the GSL RNGs.)
__init__(self, seed=None, parallel_safe=True)
describe(self)
next(self, n=1, distribution=’uniform’, parameters=[], mask_local=None)
Return n random numbers from the distribution.
If n >= 0, return a numpy array, if n < 0, raise an Exception.
GSLRNG¶
Wrapper for the GSL random number generators.
__getattr__(self, name)
This is to give GSLRNG the same methods as the GSL RNGs.
__init__(self, seed=None, type=’mt19937’, parallel_safe=True)
next(self, n=1, distribution=’uniform’, parameters=[], mask_local=None)
Return n random numbers from the distribution.
If n >= 0, return a numpy array,
if n < 0, raise an Exception.
NativeRNG¶
Signals that the simulator’s own native RNG should be used. Each simulator module should implement a class of the same name which inherits from this and which sets the seed appropriately.
__init__(self, seed=None)
next(self, n=1, distribution=’uniform’, parameters=[], mask_local=None)
Return n random numbers from the distribution.
If n is 1, return a float, if n > 1, return a Numpy array,
if n <= 0, raise an Exception.
RandomDistribution¶
Class which defines a next(n) method which returns an array of n random numbers from a given distribution.
__init__(self, distribution=’uniform’, parameters=[], rng=None, boundaries=None, constrain=’clip’)
If present, rng should be a NumpyRNG or GSLRNG object. distribution should be the name of a method supported by the underlying
random number generator object.
- parameters should be a list or tuple containing the arguments expected
- by the underlying method in the correct order. named arguments are not yet supported.
- boundaries is a tuple (min, max) used to specify explicitly, for distribution
- like Gaussian, Gamma or others, hard boundaries for the parameters. If parameters are drawn outside those boundaries, the policy applied will depend on the constrain parameter.
- constrain control the policy for weights out of the specified boundaries.
- If “clip”, random numbers are clipped to the boundaries. If “redraw”, random numbers are drawn till they fall within the boundaries.
- Note that NumpyRNG and GSLRNG distributions may not have the same names,
- e.g., ‘normal’ for NumpyRNG and ‘gaussian’ for GSLRNG, and the arguments may also differ.
next(self, n=1, mask_local=None)
Return n random numbers from the distribution.
The utility module¶
colour(col, text)¶
notify(msg=’Simulation finished.’, subject=’Simulation finished.’, smtphost=None, address=None)¶
Send an e-mail stating that the simulation has finished.
get_script_args(n_args, usage=’‘)¶
Get command line arguments.
This works by finding the name of the main script and assuming any arguments after this in sys.argv are arguments to the script. It would be nicer to use optparse, but this doesn’t seem to work too well with nrniv or mpirun.
init_logging(logfile, debug=False, num_processes=1, rank=0, level=None)¶
Timer¶
For timing script execution.
time_in_words(s)
- Formats a time in seconds as a string containing the time in days,
hours, minutes, seconds. Examples:
>>> time_in_words(1) 1 second >>> time_in_words(123) 2 minutes, 3 seconds >>> time_in_words(24*3600) 1 day
__init__(self)
diff(self, format=None)
Return the time since the last time elapsedTime() or diff() was called.
elapsedTime(self, format=None)
Return the elapsed time in seconds but keep the clock running.
reset(self)
Reset the time to zero, and start the clock.
start(self)
Start timing.
ProgressBar¶
Create a progress bar in the shell.
__init__(self, min_value=0, max_value=100, width=77, **kwargs)
build_bar(self)
Figure new percent complete, and rebuild the bar string base on self.amount.
increment_amount(self, add_amount=1)
Increment self.amount by ‘add_ammount’ or default to incrementing by 1, and then rebuild the bar string.
update_amount(self, new_amount=None)
Update self.amount with ‘new_amount’, and then rebuild the bar string.