Ejemplo n.º 1
0
from brian2.core.preferences import brian_prefs, BrianPreference

# Preferences
brian_prefs.register_preferences(
    'codegen',
    'Code generation preferences',
    target=BrianPreference(
        default='numpy',
        docs='''
        Default target for code generation.
        
        Can be a string, in which case it should be one of:
        
        * `'numpy'` by default because this works on all platforms, but may not
          be maximally efficient.
        * `'weave`' uses ``scipy.weave`` to generate and compile C++ code,
          should work anywhere where ``gcc`` is installed and available at the
          command line.
        
        Or it can be a ``CodeObject`` class.
        ''',
    ),
)
Ejemplo n.º 2
0
brian_prefs.register_preferences(
    'logging',
    'Logging system preferences',
    delete_log_on_exit=BrianPreference(
        default=True,
        docs='''
        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.
        ''',
    ),
    file_log_level=BrianPreference(default='DEBUG',
                                   docs='''
        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.
        ''',
                                   validator=log_level_validator),
    console_log_level=BrianPreference(default='WARNING',
                                      docs='''
        What log level to use for the log written to the console.
        
        Has to be one of CRITICAL, ERROR, WARNING, INFO or DEBUG.
        ''',
                                      validator=log_level_validator),
    file_log=BrianPreference(default=True,
                             docs='''
        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.
        '''),
    save_script=BrianPreference(default=True,
                                docs='''
        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.
        '''))
Ejemplo n.º 3
0
__all__ = ['WeaveCodeObject', 'WeaveCodeGenerator']

# Preferences
brian_prefs.register_preferences(
    'codegen.runtime.weave',
    'Weave runtime codegen preferences',
    compiler = BrianPreference(
        default='gcc',
        validator=lambda pref: pref=='gcc',
        docs='''
        Compiler to use for weave.
        '''
        ),
    extra_compile_args = BrianPreference(
        default=['-w', '-O3', '-ffast-math'],
        docs='''
        Extra compile arguments to pass to compiler
        '''
        ),
    include_dirs = BrianPreference(
        default=[],
        docs='''
        Include directories to use.
        '''
        )
    )


def weave_data_type(dtype):
    '''
Ejemplo n.º 4
0
'''
Module declaring general code generation preferences.
'''

from .codeobject import CodeObject
from brian2.core.preferences import brian_prefs, BrianPreference

# Preferences
brian_prefs.register_preferences(
    'codegen',
    'Code generation preferences',
    target = BrianPreference(
        default='numpy',
        docs='''
        Default target for code generation.
        
        Can be a string, in which case it should be one of:
        
        * `'numpy'` by default because this works on all platforms, but may not
          be maximally efficient.
        * `'weave`' uses ``scipy.weave`` to generate and compile C++ code,
          should work anywhere where ``gcc`` is installed and available at the
          command line.
        
        Or it can be a ``CodeObject`` class.
        ''',
        validator=lambda target: isinstance(target, str) or issubclass(target, CodeObject),
        ),
    )
Ejemplo n.º 5
0
from ..targets import runtime_targets

from brian2.core.preferences import brian_prefs, BrianPreference

__all__ = ['WeaveCodeObject']

# Preferences
brian_prefs.register_preferences(
    'codegen.runtime.weave',
    'Weave runtime codegen preferences',
    compiler = BrianPreference(
        default='gcc',
        validator=lambda pref: pref=='gcc',
        docs='''
        Compiler to use for weave.
        ''',
        ),
    extra_compile_args = BrianPreference(
        default=['-w', '-O3', '-ffast-math'],
        docs='''
        Extra compile arguments to pass to compiler
        ''',
        ),
    )


def weave_data_type(dtype):
    '''
    Gives the C language specifier for numpy data types using weave. For example,
    ``numpy.int32`` maps to ``long`` in C.
    '''
Ejemplo n.º 6
0
brian_prefs.register_preferences('logging', 'Logging system preferences',
    delete_log_on_exit=BrianPreference(
        default=True,
        docs=    '''
        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.
        ''',
        ),
    file_log_level=BrianPreference(
        default='DEBUG',
        docs='''
        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.
        ''',
        validator=log_level_validator),
    console_log_level=BrianPreference(
        default='WARNING',
        docs='''
        What log level to use for the log written to the console.
        
        Has to be one of CRITICAL, ERROR, WARNING, INFO or DEBUG.
        ''',
        validator=log_level_validator),
    file_log=BrianPreference(
        default=True,
        docs= '''
        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.
        '''),
    save_script=BrianPreference(
        default=True,
        docs= '''
        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.
        ''')
    )
Ejemplo n.º 7
0
from ...codeobject import CodeObject

from ...templates import Templater
from ...generators.numpy_generator import NumpyCodeGenerator
from ...targets import codegen_targets

__all__ = ['NumpyCodeObject']

# Preferences
brian_prefs.register_preferences(
    'codegen.runtime.numpy',
    'Numpy runtime codegen preferences',
    discard_units = BrianPreference(
        default=False,
        docs='''
        Whether to change the namespace of user-specifed functions to remove
        units.
        '''
        )
    )


class NumpyCodeObject(CodeObject):
    '''
    Execute code using Numpy
    
    Default for Brian because it works on all platforms.
    '''
    templater = Templater('brian2.codegen.runtime.numpy_rt')
    generator_class = NumpyCodeGenerator
Ejemplo n.º 8
0
# Preferences
brian_prefs.register_preferences(
    'codegen.languages.cpp',
    'C++ codegen preferences',
    restrict_keyword = BrianPreference(
        default='__restrict__',
        docs='''
        The keyword used for the given compiler to declare pointers as restricted.
        
        This keyword is different on different compilers, the default is for gcc.
        ''',
        ),
    flush_denormals = BrianPreference(
        default=False,
        docs='''
        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);
            
        Found at `<http://stackoverflow.com/questions/2487653/avoiding-denormal-values-in-c>`_.
        ''',
        ),
    )

Ejemplo n.º 9
0
# Preferences
brian_prefs.register_preferences(
    'codegen.generators.cpp',
    'C++ codegen preferences',
    restrict_keyword = BrianPreference(
        default='__restrict__',
        docs='''
        The keyword used for the given compiler to declare pointers as restricted.
        
        This keyword is different on different compilers, the default is for gcc.
        ''',
        ),
    flush_denormals = BrianPreference(
        default=False,
        docs='''
        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);
            
        Found at `<http://stackoverflow.com/questions/2487653/avoiding-denormal-values-in-c>`_.
        ''',
        ),
    )

Ejemplo n.º 10
0
'''
Definitions, documentation, default values and validation functions for core
Brian preferences.
'''
from numpy import float64, int32

from brian2.core.preferences import BrianPreference, brian_prefs

def dtype_repr(dtype):
    return dtype.__name__

brian_prefs.register_preferences('core', 'Core Brian preferences',
    default_float_dtype=BrianPreference(
        default=float64,
        docs='''
        Default dtype for all arrays of scalars (state variables, weights, etc.).
        ''',
        representor=dtype_repr,
        ),
    default_integer_dtype=BrianPreference(
        default=int32,
        docs='''
        Default dtype for all arrays of integer scalars'
        ''',
        representor=dtype_repr,
        )
    )
Ejemplo n.º 11
0
           'make_weave_function']

# Preferences
brian_prefs.register_preferences(
    'codegen.runtime.weave',
    'Weave runtime codegen preferences',
    compiler = BrianPreference(
        default='gcc',
        validator=lambda pref: pref=='gcc',
        docs='''
        Compiler to use for weave.
        '''
        ),
    extra_compile_args = BrianPreference(
        default=['-w', '-O3'],
        docs='''
        Extra compile arguments to pass to compiler
        '''
        ),
    include_dirs = BrianPreference(
        default=[],
        docs='''
        Include directories to use. Note that ``$prefix/include`` will be
        appended to the end automatically, where ``$prefix`` is Python's
        site-specific directory prefix as returned by `sys.prefix`.
        '''
        )
    )


def make_weave_function(code, namespace=None, discard_units=None):
Ejemplo n.º 12
0
'''
Definitions, documentation, default values and validation functions for core
Brian preferences.
'''
from numpy import float64

from brian2.core.preferences import BrianPreference, brian_prefs

def dtype_repr(dtype):
    return dtype.__name__

brian_prefs.register_preferences('core', 'Core Brian preferences',
    default_scalar_dtype=BrianPreference(
        default=float64,
        docs='''
        Default dtype for all arrays of scalars (state variables, weights, etc.).'
        ''',
        representor=dtype_repr,
        )
    )
Ejemplo n.º 13
0
                                   AttributeVariable, AuxiliaryVariable,
                                   Subexpression)

from ...codeobject import CodeObject

from ...templates import Templater
from ...generators.numpy_generator import NumpyCodeGenerator
from ...targets import codegen_targets

__all__ = ['NumpyCodeObject']

# Preferences
brian_prefs.register_preferences('codegen.runtime.numpy',
                                 'Numpy runtime codegen preferences',
                                 discard_units=BrianPreference(default=False,
                                                               docs='''
        Whether to change the namespace of user-specifed functions to remove
        units.
        '''))


class NumpyCodeObject(CodeObject):
    '''
    Execute code using Numpy
    
    Default for Brian because it works on all platforms.
    '''
    templater = Templater('brian2.codegen.runtime.numpy_rt')
    generator_class = NumpyCodeGenerator
    class_name = 'numpy'