Brian has a system of global preferences that affect how certain objects
behave. These can be set either in scripts by using the
or in a file. Each preference looks like
codegen.c.compiler, i.e. dotted
Accessing and setting preferences¶
Preferences can be accessed and set either keyword-based or attribute-based. The following are equivalent:
prefs['codegen.c.compiler'] = 'gcc' prefs.codegen.c.compiler = 'gcc'
Using the attribute-based form can be particulary useful for interactive
work, e.g. in ipython, as it offers autocompletion and documentation.
prefs.codegen.c? would display a docstring with all
the preferences available in the
Preferences are stored in a hierarchy of files, with the following order (each step overrides the values in the previous step but no error is raised if one is missing):
- The global defaults are stored in the installation directory.
- The user default are stored in
~/.brian/user_preferences(which works on Windows as well as Linux). The
~symbol refers to the user directory.
- The file
brian_preferencesin the current directory.
The preference files are of the following form:
a.b.c = 1 # Comment line [a] b.d = 2 [a.b] b.e = 3
This would set preferences
List of preferences¶
Brian itself defines the following preferences (including their default values):
Directory containing GSL code
- Set path to directory containing GSL header files (gsl_odeiv2.h etc.) If this directory is already in Python’s include (e.g. because of conda installation), this path can be set to None.
Code generation preferences
Whether to pull out scalar expressions out of the statements, so that they are only evaluated once instead of once for every neuron/synapse/… Can be switched off, e.g. because it complicates the code (and the same optimisation is already performed by the compiler) or because the code generation target does not deal well with it. Defaults to
Default target for the evaluation of string expressions (e.g. when indexing state variables). Should normally not be changed from the default numpy target, because the overhead of compiling code is not worth the speed gain for simple expressions.
Accepts the same arguments as codegen.target, except for
Default target for code generation.
Can be a string, in which case it should be one of:
'auto'the default, automatically chose the best code generation target available.
scipy.weaveto generate and compile C++ code, should work anywhere where
gccis installed and available at the command line.
'cython', uses the Cython package to generate C++ code. Needs a working installation of Cython and a C++ compiler.
'numpy'works on all platforms and doesn’t need a C compiler but is often less efficient.
Or it can be a
C++ compilation preferences
Compiler to use (uses default if empty)
Should be gcc or msvc.
List of macros to define; each macro is defined using a 2-tuple, where ‘value’ is either the string to define it to or None to define it without a particular value (equivalent of “#define FOO” in source or -DFOO on Unix C compiler command line).
Extra arguments to pass to compiler (if None, use either
['-w', '-O3', '-ffast-math', '-fno-finite-math-only', '-march=native']
Extra compile arguments to pass to GCC compiler
['/Ox', '/w', '/arch:SSE2', '/MP']
Extra compile arguments to pass to MSVC compiler (the default
/arch:flag is determined based on the processor architecture)
Any extra platform- and compiler-specific information to use when linking object files together.
A list of strings specifying header files to use when compiling the code. The list might look like [“<vector>”,“‘my_header’”]. Note that the header strings need to be in a form than can be pasted at the end of a #include statement in the C++ code.
Include directories to use. Note that
$prefix/includewill be appended to the end automatically, where
$prefixis Python’s site-specific directory prefix as returned by
List of library names (not filenames or paths) to link against.
List of directories to search for C/C++ libraries at link time. Note that
$prefix/libwill be appended to the end automatically, where
$prefixis Python’s site-specific directory prefix as returned by
MSVC architecture name (or use system architectue by default).
Could take values such as x86, amd64, etc.
Location of the MSVC command line tool (or search for best by default).
List of directories to search for C/C++ libraries at run time.
Codegen generator preferences (see subcategories for individual languages)
C++ codegen preferences
Adds code to flush denormals to zero.
The code is gcc and architecture specific, so may not compile on all platforms. The code, for reference is:#define CSR_FLUSH_TO_ZERO (1 << 15) unsigned csr = __builtin_ia32_stmxcsr(); csr |= CSR_FLUSH_TO_ZERO; __builtin_ia32_ldmxcsr(csr);
The keyword used for the given compiler to declare pointers as restricted.
This keyword is different on different compilers, the default works for gcc and MSVS.
Runtime codegen preferences (see subcategories for individual targets)
Cython runtime codegen preferences
Location of the cache directory for Cython files. By default, will be stored in a
brian_extensionssubdirectory where Cython inline stores its temporary files (the result of
Whether to use a lock file to prevent simultaneous write access to cython .pyx and .so files.
Numpy runtime codegen preferences
Whether to change the namespace of user-specifed functions to remove units.
Core Brian preferences
Default dtype for all arrays of scalars (state variables, weights, etc.).
Currently, this is not supported (only float64 can be used).
Default dtype for all arrays of integer scalars.
Whether to raise an error for outdated dependencies (
True) or just a warning (
['start', 'groups', 'thresholds', 'synapses', 'resets', 'end']
Default schedule used for networks that don’t specify a schedule.
C++ standalone preferences
Additional flags to pass to the GNU make command on Linux/OS-X. Defaults to “-j” for parallel compilation.
Additional flags to pass to the nmake command on Windows. By default, no additional flags are passed.
Which strategy to chose for solving the three tridiagonal systems with OpenMP:
'branches'means to solve the three systems sequentially, but for all the branches in parallel,
'systems'means to solve the three systems in parallel, but all the branches within each system sequentially. The
'branches'approach is usually better for morphologies with many branches and a large number of threads, while the
'systems'strategy should be better for morphologies with few branches (e.g. cables) and/or simulations with no more than three threads. If not specified (the default), the
'systems'strategy will be used when using no more than three threads or when the morphology has less than three branches in total.
The number of threads to use if OpenMP is turned on. By default, this value is set to 0 and the C++ code is generated without any reference to OpenMP. If greater than 0, then the corresponding number of threads are used to launch the simulation.
Dictionary of environment variables and their values that will be set during the execution of the standalone code.
Logging system preferences
What log level to use for the log written to the console.
Has to be one of CRITICAL, ERROR, WARNING, INFO, DEBUG or DIAGNOSTIC.
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.
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.
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.
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.
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
Trueas well, then the output is saved to a file and if an error occurs the name of this file will be printed.
Whether to redirect stdout/stderr to a file.
logging.std_redirectionand this preference are set to
True, 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 is
Trueand this preference is
False, 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