utils package

Utility functions for Brian.

debugging module

Some tools for debugging.

Exported members: RedirectStdStreams, std_silent

Classes

RedirectStdStreams([stdout, stderr]) Context manager which allows you to temporarily redirect stdin/stdout and restore them on exit.
std_silent([alwaysprint]) Context manager which temporarily silences stdin/stdout unless there is an exception.

environment module

Utility functions to get information about the environment Brian is running in.

Functions

running_from_ipython() Check whether we are currently running under ipython.

filetools module

File system tools

Exported members: ensure_directory, ensure_directory_of_file, in_directory, copy_directory

Classes

in_directory(new_dir) Safely temporarily work in a subdirectory

Functions

copy_directory(source, target) Copies directory source to target.
ensure_directory(d) Ensures that a given directory exists (creates it if necessary)
ensure_directory_of_file(f) Ensures that a directory exists for filename to go in (creates if necessary), and returns the directory path.

logger module

Brian’s logging module.

Preferences

Logging system preferences

logging.console_log_level = 'WARNING'

What log level to use for the log written to the console.

Has to be one of CRITICAL, ERROR, WARNING, INFO or DEBUG.

logging.delete_log_on_exit = True

Whether to delete the log and script file on exit.

If set to True (the default), log files (and the copy of the main script) will be deleted after the brian process has exited, unless an uncaught exception occured. If set to False, all log files will be kept.

logging.file_log = True

Whether to log to a file or not.

If set to True (the default), logging information will be written to a file. The log level can be set via the logging.file_log_level preference.

logging.file_log_level = 'DEBUG'

What log level to use for the log written to the log file.

In case file logging is activated (see logging.file_log), which log level should be used for logging. Has to be one of CRITICAL, ERROR, WARNING, INFO or DEBUG.

logging.save_script = True

Whether to save a copy of the script that is run.

If set to True (the default), a copy of the currently run script is saved to a temporary location. It is deleted after a successful run (unless logging.delete_log_on_exit is False) but is kept after an uncaught exception occured. This can be helpful for debugging, in particular when several simulations are running in parallel.

Exported members: get_logger(), BrianLogger

Classes

BrianLogger(name) Convenience object for logging.
HierarchyFilter(name) A class for suppressing all log messages in a subtree of the name hierarchy.
LogCapture(log_list[, log_level]) A class for capturing log warnings.
NameFilter(name) A class for suppressing log messages ending with a certain name.
catch_logs([log_level]) A context manager for catching log messages.

Functions

brian_excepthook(exc_type, exc_obj, exc_tb) Display a message mentioning the debug log in case of an uncaught exception.
clean_up_logging() Shutdown the logging system and delete the debug log file if no error occured.
get_logger([module_name]) Get an object that can be used for logging.
log_level_validator(log_level)

ordereddict module

Classes

OrderedDict(*args, **kwds) Dictionary that remembers insertion order

stringtools module

A collection of tools for string formatting tasks.

Exported members: indent, deindent, word_substitute, get_identifiers, strip_empty_lines, stripped_deindented_lines, strip_empty_leading_and_trailing_lines, code_representation

Functions

code_representation(code) Returns a string representation for several different formats of code
deindent(text[, numtabs, spacespertab, ...]) Returns a copy of the string with the common indentation removed.
get_identifiers(expr) Return all the identifiers in a given string expr, that is everything that matches a programming language variable like expression, which is here implemented as the regexp \b[A-Za-z_][A-Za-z0-9_]*\b.
indent(text[, numtabs, spacespertab, tab]) Indents a given multiline string.
strip_empty_leading_and_trailing_lines(s) Removes all empty leading and trailing lines in the multi-line string s.
strip_empty_lines(s) Removes all empty lines from the multi-line string s.
stripped_deindented_lines(code) Returns a list of the lines in a multi-line string, deindented.
word_substitute(expr, substitutions) Applies a dict of word substitutions.

timedarray module

Exported members: TimedArray

Classes

TimedArray(values, dt[, name]) A function of time built from an array of values.

topsort module

Exported members: topsort

Functions

topsort(graph) Topologically sort a graph