# -*- coding: utf-8 -*-# SPDX-FileCopyrightText: 2015-2023 Tanguy Fardet# SPDX-License-Identifier: GPL-3.0-or-later# nngt/simulation/__init__.py"""Module to interact easily with the NEST simulator. It allows to:* build a NEST network from :class:`~nngt.Network` or :class:`~nngt.SpatialNetwork` objects,* monitor the activity of the network (taking neural groups into account)* plot the activity while separating the behaviours of predefined neural groups"""importloggingas_loggingimportsysas_sysimporttypesas_typesimportnngtas_nngtfromnngt.lib.loggerimport_log_message_logger=_logging.getLogger(__name__)# --------- ## Wrap nest ## --------- #importnestwarnlist=["Connect","Disconnect","Create","SetStatus","ResetNetwork","set",]def_wrap_reset_kernel(func):''' Reset all NeuralPops and parent Networks before calling nest.ResetKernel. '''defwrapper(*args,**kwargs):_nngt.NeuralPop._nest_reset()returnfunc(*args,**kwargs)returnwrapperdef_wrap_warn(func):''' Warn when risky nest functions are called. '''defwrapper(*args,_warn=True,**kwargs):if_warn:_log_message(_logger,"WARNING","This function could interfere ""with NNGT, making your Network obsolete compared to ""the one in NEST... make sure to check what is ""modified! Pass the `_warn=False` keyword to the ""function if you know what you are doing and want to ""hide this message.")returnfunc(*args,**kwargs)returnwrapper
[docs]classNestMod(_types.ModuleType):''' Wrapped module to replace nest. '''def__getattribute__(self,attr):ifattrinwarnlist:return_wrap_warn(getattr(nest,attr))elifattr=="ResetKernel":return_wrap_reset_kernel(nest.ResetKernel)returngetattr(nest,attr)