BrianGlobalPreferences class¶
(Shortest import: from brian2.core.preferences import BrianGlobalPreferences)
-
class
brian2.core.preferences.BrianGlobalPreferences[source]¶ Bases:
collections.abc.MutableMappingClass of the
prefsobject.Used for getting/setting/validating/registering preference values. All preferences must be registered via
register_preferences. To get or set a preference, you can either use a dictionary-based or an attribute-based interface:prefs['core.default_float_dtype'] = float32 prefs.core.default_float_dtype = float32
Preferences can be read from files, see
load_preferencesandread_preference_file. Note thatload_preferencesis called automatically when Brian has finished importing.Attributes
as_fileGet a Brian preference doc file format string for the current preferences defaults_as_fileGet a Brian preference doc file format string for the default preferences toplevel_categoriesThe toplevel preference categories Methods
check_all_validated()Checks that all preferences that have been set have been validated. do_validation()Validates preferences that have not yet been validated. eval_pref(value)Evaluate a string preference in the units namespace get_documentation([basename, link_targets])Generates a string documenting all preferences with the given basename.load_preferences()Load all the preference files, but do not validate them. read_preference_file(file)Reads a Brian preferences file register_preferences(prefbasename, …)Registers a set of preference names, docs and validation functions. reset_to_defaults()Resets the parameters to their default values. Details
-
as_file¶ Get a Brian preference doc file format string for the current preferences
-
defaults_as_file¶ Get a Brian preference doc file format string for the default preferences
-
toplevel_categories¶ The toplevel preference categories
-
check_all_validated()[source]¶ Checks that all preferences that have been set have been validated.
Logs a warning if not. Should be called by
Network.runor other key Brian functions.
-
get_documentation(basename=None, link_targets=True)[source]¶ Generates a string documenting all preferences with the given
basename. If nobasenameis given, all preferences are documented.
-
load_preferences()[source]¶ Load all the preference files, but do not validate them.
Preference files are read in the following order:
~/.brian/user_preferencesfrom the user’s home directory./brian_preferencesfrom the current directory
Files that are missing are ignored. Preferences read at each step override preferences from previous steps.
-
read_preference_file(file)[source]¶ Reads a Brian preferences file
The file format for Brian preferences is a plain text file of the form:
a.b.c = 1 # Comment line [a] b.d = 2 [a.b] e = 3
Blank and comment lines are ignored, all others should be of one of the following two forms:
key = value [section]
evalis called on the values, so strings should be written as, e.g.'3'rather than3. The eval is called with all unit names available. Within a section, the section name is prepended to the key. So in the above example, it would give the following unvalidated dictionary:{'a.b.c': 1, 'a.b.d': 2, 'a.b.e': 3, }
-