Esempio n. 1
0
import brian2
from brian2.core.preferences import brian_prefs

from .environment import running_from_ipython

__all__ = ["get_logger", "BrianLogger"]

# ===============================================================================
# Global options for logging
# ===============================================================================
brian_prefs.define(
    "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 occured. If set to ``False``, all log files will be kept.
    """,
)

# ===============================================================================
# Initial setup
# ===============================================================================

# get the root logger
logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)

# Log to a file
Esempio n. 2
0
'''
Memory management
'''
from numpy import zeros, dtype

from brian2.core.preferences import brian_prefs

__all__ = ['allocate_array',
           ]

brian_prefs.define('default_scalar_dtype', float,
    '''
    Default dtype for all arrays of scalars (state variables, weights, etc.).
    ''', validator=dtype)

def allocate_array(shape, dtype=None):
    '''
    Allocates a 1D array initialised to 0
    
    Parameters
    ----------
    shape : (int, tuple)
        The shape of the array.
    dtype : dtype, optional
        The numpy datatype of the array. If not specified, use the
        :bpref:`default_scalar_dtype` preference. 
        
    Returns
    -------
    arr : ndarray
        The allocated array (initialised to zero).