Utility classes and functions

init_logging(logfile, debug=False, num_processes=1, rank=0, level=None)[source]

Simple configuration of logging.


Import and return a PyNN simulator backend module based on command-line arguments.

The simulator name should be the first positional argument. If your script needs additional arguments, you can specify them as (name, help_text) tuples. If you need more complex argument handling, you should use argparse directly.

Returns (simulator, command-line arguments)

class Timer[source]

For timing script execution.

Timing starts on creation of the timer.


Start/restart timing.


Return the elapsed time in seconds but keep the clock running.

If called with format="long", return a text representation of the time. Examples:

>>> timer.elapsed_time()
>>> timer.elapsed_time(format='long')
16 minutes, 27 seconds

Deprecated. Use elapsed_time() instead.


Reset the time to zero, and start the clock.


Return the time since the last time elapsed_time() or diff() was called.

If called with format='long', return a text representation of the time.

static time_in_words(s)[source]

Formats a time in seconds as a string containing the time in days, hours, minutes, seconds. Examples:

>>> Timer.time_in_words(1)
1 second
>>> Timer.time_in_words(123)
2 minutes, 3 seconds
>>> Timer.time_in_words(24*3600)
1 day

Store the time since the last time since the last time elapsed_time(), diff() or mark() was called, together with the provided label, in the attribute ‘marks’.

class ProgressBar(width=77, char='#', mode='fixed')[source]

Create a progress bar in the shell.


Rebuild the bar string based on level, which should be a number between 0 and 1.

notify(msg='Simulation finished.', subject='Simulation finished.', smtphost=None, address=None)[source]

Send an e-mail stating that the simulation has finished.

save_population(population, filename, variables=None)[source]

Saves the spike_times of a population and the size, structure, labels such that one can load it back into a SpikeSourceArray population using the load_population() function.

load_population(filename, sim)[source]

Loads a population that was saved with the save_population() function into SpikeSourceArray.

Basic plotting