Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions brainpy/dyn/neurons/lif.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,10 @@ class ExpIF(ExpIFLTC):
conductance-based synaptic drive." Physical Review E 76, no. 2 (2007): 021919.
.. [5] https://en.wikipedia.org/wiki/Exponential_integrate-and-fire

.. seealso::

:class:`brainpy.state.ExpIF` provides the state-based formulation of this neuron.

**Examples**

There is a simple usage example::
Expand Down Expand Up @@ -978,6 +982,10 @@ class ExpIFRefLTC(ExpIFLTC):
conductance-based synaptic drive." Physical Review E 76, no. 2 (2007): 021919.
.. [5] https://en.wikipedia.org/wiki/Exponential_integrate-and-fire

.. seealso::

:class:`brainpy.state.ExpIFRef` provides the state-based formulation of this neuron.

**Examples**

There is a simple usage example::
Expand Down Expand Up @@ -1319,6 +1327,10 @@ class AdExIFLTC(GradNeuDyn):
inputs." Journal of Neuroscience 23.37 (2003): 11628-11640.
.. [2] http://www.scholarpedia.org/article/Adaptive_exponential_integrate-and-fire_model

.. seealso::

:class:`brainpy.state.AdExIF` provides the state-based formulation of this model.

**Examples**

An example usage:
Expand Down
13 changes: 6 additions & 7 deletions brainpy/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
from ._base import __all__ as base_all
from ._exponential import *
from ._exponential import __all__ as exp_all
from ._hh import *
from ._hh import __all__ as hh_all
from ._inputs import *
from ._inputs import __all__ as inputs_all
from ._izhikevich import *
from ._izhikevich import __all__ as izh_all
from ._lif import *
from ._lif import __all__ as neuron_all
from ._projection import *
Expand All @@ -34,13 +38,8 @@
from ._synaptic_projection import __all__ as synproj_all
from ._synouts import *
from ._synouts import __all__ as synout_all
from .. import mixin

__main__ = ['version2', 'mixin'] + inputs_all + neuron_all + readout_all + stp_all + synapse_all
__main__ = inputs_all + neuron_all + izh_all + hh_all + readout_all + stp_all + synapse_all
__main__ = __main__ + synout_all + base_all + exp_all + proj_all + synproj_all
del inputs_all, neuron_all, readout_all, stp_all, synapse_all, synout_all, base_all
del inputs_all, neuron_all, izh_all, hh_all, readout_all, stp_all, synapse_all, synout_all, base_all
del exp_all, proj_all, synproj_all

if __name__ == '__main__':
mixin

20 changes: 11 additions & 9 deletions brainpy/state/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def _input_label_repr(name: str, label: Optional[str] = None):


class Dynamics(brainstate.nn.Dynamics):
__module__ = 'brainpy.state'

def __init__(self, in_size: Size, name: Optional[str] = None):
# initialize
super().__init__(name=name, in_size=in_size)
Expand Down Expand Up @@ -401,21 +403,21 @@ def align_pre(self, dyn: Union[ParamDescriber[T], T]) -> T:
Examples
--------
>>> import brainstate
>>> n1 = brainstate.nn.LIF(10)
>>> n1.align_pre(brainstate.nn.Expon.desc(n1.varshape)) # n2 will run after n1
>>> n1 = brainpy.state.LIF(10)
>>> n1.align_pre(brainpy.state.Expon.desc(n1.varshape)) # n2 will run after n1
"""
if isinstance(dyn, Dynamics):
self._add_after_update(id(dyn), dyn)
self.add_after_update(id(dyn), dyn)
return dyn
elif isinstance(dyn, ParamDescriber):
if not issubclass(dyn.cls, Dynamics):
raise TypeError(f'The input {dyn} should be an instance of {Dynamics}.')
if not self._has_after_update(dyn.identifier):
self._add_after_update(
if not self.has_after_update(dyn.identifier):
self.add_after_update(
dyn.identifier,
dyn() if ('in_size' in dyn.kwargs or len(dyn.args) > 0) else dyn(in_size=self.varshape)
)
return self._get_after_update(dyn.identifier)
return self.get_after_update(dyn.identifier)
else:
raise TypeError(f'The input {dyn} should be an instance of {Dynamics} or a delayed initializer.')

Expand All @@ -425,7 +427,7 @@ class Neuron(Dynamics):
Base class for all spiking neuron models.

This abstract class serves as the foundation for implementing various spiking neuron
models in the BrainPy framework. It extends the ``brainstate.nn.Dynamics`` class and
models in the BrainPy framework. It extends the ``brainpy.state.Dynamics`` class and
provides common functionality for spike generation, membrane potential dynamics, and
surrogate gradient handling required for training spiking neural networks.

Expand Down Expand Up @@ -595,7 +597,7 @@ class Neuron(Dynamics):
.. [3] Gerstner, W., Kistler, W. M., Naud, R., & Paninski, L. (2014). Neuronal dynamics:
From single neurons to networks and models of cognition. Cambridge University Press.
"""
__module__ = 'brainpy'
__module__ = 'brainpy.state'

def __init__(
self,
Expand Down Expand Up @@ -849,4 +851,4 @@ class Synapse(Dynamics):
.. [3] Gerstner, W., Kistler, W. M., Naud, R., & Paninski, L. (2014). Neuronal dynamics:
From single neurons to networks and models of cognition. Cambridge University Press.
"""
__module__ = 'brainpy'
__module__ = 'brainpy.state'
4 changes: 2 additions & 2 deletions brainpy/state/_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_neuron_soft_vs_hard_reset(self):
def test_neuron_module_attribute(self):
"""Test __module__ attribute is correctly set."""
neuron = Neuron(in_size=self.in_size)
self.assertEqual(neuron.__module__, 'brainpy')
self.assertEqual(neuron.__module__, 'brainpy.state')


class TestSynapseBaseClass(unittest.TestCase):
Expand Down Expand Up @@ -247,7 +247,7 @@ def update(self, x=None):
def test_synapse_module_attribute(self):
"""Test __module__ attribute is correctly set."""
synapse = Synapse(in_size=self.in_size)
self.assertEqual(synapse.__module__, 'brainpy')
self.assertEqual(synapse.__module__, 'brainpy.state')

def test_synapse_varshape_attribute(self):
"""Test varshape attribute is correctly set."""
Expand Down
4 changes: 2 additions & 2 deletions brainpy/state/_exponential.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Expon(Synapse, AlignPost):
where synaptic variables are aligned with post-synaptic neurons, enabling event-driven
computation and more efficient handling of sparse connectivity patterns.
"""
__module__ = 'brainpy'
__module__ = 'brainpy.state'

def __init__(
self,
Expand Down Expand Up @@ -156,7 +156,7 @@ class DualExpon(Synapse, AlignPost):
where synaptic variables are aligned with post-synaptic neurons, enabling event-driven
computation and more efficient handling of sparse connectivity patterns.
"""
__module__ = 'brainpy'
__module__ = 'brainpy.state'

def __init__(
self,
Expand Down
Loading
Loading