superneuromat.NeuronListView#

class superneuromat.NeuronListView(model: SNN, indices: list[int] | slice | None = None, max_len: int | None = None)[source]#

Redirects indexing to the SNN’s neurons.

Returns a Neuron or a list of Neurons.

This is used to allow for the following syntax:

snn.neurons[0]
snn.neurons[1:10]

You can take a view of a view:

snn.neurons[0:10][-5:]

You can add two views together. This will return a view of the concatenation of the two views.

However, if you add a view and something containing neurons from another model, or some other type of object,the result will be a list.

Equivalence checking can be done between views and views, or views and an iterable. In the latter case, element-wise equality is used.

Attributes:
ispikes
leaks
m

The SNN that this object is associated with.

num_onmodel
refractory_periods
refractory_periods_state
reset_states
states
thresholds

Methods

add(other[, right])

Concatenate this ListView with another iterable.

add_spike(time, idx[, value, exist])

Adds an external spike in the SNN

add_spikes(spikes[, time_offset, exist])

Add a time-series of spikes to this neuron.

append(x)

Append a compatible object to this ListView.

clear()

Make this ListView empty by clearing the indices of this ListView.

clear_input_spikes([t, destination, ...])

Delete input spikes from the SNN.

copy([model])

Create a copy of this ListView with the same indices, referring to the same SNN.

count(value)

Return the number of occurrences of value in this ListView.

extend(li)

Extend this ListView with the given iterable of compatible objects.

index(value[, start, stop])

Return the index of value in this ListView.

info([max_entries])

Generate a summary of the objects in this ListView.

insert(i, x)

Insert a compatible object at the given index in this ListView.

pop([index])

Remove and return the last item, or the item at the given index.

pretty_spike_train([max_steps, max_neurons, ...])

Returns a list[str] showing the spike train for each neuron in this NeuronListView.

print_spike_train([max_steps, max_neurons, ...])

Prints the spike train for each neuron in this NeuronListView.

remove(value)

Remove the first occurrence of value from this ListView.

reverse()

Reverse the order of the items in this ListView.

sort([key, reverse])

Sort the items in this ListView.

tolist()

Returns a list of the objects in this ListView.

using_model(model)

Returns a copy of the listview using the given model.

add(other, right=False)[source]#

Concatenate this ListView with another iterable.

Parameters:
Returns:

If both operands self + other are ModelListViews of the same type and model, returns a ModelListView of the same type and model with the concatenated indices. Otherwise, returns a list of the concatenated objects.

Return type:

NeuronListView | SynapseListView | list[ModelAccessor | Any]

add_spike(time: int, idx: int, value=1.0, exist='error')[source]#

Adds an external spike in the SNN

Parameters:
  • time (int) – The time step at which the external spike is added

  • idx (int) – The neuron for which the external spike is added

  • value (float) – The value of the external spike (default: 1.0)

  • exist (str) –

    action for existing spikes on a neuron at a given time step. Should be one of [‘error’, ‘overwrite’, ‘add’, ‘dontadd’]. (default: ‘error’)

    if exist=’add’, the existing spike value is added to the new value.

Raises:
  • TypeError

    if:

    • time cannot be precisely cast to int

    • neuron_id is not an int

    • value is not an int or float

  • ValueError – if spike already exists at that neuron and timestep and exist=’error’, or if exist is an invalid setting.

add_spikes(spikes: float | ~collections.abc.Sequence[float] | ~collections.abc.Sequence[~collections.abc.Sequence[float]] | ~numpy.ndarray[(<class 'int'>,), ~numpy.dtype] | ~numpy.ndarray[(<class 'int'>, <class 'int'>), ~numpy.dtype], time_offset: int = 0, exist: str = 'error')[source]#

Add a time-series of spikes to this neuron.

Parameters:
  • spikes (numpy.typing.ArrayLike)

  • time_offset (int, default=0) – The number of time steps to offset the spikes by.

  • exist (str, default='error') –

    Action if a queued spike already exists at the given time step. Should be one of [‘error’, ‘overwrite’, ‘add’, ‘dontadd’].

    Note: 0.0-valued spikes are not added unless exist='overwrite'.

If the input is a scalar, a single spike is sent to each neuron in this NeuronListView at time time_offset.

If the input is a 1-dimensional array, it is assumed to be the values of spikes to send to each neuron in this NeuronListView at time time_offset.

If the input is a 2-dimensional array, it is assumed to be, for each time step, a list of values to send to each neuron in this NeuronListView, starting at time time_offset. That is, the first row of the array corresponds to the first time step, the second row to the second time step, and so on.

append(x)[source]#

Append a compatible object to this ListView.

Parameters:

x (Neuron | Synapse) – The object to append to this ListView.

Raises:
  • RuntimeError – If this ListView is not associated with an SNN.

  • ValueError – if x is not the same accessor type as this ListView (i.e. you can’t add a Neuron to a SynapseListView), or if x is not from the same model.

clear()[source]#

Make this ListView empty by clearing the indices of this ListView.

clear_input_spikes(t: int | slice | list | ndarray | None = None, destination: int | slice | list | ndarray | None = None, remove_empty: bool = True)[source]#

Delete input spikes from the SNN.

Parameters:
  • t (int | slice | list | np.ndarray | None, default=None) – The time step(s) from which to delete input spikes. If None, delete input spikes across all time steps.

  • destination (int | Neuron | slice | list | np.ndarray | None, default=None) – The neuron(s) from which to delete input spikes. If None, delete all input spikes from only neurons in this NeuronListView.

  • remove_empty (bool, default=True) – If True, remove empty time steps from the input spike train.

copy(model=None)[source]#

Create a copy of this ListView with the same indices, referring to the same SNN.

count(value)[source]#

Return the number of occurrences of value in this ListView.

Parameters:

value (int | Neuron | Synapse)

Returns:

The number of occurrences of value in this ListView.

If value can be cast to int (excluding ModelAccessors), then the number of occurrences of that index in the ListView.

Return type:

int

extend(li)[source]#

Extend this ListView with the given iterable of compatible objects.

Parameters:

li (Sequence[Neuron] | Sequence[Synapse]) – The iterable of objects to extend this ListView with.

Raises:
  • RuntimeError – If this ListView is not associated with an SNN.

  • ValueError – if any of the objects are not the same accessor type as this ListView (i.e. you can’t add a Neuron to a SynapseListView), or if any of the objects in are not from the same model.

index(value, start=0, stop=9223372036854775807)[source]#

Return the index of value in this ListView.

Parameters:
  • value (Neuron | Synapse)

  • start (int, optional) – The starting index of the search, by default 0

  • stop (_type_, optional) – The ending index of the search (non-inclusive), by default sys.maxsize

Returns:

first index of value in this ListView.

Return type:

int

Raises:

ValueError – if the value is not present.

info(max_entries: int | None = 30)[source]#

Generate a summary of the objects in this ListView.

Similar to SNN.neuron_info() or SNN.synapse_info(), but only including information about objects in this ListView.

Parameters:

max_entries (int | None, default=30) – Limits the number of entries which will be included. If None, all entries will be included.

Return type:

str

insert(i, x)[source]#

Insert a compatible object at the given index in this ListView.

Parameters:
  • i (int) – The index at which to insert x.

  • x (Neuron | Synapse) – The object to insert into this ListView.

Raises:
  • RuntimeError – If this ListView is not associated with an SNN.

  • ValueError – if x is not the same accessor type as this ListView (i.e. you can’t add a Neuron to a SynapseListView), or if x is not from the same model.

property m[source]#

The SNN that this object is associated with.

When setting this property, the object is moved from its current model to the new model, if possible.

pop(index=-1)[source]#

Remove and return the last item, or the item at the given index.

Parameters:

index (int, optional) – The index (in this list) of the item to return If not specified, the last item is returned.

Returns:

NeuronListViews will return Neurons, SynapseListViews will return Synapses.

Return type:

Neuron | Synapse

pretty_spike_train(max_steps=None, max_neurons=None, use_unicode=True, indices=None)[source]#

Returns a list[str] showing the spike train for each neuron in this NeuronListView.

print_spike_train(max_steps=None, max_neurons=None, use_unicode=True, indices=None)[source]#

Prints the spike train for each neuron in this NeuronListView.

remove(value)[source]#

Remove the first occurrence of value from this ListView.

Parameters:

value (Neuron | Synapse) – The item to remove from this ListView.

Raises:
reverse()[source]#

Reverse the order of the items in this ListView.

sort(key=None, reverse=False)[source]#

Sort the items in this ListView.

Parameters:
  • key (callable | None, default=None) – A function to be called on each item in the ListView. The function should take a single argument, which will be the item from the ListView, and return a value that will be used for sorting. If None, the items will be sorted by its index in the SNN.

  • reverse (bool, default=False) – If True, the items will be sorted in descending order.

tolist()[source]#

Returns a list of the objects in this ListView.

using_model(model)[source]#

Returns a copy of the listview using the given model.