| 1 |
""" |
| 2 |
Definitions, documentation, default values and validation functions for core |
| 3 |
Brian preferences. |
| 4 |
""" |
| 5 |
|
| 6 |
from numpy import float32, float64, int32 |
| 7 |
|
| 8 |
from brian2.core.preferences import BrianPreference, prefs |
| 9 |
|
| 10 |
__all__ = [] |
| 11 |
|
| 12 |
|
| 13 |
def dtype_repr(dtype): |
| 14 |
return dtype.__name__ |
| 15 |
|
| 16 |
|
| 17 |
def default_float_dtype_validator(dtype): |
| 18 |
return dtype in [float32, float64] |
| 19 |
|
| 20 |
|
| 21 |
def outdated_dependency_error_validator(value): |
| 22 |
if value is not None: |
| 23 |
import warnings |
| 24 |
|
| 25 |
warnings.warn( |
| 26 |
"The 'core.outdated_dependency_error' preference is no longer " |
| 27 |
"used and will be removed in a future version. Brian2 now " |
| 28 |
"relies on package managers for dependency management.", |
| 29 |
UserWarning, |
| 30 |
stacklevel=2, |
| 31 |
) |
| 32 |
return True # We always accept the value user provides, but warn them |
| 33 |
|
| 34 |
|
| 35 |
prefs.register_preferences( |
| 36 |
"core", |
| 37 |
"Core Brian preferences", |
| 38 |
default_float_dtype=BrianPreference( |
| 39 |
default=float64, |
| 40 |
docs=""" |
| 41 |
Default dtype for all arrays of scalars (state variables, weights, etc.). |
| 42 |
""", |
| 43 |
representor=dtype_repr, |
| 44 |
validator=default_float_dtype_validator, |
| 45 |
), |
| 46 |
default_integer_dtype=BrianPreference( |
| 47 |
default=int32, |
| 48 |
docs=""" |
| 49 |
Default dtype for all arrays of integer scalars. |
| 50 |
""", |
| 51 |
representor=dtype_repr, |
| 52 |
), |
| 53 |
outdated_dependency_error=BrianPreference( |
| 54 |
default=None, |
| 55 |
docs=""" |
| 56 |
**DEPRECATED**: This preference is no longer used. Brian2 now relies on |
| 57 |
package managers (pip, conda) for dependency management instead of runtime |
| 58 |
version checking. Setting this preference has no effect and it will be |
| 59 |
removed in a future version. |
| 60 |
|
| 61 |
Previously controlled whether to raise an error for outdated dependencies |
| 62 |
(``True``) or just a warning (``False``). |
| 63 |
""", |
| 64 |
validator=outdated_dependency_error_validator, |
| 65 |
), |
| 66 |
stop_on_keyboard_interrupt=BrianPreference( |
| 67 |
default=True, |
| 68 |
docs=""" |
| 69 |
Whether to "gracefully" stop a simulation after pressing Ctrl+C (defaults to |
| 70 |
``True``). Note that pressing Ctrl+C a second time will force the usual |
| 71 |
interruption mechanism. |
| 72 |
""", |
| 73 |
), |
| 74 |
) |
| 75 |
|
| 76 |
prefs.register_preferences( |
| 77 |
"legacy", |
| 78 |
"Preferences to enable legacy behaviour", |
| 79 |
refractory_timing=BrianPreference( |
| 80 |
default=False, |
| 81 |
docs=""" |
| 82 |
Whether to use the semantics for checking the refractoriness condition |
| 83 |
that were in place up until (including) version 2.1.2. In that |
| 84 |
implementation, refractory periods that were multiples of dt could lead |
| 85 |
to a varying number of refractory timesteps due to the nature of |
| 86 |
floating point comparisons). This preference is only provided for exact |
| 87 |
reproducibility of previously obtained results, new simulations should |
| 88 |
use the improved mechanism which uses a more robust mechanism to |
| 89 |
convert refractoriness into timesteps. Defaults to ``False``. |
| 90 |
""", |
| 91 |
), |
| 92 |
) |