"""Quality of life patch for the NEURON simulator."""try:fromfunctoolsimportcache,cached_propertyexceptImportError:# pragma: nocoverimportfunctoolsdefcached_property(f):returnproperty(functools.lru_cache()(f))functools.cache=cache=functools.lru_cache()functools.cached_property=cached_propertyfrom.coreimport(is_density_mechanism,is_nrn_scalar,is_point_process,is_section,is_segment,transform,transform_arc,transform_netcon,transform_record,)from.exceptionsimportNotConnectableError,NotConnectedErrorfrom.interpreterimportPythonHocInterpreterp:"PythonHocInterpreter"h:"PythonHocInterpreter"def__getattr__(attr):ifattr=="p"orattr=="h":return_get_interpreter()else:raiseAttributeError(f"module {__name__} has no attribute {attr}.")@cachedef_get_interpreter():p=PythonHocInterpreter()PythonHocInterpreter._process_registration_queue()returnp
[docs]defconnection(source,target,strict=True):ifnothasattr(source,"_connections"):raiseNotConnectableError(f"Source {source} is not connectable. It lacks attribute _connections ""required to form NetCons.")ifnothasattr(target,"_connections"):raiseNotConnectableError(f"Target {target} is not connectable. It lacks attribute _connections ""required to form NetCons.")reverse=sourceintarget._connectionsiftargetnotinsource._connections:ifreverseandnotstrict:returntarget._connections[source]raiseNotConnectedError("Source is not connected to target.")returnsource._connections[target]