utils package
Utility functions for Brian.
Exported members:
get_logger()
, BrianLogger
, std_silent
arrays
module
Helper module containing functions that operate on numpy arrays.
Functions
|
Calculates offsets corresponding to an array, where repeated values are subsequently numbered, i.e. if there n identical values, the returned array will have values from 0 to n-1 at their positions. |
caching
module
Module to support caching of function results to memory (used to cache results
of parsing, generation of state update code, etc.). Provides the cached
decorator.
Classes
|
Mixin class for objects that will be used as keys for caching (e.g. |
Functions
|
Decorator to cache a function so that it will not be re-evaluated when called with the same arguments. |
environment
module
Utility functions to get information about the environment Brian is running in.
Functions
Check whether we are currently running under ipython. |
filelock
module
A platform independent file lock that supports the with-statement.
Exported members:
Timeout
, BaseFileLock
, WindowsFileLock
, UnixFileLock
, SoftFileLock
, FileLock
Classes
|
Implements the base class of a file lock. |
Alias for the lock, which should be used for the current platform. |
|
Simply watches the existence of the lock file. |
|
Raised when the lock could not be acquired in timeout seconds. |
|
Uses the |
|
Uses the |
Functions
|
Returns the logger instance used in this module. |
filetools
module
File system tools
Exported members:
ensure_directory
, ensure_directory_of_file
, in_directory
, copy_directory
Classes
|
Safely temporarily work in a subdirectory |
Functions
|
Copies directory source to target. |
Ensures that a given directory exists (creates it if necessary) |
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
= 'INFO'
What log level to use for the log written to the console.
Has to be one of CRITICAL, ERROR, WARNING, INFO, DEBUG or DIAGNOSTIC.
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 occurred. If set toFalse
, all log files will be kept.
logging.display_brian_error_message
= True
Whether to display a text for uncaught errors, mentioning the location of the log file, the mailing list and the github issues.
Defaults to
True
.
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, DEBUG or DIAGNOSTIC.
logging.file_log_max_size
= 10000000
The maximum size for the debug log before it will be rotated.
If set to any value
> 0
, the debug log will be rotated once this size is reached. Rotating the log means that the old debug log will be moved into a file in the same directory but with suffix".1"
and the a new log file will be created with the same pathname as the original file. Only one backup is kept; if a file with suffix".1"
already exists when rotating, it will be overwritten. If set to0
, no log rotation will be applied. The default setting rotates the log file after 10MB.
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 isFalse
) but is kept after an uncaught exception occured. This can be helpful for debugging, in particular when several simulations are running in parallel.
logging.std_redirection
= True
Whether or not to redirect stdout/stderr to null at certain places.
This silences a lot of annoying compiler output, but will also hide error messages making it harder to debug problems. You can always temporarily switch it off when debugging. If logging.std_redirection_to_file is set to
True
as well, then the output is saved to a file and if an error occurs the name of this file will be printed.
logging.std_redirection_to_file
= True
Whether to redirect stdout/stderr to a file.
If both
logging.std_redirection
and this preference are set toTrue
, all standard output/error (most importantly output from the compiler) will be stored in files and if an error occurs the name of this file will be printed. If logging.std_redirection isTrue
and this preference isFalse
, then all standard output/error will be completely suppressed, i.e. neither be displayed nor stored in a file.The value of this preference is ignore if logging.std_redirection is set to
False
.
Exported members:
get_logger()
, BrianLogger
, std_silent
Classes
|
Convenience object for logging. |
|
A class for suppressing all log messages in a subtree of the name hierarchy. |
|
A class for capturing log warnings. |
|
A class for suppressing log messages ending with a certain name. |
|
A class for removing the |
|
A context manager for catching log messages. |
|
Context manager that temporarily silences stdout and stderr but keeps the output saved in a temporary file and writes it if an exception is raised. |
Functions
|
Display a message mentioning the debug log in case of an uncaught exception. |
Shutdown the logging system and delete the debug log file if no error occured. |
|
Get an object that can be used for logging. |
|
stringtools
module
A collection of tools for string formatting tasks.
Exported members:
indent
, deindent
, word_substitute
, replace
, get_identifiers
, strip_empty_lines
, stripped_deindented_lines
, strip_empty_leading_and_trailing_lines
, code_representation
, SpellChecker
Classes
|
A simple spell checker that will be used to suggest the correct name if the user made a typo (e.g. for state variable names). |
Functions
|
Returns a string representation for several different formats of code |
|
Returns a copy of the string with the common indentation removed. |
|
Return all the identifiers in a given string |
|
Indents a given multiline string. |
|
Applies a dictionary of substitutions. |
Removes all empty leading and trailing lines in the multi-line string |
Removes all empty lines from the multi-line string |
Returns a list of the lines in a multi-line string, deindented. |
|
Applies a dict of word substitutions. |
topsort
module
Exported members:
topsort
Functions
|
Topologically sort a graph |