spynnaker.pyNN.utilities package

Subpackages

Submodules

spynnaker.pyNN.utilities.bit_field_utilities module

spynnaker.pyNN.utilities.bit_field_utilities.FILTER_HEADER_WORDS = 2

n_filters, pointer for array

spynnaker.pyNN.utilities.bit_field_utilities.get_bitfield_key_map_data(incoming_projections: Iterable[Projection]) NDArray[uint32][source]
Parameters:

incoming_projections – The projections to generate bitfields for

Returns:

Data for the key map region.

spynnaker.pyNN.utilities.bit_field_utilities.get_sdram_for_bit_field_region(incoming_projections: Iterable[Projection]) int[source]

The SDRAM for the bit field filter region.

Parameters:

incoming_projections – The projections that target the vertex in question

Returns:

the estimated number of bytes used by the bit field region

spynnaker.pyNN.utilities.bit_field_utilities.get_sdram_for_keys(incoming_projections: Iterable[Projection]) int[source]

Gets the space needed for keys.

Parameters:

incoming_projections – The projections that target the vertex in question

Returns:

SDRAM needed

spynnaker.pyNN.utilities.bit_field_utilities.is_sdram_poisson_source(app_edge: ApplicationEdge) bool[source]
Returns:

True if a given app edge is a poisson source being sent over SDRAM as it can likely be discounted if so

spynnaker.pyNN.utilities.bit_field_utilities.write_bitfield_init_data(spec: DataSpecificationBase, bit_field_region: int, n_bit_field_bytes: int, bit_field_region_ref: int | None = None) None[source]

Writes the initialisation data needed for the bitfield generator.

Parameters:
  • spec – data specification writer

  • bit_field_region – the region ID for the bit-field filters

  • n_bit_field_bytes – the size of the region

  • bit_field_region_ref – The reference to the region

spynnaker.pyNN.utilities.buffer_data_type module

class spynnaker.pyNN.utilities.buffer_data_type.BufferDataType(value)[source]

Bases: Enum

Different functions to retrieve the data.

This class is designed to used internally by NeoBufferDatabase

EIEIO_SPIKES = 2
MATRIX = 4
MULTI_SPIKES = 3
NEURON_SPIKES = 1
NOT_NEO = 6
REWIRES = 5

spynnaker.pyNN.utilities.constants module

spynnaker.pyNN.utilities.constants.LIVE_POISSON_CONTROL_PARTITION_ID = 'CONTROL'

The partition ID used for Poisson live control data

spynnaker.pyNN.utilities.constants.MAX_RING_BUFFER_BITS = 14

The maximum number of bits for the ring buffer index that are likely to fit in DTCM (14-bits = 16,384 16-bit ring buffer entries = 32Kb DTCM

spynnaker.pyNN.utilities.constants.MIN_SUPPORTED_DELAY = 1

the minimum supported delay slot between two neurons

spynnaker.pyNN.utilities.constants.OUT_SPIKE_BYTES = 32

The number of bytes for each spike line

spynnaker.pyNN.utilities.constants.OUT_SPIKE_SIZE = 8

The size of each output spike line

spynnaker.pyNN.utilities.constants.POP_TABLE_MAX_ROW_LENGTH = 256

The maximum row length of the master population table

spynnaker.pyNN.utilities.constants.SPIKE_PARTITION_ID = 'SPIKE'

The partition ID used for spike data

spynnaker.pyNN.utilities.constants.SYNAPSE_SDRAM_PARTITION_ID = 'SDRAM Synaptic Inputs'

The name of the partition for Synaptic SDRAM

spynnaker.pyNN.utilities.constants.SYNAPTIC_ROW_HEADER_WORDS = 3

Words: 2 for row length and number of rows and 1 for plastic region size (which might be 0)

spynnaker.pyNN.utilities.constants.WRITE_BANDWIDTH_BYTES_PER_SECOND = 262144000

The conservative amount of write bandwidth available on a chip

spynnaker.pyNN.utilities.data_population module

class spynnaker.pyNN.utilities.data_population.DataPopulation(database_file: str, label: str, indexes: None | Sequence[int] | ndarray[tuple[Any, ...], dtype[integer]] = None)[source]

Bases: object

A wrapper of a sqlite3 database to provide the Population data methods

Parameters:
  • database_file – The name of a file that contains an SQLite database holding the data.

  • label – Label of the Population

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

describe(template: str | None = None, engine: str | TemplateEngine | None = None) str | Dict[str, Any][source]

Returns a human-readable description of the population.

The output may be customised 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 – Template filename

  • engine – Template substitution engine

Returns:

Human-readable description as a string or dict

find_units(variable: str) str | None[source]

Get the units of a variable.

Parameters:

variable – The name of the variable

Returns:

The units of the variable

get_data(variables: str | List[str] | Tuple[str, ...] = 'all', gather: bool = True, clear: bool = False, *, annotations: Dict[str, Any] | None = None) neo.Block[source]

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

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

  • gather

    Ignored. Purely for PyNN compatibility

    Note

    SpiNNaker always gathers.

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

  • annotations – annotations to put on the neo block

Returns:

Data in neo format

Raises:

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

get_spike_counts(gather: bool = True) Dict[int, int][source]

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

The dict keys are neuron IDs, not indices.

Parameters:

gather

Ignored. Purely for PyNN compatibility

Note

SpiNNaker always gathers.

Returns:

A dict containing the number of spikes for each neuron.

id_to_index(id: int) int[source]
id_to_index(id: Iterable[int]) List[int]

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

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

Parameters:

id

Returns:

Index of cell(s) in the Population

index_to_id(index: int) int[source]
index_to_id(index: Iterable[int]) List[int]

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

Parameters:

index

Returns:

The ID(s) of the cell(s) in the Population

property label: str

The label of the population.

property local_size: int

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

mean_spike_count(gather: bool = True) float[source]
Parameters:

gather

Ignored. Purely for PyNN compatibility

Note

SpiNNaker always gathers.

Returns:

The mean number of spikes per neuron.

property size: int

The number of neurons in the population.

spinnaker_get_data(variable: str, as_matrix: bool = False, view_indexes: Sequence[int] | None = None) ndarray[tuple[Any, ...], dtype[floating]][source]

SsPyNNaker specific method for getting data as a numpy array, instead of the Neo-based object

Parameters:
  • variable – a single variable name.

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

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

Returns:

array of the data

write_data(io: str | neo.baseio.BaseIO, variables: Names = 'all', gather: bool = True, clear: bool = False, annotations: Annotations = None) None[source]

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

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

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

  • gather

    Ignored. Purely for PyNN compatibility

    Note

    SpiNNaker always gathers.

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

  • annotations – annotations to put on the Neo block

spynnaker.pyNN.utilities.neo_buffer_database module

class spynnaker.pyNN.utilities.neo_buffer_database.NeoBufferDatabase(database_file: str | None = None, read_only: bool | None = None)[source]

Bases: BufferDatabase, NeoCsv

Extra support for Neo on top of the Database for SQLite 3.

This is the same database as used by BufferManager but with extra tables and access methods added.

Parameters:
  • database_file – The name of a file that contains (or will contain) an SQLite database holding the data. If omitted the default location will be used.

  • read_only – By default the database is read-only if given a database file. This allows to override that (mainly for clear)

add_segment(block: neo.Block, pop_label: str, variables: Names, view_indexes: ViewIndices, allow_missing: bool) None[source]

Adds a segment to the block.

Parameters:
  • block

  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

  • variables – One or more variable names or None for all available

  • view_indexes – List of neurons IDs to include or None for all

  • allow_missing – If True silently skips any variables not recorded

Raises:

ConfigurationException – If the recording metadata not setup correctly

static array_to_string(indexes: Collection[int]) str[source]

Converts a list of non-negative integers into a compact string. Works best if the list is sorted.

IDs are comma separated, except when a series of IDs is sequential then the start:end is used.

Parameters:

indexes – Collection (ideally sorted of int Values)

Returns:

string representation to be used in the database

clear_data(pop_label: str, variables: Names) None[source]

Clears the data for one population and given variables.

Parameters:
  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typical the Population label, corrected for None or duplicate values

  • variables – names of variable to get data for

csv_block_metadata(csv_file: str, pop_label: str, annotations: Annotations = None) bool[source]

Writes the data including metadata to a CSV file. Overwrites any previous data in the file.

Parameters:
  • csv_file – Path to file to write block metadata to

  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

  • annotations – annotations to put on the neo block

Returns:

True if metadata was available and therefore written

Raises:

ConfigurationException – If the recording metadata not setup correctly

csv_segment(csv_file: str, pop_label: str, variables: Names, view_indexes: ViewIndices, allow_missing: bool) None[source]

Writes the data including metadata to a CSV file.

Parameters:
  • csv_file – Path to file to write block metadata to

  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typical the Population label, corrected for None or duplicate values

  • variables – One or more variable names or None for all available

  • view_indexes – List of neurons IDs to include or None for all

  • allow_missing – Flag to say if data for missing variable should raise an exception

Raises:

ConfigurationException – If the recording metadata not setup correctly

find_units(pop_label: str, variable: str) str | None[source]

Gets the metadata ID for this population and recording label combination.

Parameters:
  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

  • variable

Returns:

data_type, sampling_interval_ms, units

Raises:

ConfigurationException – If the recording metadata not setup correctly

get_empty_block(pop_label: str, annotations: Annotations) neo.Block | None[source]
Parameters:
  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

  • annotations – annotations to put on the neo block

Returns:

The Neo block

Raises:

ConfigurationException – If the recording metadata not setup correctly

get_full_block(pop_label: str, variables: Names, view_indexes: ViewIndices, annotations: Annotations) neo.Block[source]

Creates a block with metadata and data for this segment. Any previous segments will be empty.

Parameters:
  • pop_label

    The label for the population of interest

    Note

    This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

  • variables – One or more variable names or None for all available

  • view_indexes – List of neurons IDs to include or None for all

  • annotations – annotations to put on the neo block

Returns:

The Neo block

get_population(pop_label: str) DataPopulation[source]

Gets an Object with the same data retrieval API as a Population.

Retrieval is limited to recorded data and a little metadata needed to create a single Neo Segment wrapped in a Neo Block.

Note

As each database only includes data for one run (with resets creating another database) the structure is relatively simple.

Parameters:

pop_label

The label for the population of interest

Note

This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

Returns:

An Object which acts like a Population for getting neo data

get_population_metadata(pop_label: str) Tuple[int, int, str][source]

Gets the metadata for the population with this label

Parameters:

pop_label

The label for the population of interest

Note

This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

Returns:

population size, first ID and description

Raises:

ConfigurationException – If the recording metadata not setup correctly

get_recording_populations() Tuple[str, ...][source]

Gets a list of the labels of Populations recording. Or to be exact the ones with metadata saved so likely to be recording.

Note

These are actually the labels of the Application Vertices. Typically the Population label, corrected for None or duplicate values

Returns:

List of population labels

get_recording_variables(pop_label: str) Tuple[str, ...][source]

List of the names of variables recording. Or, to be exact, list of the names of variables with metadata so likely to be recording.

Parameters:

pop_label

The label for the population of interest

Note

This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

Returns:

List of variable names

get_spike_counts(pop_label: str, view_indexes: None | Sequence[int] | ndarray[tuple[Any, ...], dtype[integer]] = None) Dict[int, int][source]

Gets the spike counts for the population with this label.

Parameters:
  • pop_label – label for the Population

  • view_indexes – If supplied indexes to retrieve.

Returns:

dict of index to count

has_population_metadata(pop_label: str) bool[source]

Check if there is Metadata for the population with this label

Parameters:

pop_label

The label for the population of interest

Note

This is actually the label of the Application Vertex. Typically the Population label, corrected for None or duplicate values

Returns:

True if there is Metadata with this label

classmethod segement_db(segment_number: int, read_only: bool | None = None) NeoBufferDatabase[source]
Returns:

A NeoBufferDatabase for this segment.

spinnaker_get_data(pop_label: str, variable: str, as_matrix: bool = False, view_indexes: None | Sequence[int] | ndarray[tuple[Any, ...], dtype[integer]] = None) ndarray[tuple[Any, ...], dtype[floating]][source]

SsPyNNaker specific method for getting data as a numpy array, instead of the Neo-based object

Parameters:
  • pop_label – label for the Population

  • variable – Single variable name.

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

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

Returns:

array of the data

Raises:

ConfigurationException – If variable is a list of a length other than 1

classmethod string_to_array(string: str) List[int][source]

Converts a string into a list of integers. Assumes the string was created by array_to_string()

Parameters:

string – in format used by array_to_string

Returns:

List of integers

write_metadata() None[source]

Write the current metadata to the database.

The underlying call does not guarantee order so there order the metadata is added is not consistent,

Note

The database must be writable for this to work!

write_segment_metadata() None[source]

Writes the global information from the Views.

This writes information held in SpynnakerDataView so that the database is usable stand-alone.

Note

The database must be writable for this to work!

write_t_stop() None[source]

Records the current run time as t_Stop.

This writes information held in SpynnakerDataView so that the database is usable stand-alone.

Note

The database must be writable for this to work!

spynnaker.pyNN.utilities.neo_compare module

spynnaker.pyNN.utilities.neo_compare.compare_analogsignal(as1: neo.AnalogSignal, as2: neo.AnalogSignal, *, same_length: bool = True) None[source]

Compares two analog signal objects to see if they are the same.

Parameters:
  • as1 – first analog signal holding list of individual analog signal objects

  • as2 – second analog signal holding list of individual analog signal objects

  • same_length – Flag to indicate if the same length of data is held, i.e., all spikes up to the same time. If False allows one trains to have additional data after the first ends. This is used to compare data extracted part way with data extracted at the end.

Raises:

AssertionError – If the analog signals are not equal

spynnaker.pyNN.utilities.neo_compare.compare_blocks(neo1: neo.Block, neo2: neo.Block, *, same_runs: bool = True, same_data: bool = True, same_length: bool = True) None[source]

Compares two neo Blocks to see if they hold the same data.

Parameters:
  • neo1 – First block to check

  • neo2 – Second block to check

  • same_runs – Flag to signal if blocks are the same length. If False extra segments in the larger block are ignored

  • same_data – Flag to indicate if the same type of data is held, i.e., same spikes, v, gsyn_exc and gsyn_inh. If False only data in both blocks is compared

  • same_length – Flag to indicate if the same length of data is held, i.e., all spikes up to the same time. If False allows one trains to have additional data after the first ends. This is used to compare data extracted part way with data extracted at the end.

Raises:

AssertionError – If the blocks are not equal

spynnaker.pyNN.utilities.neo_compare.compare_segments(seg1: neo.Segment, seg2: neo.Segment, *, same_data: bool = True, same_length: bool = True) None[source]

COmpare two segments objects to see if they are the same.

Parameters:
  • seg1 – First Segment to check

  • seg2 – Second Segment to check

  • same_data – Flag to indicate if the same type of data is held, i.e., same spikes, v, gsyn_exc and gsyn_inh. If False only data in both blocks is compared

  • same_length – Flag to indicate if the same length of data is held, i.e., all spikes up to the same time. If False allows one trains to have additional data after the first ends. This is used to compare data extracted part way with data extracted at the end.

Raises:

AssertionError – If the segments are not equal

spynnaker.pyNN.utilities.neo_compare.compare_spiketrain(spiketrain1: neo.SpikeTrain, spiketrain2: neo.SpikeTrain, *, same_length: bool = True) None[source]

Checks two spike trains have the exact same data.

Parameters:
  • spiketrain1 – first spike train

  • spiketrain2 – second spike train

  • same_length – Flag to indicate if the same length of data is held, i.e., all spikes up to the same time. If False allows one trains to have additional spikes after the first ends. This is used to compare data extracted part way with data extracted at the end.

Raises:

AssertionError – If the spike trains are not equal

spynnaker.pyNN.utilities.neo_compare.compare_spiketrains(spiketrains1: List[neo.SpikeTrain], spiketrains2: List[neo.SpikeTrain], *, same_data: bool = True, same_length: bool = True) None[source]

Check two Lists of spike trains have the exact same data.

Parameters:
  • spiketrains1 – First list of spike trains to compare

  • spiketrains2 – Second list of spike trains to compare

  • same_data – Flag to indicate if the same type of data is held, i.e., same spikes, v, gsyn_exc and gsyn_inh. If False allows one or both lists to be Empty. Even if False none empty lists must be the same length

  • same_length – Flag to indicate if the same length of data is held, i.e., all spikes up to the same time. If False allows one trains to have additional spikes after the first ends. This is used to compare data extracted part way with data extracted at the end.

Raises:

AssertionError – If the spike trains are not equal

spynnaker.pyNN.utilities.neo_convertor module

spynnaker.pyNN.utilities.neo_convertor.convert_analog_signal(signal_array: neo.AnalogSignal, time_unit: quantities.UnitTime = quantities.ms) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Converts part of a NEO object into told spynnaker7 format.

Parameters:
  • signal_array – Extended Quantities object

  • time_unit – Data time unit for time index

Returns:

Data in Spynnaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_data(data: neo.Block, name: str, run: int = 0) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Converts the data into a numpy array in the format ID, time, value.

Parameters:
  • data – Data as returned by a getData() call

  • name – Name of the data to be extracted. Same values as used in getData()

  • run – Zero based index of the run to extract data for

Returns:

Data for the named data type in Spynnaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_data_list(data: neo.Block, name: str, runs: Sequence[int] | None = None) List[ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]

Converts the data into a list of numpy arrays in the format ID, time, value.

Parameters:
  • data – Data as returned by a getData() call

  • name – Name of the data to be extracted. Same values as used in getData()

  • runs – List of Zero based index of the run to extract data for. Or None to extract all runs

Returns:

List of numpy arrays for the named data in Spynnaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_gsyn(gsyn_exc: neo.Block, gsyn_inh: neo.Block) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Converts two neo objects into the spynnaker7 format.

Note

It is acceptable for both neo parameters to be the same object

Parameters:
  • gsyn_exc – neo with gsyn_exc data

  • gsyn_inh – neo with gsyn_inh data

Returns:

Gsyn in sPyNNaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_gsyn_exc_list(data: neo.Block, runs: Sequence[int] | None = None) List[ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]

Converts the gsyn_exc into a list numpy array one per segment (all runs) in the format ID, time, value.

Parameters:
  • data – The data to convert; it must have Gsyn_exc data in it

  • runs – List of Zero based index of the run to extract data for. Or None to extract all runs

Returns:

Gsyn in sPyNNaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_gsyn_inh_list(data: neo.Block, runs: Sequence[int] | None = None) List[ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]

Converts the gsyn_inh into a list numpy array one per segment (all runs) in the format ID, time, value.

Parameters:
  • data – The data to convert; it must have Gsyn_inh data in it

  • runs – List of Zero based index of the run to extract data for. Or None to extract all runs

Returns:

Gsyn in sPyNNaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_spikes(neo: neo.Block, run: int = 0) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Extracts the spikes for run one from a Neo Object.

Parameters:
  • neo – neo Object including Spike Data

  • run – Zero based index of the run to extract data for

Returns:

Spikes in sPyNNaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_spiketrains(spiketrains: List[neo.SpikeTrain]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Converts a list of spiketrains into spynnaker7 format.

Parameters:

spiketrains – List of SpikeTrains

Returns:

Spikes in sPyNNaker (7) format

spynnaker.pyNN.utilities.neo_convertor.convert_v_list(data: neo.Block, runs: Sequence[int] | None = None) List[ndarray[tuple[Any, ...], dtype[_ScalarT]]][source]

Converts the voltage into a list numpy array one per segment (all runs) in the format ID, time, value.

Parameters:
  • data – The data to convert; it must have V data in it

  • runs – List of Zero based index of the run to extract data for. Or None to extract all runs

Returns:

Voltage in sPyNNaker (7) format

spynnaker.pyNN.utilities.neo_convertor.count_spikes(neo: neo.Block) int[source]

Help function to count the number of spikes in a list of spiketrains.

Only counts run 0

Parameters:

neo – Neo Object which has spikes in it

Returns:

The number of spikes in the first segment

spynnaker.pyNN.utilities.neo_convertor.count_spiketrains(spiketrains: neo.SpikeTrain) int[source]

Help function to count the number of spikes in a list of spiketrains.

Parameters:

spiketrains – List of SpikeTrains

Returns:

Total number of spikes in all the spiketrains

spynnaker.pyNN.utilities.neo_csv module

class spynnaker.pyNN.utilities.neo_csv.NeoCsv[source]

Bases: object

Code to read a csv file and create a neo object.

read_csv(csv_file: str) neo.Block[source]

Reads a whole CSV file and creates a block with data.

Parameters:

csv_file – Path of file to read

Returns:

a block with all the data in the CSV file.

spynnaker.pyNN.utilities.running_stats module

class spynnaker.pyNN.utilities.running_stats.RunningStats[source]

Bases: object

Keeps running statistics. From: https://www.johndcook.com/blog/skewness_kurtosis/

add_item(x: int | float) None[source]

Adds an item to the running statistics.

Parameters:

x – The item to add

add_items(mean: float, variance: float, n_items: int) None[source]

Add a bunch of items (via their statistics).

Parameters:
  • mean – The mean of the items to add.

  • variance – The variance of the items to add.

  • n_items – The number of items represented.

property mean: float

The mean of the items seen.

property n_items: int

The number of items seen.

property standard_deviation: float

The population standard deviation of the items seen.

property variance: float

The variance of the items seen.

spynnaker.pyNN.utilities.struct module

class spynnaker.pyNN.utilities.struct.Struct(fields: Sequence[Tuple[DataType, str]], repeat_type: StructRepeat = StructRepeat.PER_NEURON, default_values: Dict[str, int | float] | None = None)[source]

Bases: object

Represents a C code structure.

Parameters:
  • fields – The types and names of the fields, ordered as they appear in the structure.

  • repeat_type – How the structure repeats

  • default_values – Dict of field name -> value to use when values doesn’t contain the field

property fields: Sequence[Tuple[DataType, str]]

The types and names of the fields, ordered as they appear in the structure.

get_data(values: Mapping[str, int | float | AbstractList[float]], vertex_slice: Slice | None = None) ndarray[tuple[Any, ...], dtype[uint32]][source]
Parameters:
  • values – The values to fill in the data with

  • vertex_slice – The vertex slice to get the data for, or None if the structure is global.

Returns:

The numpy array of uint32 of data for the given values

get_generator_data(values: Mapping[str, int | float | AbstractList[float]], vertex_slice: Slice | None = None) ndarray[tuple[Any, ...], dtype[uint32]][source]
Parameters:
  • values – The values to fill in the data with

  • vertex_slice – The vertex slice or None for a structure with repeat_type global, or where a single value repeats for every neuron. If this is not the case and vertex_slice is None, an error will be raised!

Returns:

A numpy array of uint32 of data to generate the given values.

get_size_in_whole_words(array_size: int = 1) int[source]
Parameters:

array_size – The number of elements in an array of structures

Returns:

The size of the structure in whole words in an array of given size (default 1 item).

property is_generatable: bool

Whether the data inside could be generated on machine.

property numpy_dtype: dtype

The numpy data type of the structure.

read_data(data: bytearray | bytes, values: RangeDictionary, data_offset: int = 0, vertex_slice: Slice | None = None) None[source]

Read a byte string of data and write to values.

Parameters:
  • data – The data to be read

  • values – The values to update with the read data

  • data_offset – Index of the byte at the start of the valid data.

  • vertex_slice – Slice to read data for or None for all

property repeat_type: StructRepeat

How the structure repeats.

class spynnaker.pyNN.utilities.struct.StructRepeat(value)[source]

Bases: Enum

How a structure repeats, or not, in memory.

GLOBAL = 0

Indicates a single global struct

PER_NEURON = 1

Indicates a struct that repeats per neuron

spynnaker.pyNN.utilities.struct.ValueMap

The type of values used populate structure instances

alias of Mapping[str, int | float | AbstractList[float]]

spynnaker.pyNN.utilities.utility_calls module

Utility package containing simple helper functions.

spynnaker.pyNN.utilities.utility_calls.check_directory_exists_and_create_if_not(filename: str) None[source]

Create a parent directory for a file if it doesn’t exist.

Parameters:

filename – The file whose parent directory is to be created

spynnaker.pyNN.utilities.utility_calls.check_io(to_file: str | neo.baseio.BaseIO | None) None[source]

Checks an io parameter

Parameters:

to_file – io parameter to check

Raises:

ValueError – If neo can not generate an io Class

spynnaker.pyNN.utilities.utility_calls.check_rng(rng: AbstractRNG, where: str) None[source]

Check for non-None rng parameter since this is no longer compatible with sPyNNaker. If not None, warn or error depending on a config value.

Parameters:
  • rng – The rng parameter value.

  • where – Caller location for error message

spynnaker.pyNN.utilities.utility_calls.convert_param_to_numpy(param: RandomDistribution | float | List[float] | ndarray[tuple[Any, ...], dtype[_ScalarT]], no_atoms: int) ndarray[tuple[Any, ...], dtype[floating]][source]

Convert parameters into numpy arrays.

Parameters:
  • param – the param to convert

  • no_atoms – the number of atoms available for conversion of param

Returns:

the converted param as an array of floats

spynnaker.pyNN.utilities.utility_calls.convert_to(value: float, data_type: DataType) uint32[source]

Convert a value to a given data type.

Parameters:
  • value – The value to convert

  • data_type – The data type to convert to

Returns:

The converted data as a numpy data type

spynnaker.pyNN.utilities.utility_calls.create_mars_kiss_seeds(rng: RandomState) Tuple[int, ...][source]

Generates and checks that the seed values generated by the given random number generator or seed to a random number generator are suitable for use as a mars 64 kiss seed.

Parameters:

rng – the random number generator.

Returns:

a list of 4 integers which are used by the mars64 kiss random number generator for seeds.

spynnaker.pyNN.utilities.utility_calls.get_maximum_probable_value(distribution: RandomDistribution, n_items: int, chance: float = 0.01) float[source]
Parameters:
  • distribution

  • n_items

  • chance

Returns:

The likely maximum value of a RandomDistribution given a number of draws.

spynnaker.pyNN.utilities.utility_calls.get_mean(distribution: RandomDistribution) float[source]
Parameters:

distribution

Returns:

The mean of a RandomDistribution.

spynnaker.pyNN.utilities.utility_calls.get_minimum_probable_value(distribution: RandomDistribution, n_items: int, chance: float = 0.01) float[source]
Parameters:
  • distribution – Random type to check

  • n_items – Number of items to spread chance over

  • chance – Possibility of a value

Returns:

The likely minimum value of a RandomDistribution given a number of draws.

spynnaker.pyNN.utilities.utility_calls.get_n_bits(n_values: int) int[source]

Determine how many bits are required for the given number of values.

Parameters:

n_values – the number of values (starting at 0)

Returns:

the number of bits required to express that many values

spynnaker.pyNN.utilities.utility_calls.get_neo_io(file_or_folder: str) neo.io.baseio.BaseIO[source]

Hack for https://github.com/NeuralEnsemble/python-neo/issues/1287

In Neo 0.12 neo.get_io only works with existing files

Parameters:

file_or_folder

Returns:

Neo IO instance, guessing the type based on the filename suffix.

Raises:

ValueError – If neo can not generate an io Class

spynnaker.pyNN.utilities.utility_calls.get_probability_within_range(distribution: RandomDistribution, lower: float, upper: float) float[source]
Parameters:
  • distribution

  • lower

  • upper

Returns:

The probability that a value will fall within the given range for a given RandomDistribution.

spynnaker.pyNN.utilities.utility_calls.get_probable_maximum_selected(n_total_trials: int, n_trials: int, selection_prob: float, chance: float = 0.01) int[source]

Get the likely maximum number of items that will be selected from a set of n_trials from a total set of n_total_trials with a probability of selection of selection_prob.

Returns:

The likely maximum number of items

spynnaker.pyNN.utilities.utility_calls.get_probable_minimum_selected(n_total_trials: int, n_trials: int, selection_prob: float, chance: float = 0.01) int[source]

Get the likely minimum number of items that will be selected from a set of n_trials from a total set of n_total_trials with a probability of selection of selection_prob.

Returns:

The likely minimum number of items

spynnaker.pyNN.utilities.utility_calls.get_standard_deviation(distribution: RandomDistribution) float[source]
Parameters:

distribution

Returns:

The standard deviation of a RandomDistribution.

spynnaker.pyNN.utilities.utility_calls.get_time_to_write_us(n_bytes: int, n_cores: int) int[source]

Determine how long a write of a given number of bytes will take in us.

No known use so may be removed.

Parameters:
  • n_bytes – The number of bytes to transfer

  • n_cores – How many cores will be writing at the same time

Returns:

how long a write of a given number of bytes will take in us.

spynnaker.pyNN.utilities.utility_calls.get_variance(distribution: RandomDistribution) float[source]
Parameters:

distribution

Returns:

The variance of a RandomDistribution.

spynnaker.pyNN.utilities.utility_calls.high(distribution: RandomDistribution) float | None[source]

Gets the high or maximum boundary value for this distribution.

Could return None.

Parameters:

distribution

Returns:

The maximum boundary value

spynnaker.pyNN.utilities.utility_calls.low(distribution: RandomDistribution) float | None[source]

Gets the low or minimum boundary value for this distribution.

Could return None.

Parameters:

distribution

Returns:

The minimum boundary value

spynnaker.pyNN.utilities.utility_calls.read_in_data_from_file(file_path: str, min_atom: int, max_atom: int, min_time: float, max_time: float, extra: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

Read in a file of data values where the values are in a format of:

<time>  <atom ID>       <data value>
Parameters:
  • file_path – absolute path to a file containing the data

  • min_atom – min neuron ID to which neurons to read in

  • max_atom – max neuron ID to which neurons to read in

  • extra

  • min_time – min time slot to read neurons values of.

  • max_time – max time slot to read neurons values of.

Returns:

a numpy array of (time stamp, atom ID, data value)

spynnaker.pyNN.utilities.utility_calls.read_spikes_from_file(file_path: str, min_atom: float = 0, max_atom: float = inf, min_time: float = 0, max_time: float = inf, split_value: str = '\t') ndarray[tuple[Any, ...], dtype[integer]][source]

Read spikes from a file formatted as:

<time>  <neuron ID>
Parameters:
  • file_path – absolute path to a file containing spike values

  • min_atom – min neuron ID to which neurons to read in

  • max_atom – max neuron ID to which neurons to read in

  • min_time – min time slot to read neurons values of.

  • max_time – max time slot to read neurons values of.

  • split_value – the pattern to split by

Returns:

a numpy array with up to max_atom elements each of which is a list of spike times.

spynnaker.pyNN.utilities.utility_calls.report_non_spynnaker_pynn(msg: str) None[source]

Report a case of non-spynnaker-compatible PyNN being used. This will warn or error depending on the configuration setting.

Parameters:

msg – The message to report

Module contents