Skip to content

Commit fa91d65

Browse files
committed
feat(state): make brainpy.state in-tree code
Move the state-based models into brainpy/state/: neurons, synapses, synaptic outputs, STP, projections, readouts and inputs, plus the Dynamics/Neuron/Synapse bases and their tests. brainpy.state was a re-export of the external brainpy_state package; it now has an explicit __all__. The source is brainpy-state main @ 0f2e3ab. - Drop the brainpy_state dependency; raise brainevent to >=0.2.1. - Host the brainpy.state tutorials, how-to guides, concept chapters, gallery and API reference in docs/state/ and docs/apis/state.rst, and move the example scripts to examples/state/. - Point readthedocs links at https://brainpy.readthedocs.io/ (no /en/latest/). - Version 2.9.0.
1 parent 9f4529c commit fa91d65

99 files changed

Lines changed: 25045 additions & 56 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pytest --cov=brainpy tests/
215215
- Keep the API reference up to date
216216
- Fix typos and improve clarity
217217

218-
For comprehensive contribution guidelines, see our [detailed documentation](https://brainpy.readthedocs.io/en/latest/tutorial_advanced/contributing.html).
218+
For comprehensive contribution guidelines, see our [detailed documentation](https://brainpy.readthedocs.io/tutorial_advanced/contributing.html).
219219

220220
## Community
221221

‎README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<p align="center">
88
<a href="https://pypi.org/project/brainpy/"><img alt="Supported Python Version" src="https://img.shields.io/pypi/pyversions/brainpy"></a>
99
<a href="https://github.com/brainpy/BrainPy"><img alt="LICENSE" src="https://img.shields.io/badge/license-%20%20GNU%20GPLv3%20-green?style=plastic"></a>
10-
<a href="https://brainpy.readthedocs.io/en/latest/?badge=latest"><img alt="Documentation" src="https://readthedocs.org/projects/brainpy/badge/?version=latest"></a>
10+
<a href="https://brainpy.readthedocs.io/?badge=latest"><img alt="Documentation" src="https://readthedocs.org/projects/brainpy/badge/?version=latest"></a>
1111
<a href="https://badge.fury.io/py/brainpy"><img alt="PyPI version" src="https://badge.fury.io/py/brainpy.svg"></a>
1212
<a href="https://github.com/brainpy/BrainPy/actions/workflows/CI.yml"><img alt="Continuous Integration" src="https://github.com/brainpy/BrainPy/actions/workflows/CI.yml/badge.svg"></a>
1313
<a href="https://codecov.io/gh/brainpy/BrainPy"><img alt="Test Coverage" src="https://codecov.io/gh/brainpy/BrainPy/branch/main/graph/badge.svg"></a>
@@ -19,7 +19,7 @@ BrainPy is a flexible, efficient, and extensible framework for computational neu
1919
- **Source**: https://github.com/brainpy/BrainPy
2020
- **Bug reports**: https://github.com/brainpy/BrainPy/issues
2121
- **Documentation**: https://brainpy.readthedocs.io/
22-
- **Documentation (state-based)**: https://brainx.chaobrain.com/brainpy-state
22+
- **Documentation (state-based)**: https://brainpy.readthedocs.io/state/index.html
2323
- **Ecosystem**: https://brainx.chaobrain.com
2424
- **BrainPy and BrainX**: https://brainx.chaobrain.com/summ/brainpy-to-brainx.html
2525

@@ -64,7 +64,6 @@ We provide a Binder environment for BrainPy. You can use the following button to
6464

6565
- **[brain modeling ecosystem](https://brainmodeling.readthedocs.io/)**: A collection of tools and libraries for brain modeling and simulation.
6666
- **[brainpy-examples](https://github.com/brainpy/examples)**: Comprehensive examples of BrainPy computation.
67-
- **[brainpy-state](https://github.com/chaobrain/brainpy.state)**: Moderize BrainPy simulation with `brainstate` syntax.
6867
- **[BrainPy to BrainX](https://brainx.chaobrain.com/summ/brainpy-to-brainx.html)**: How `brainpy` relates to the BrainX packages, and [migration notes](https://brainx.chaobrain.com/summ/brainpy-migration-notes.html) for moving a project across.
6968
- [《神经计算建模实战》 (Neural Modeling in Action)](https://github.com/c-xy17/NeuralModeling)
7069
- [第一届神经计算建模与编程培训班 (First Training Course on Neural Modeling and Programming)](https://github.com/brainpy/1st-neural-modeling-and-programming-course)

‎brainpy/_version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616

17-
__version__ = "2.8.2"
17+
__version__ = "2.9.0"
1818
__version_info__ = tuple(map(int, __version__.split(".")))

‎brainpy/dynsys.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def reset(self, *args, **kwargs):
283283
284284
``reset()`` function is a collective behavior which resets all states in this model.
285285
286-
See https://brainpy.readthedocs.io/en/latest/tutorial_toolbox/state_resetting.html for details.
286+
See https://brainpy.readthedocs.io/tutorial_toolbox/state_resetting.html for details.
287287
"""
288288
global reset_state
289289
if reset_state is None:
@@ -297,7 +297,7 @@ def reset_state(self, *args, **kwargs):
297297
Simply speaking, this function should implement the logic of resetting of
298298
local variables in this node.
299299
300-
See https://brainpy.readthedocs.io/en/latest/tutorial_toolbox/state_resetting.html for details.
300+
See https://brainpy.readthedocs.io/tutorial_toolbox/state_resetting.html for details.
301301
"""
302302
pass
303303

@@ -511,7 +511,7 @@ def _compatible_reset_state(self, *args, **kwargs):
511511
self.reset(*args, **kwargs)
512512
warnings.warn(
513513
'''
514-
From version >= 2.4.6, the policy of ``.reset_state()`` has been changed. See https://brainpy.readthedocs.io/en/latest/tutorial_toolbox/state_saving_and_loading.html for details.
514+
From version >= 2.4.6, the policy of ``.reset_state()`` has been changed. See https://brainpy.readthedocs.io/tutorial_toolbox/state_saving_and_loading.html for details.
515515
516516
1. If you are resetting all states in a network by calling "net.reset_state(*args, **kwargs)", please use
517517
"bp.reset_state(net, *args, **kwargs)" function, or "net.reset(*args, **kwargs)".

‎brainpy/helpers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def wrap(fun: Callable):
5858
def reset_state(target: DynamicalSystem, *args, **kwargs):
5959
"""Reset states of all children nodes in the given target.
6060
61-
See https://brainpy.readthedocs.io/en/latest/tutorial_toolbox/state_resetting.html for details.
61+
See https://brainpy.readthedocs.io/tutorial_toolbox/state_resetting.html for details.
6262
6363
Parameters
6464
----------

‎brainpy/state/README.md‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
## Overview
44

5-
The `brainpy.state` module provides a state-based programming interface for brain dynamics modeling in BrainPy. This module is maintained as a separate package [`brainpy_state`](https://github.com/chaobrain/brainpy.state) and re-exported through BrainPy for seamless integration.
5+
The `brainpy.state` module provides a state-based programming interface for brain dynamics modeling in BrainPy, built on [`brainstate`](https://github.com/chaobrain/brainstate).
6+
7+
Its motivation is compatibility with the [BrainX ecosystem](https://brainx.chaobrain.com): `brainpy.state` models carry physical units through [`brainunit`](https://github.com/chaobrain/brainunit), compose with `brainstate` transformations, and can be trained online with [`braintrace`](https://github.com/chaobrain/braintrace).
68

79
State-based programming offers an alternative paradigm for defining and managing neural models, emphasizing explicit state management and transformations for building complex brain dynamics systems.
810

9-
`brainpy.state` is the recommended starting point for new `State`-based, differentiable models; the classic `DynamicalSystem`-based `brainpy` API (`brainpy.dyn`, `brainpy.math`, `brainpy.integrators`) is unchanged and fully supported. The two paradigms coexist — see the [relationship declaration](https://brainx.chaobrain.com/brainpy-state/project/relationship.html) for how they relate.
11+
`brainpy.state` is the recommended starting point for new `State`-based, differentiable models; the classic `DynamicalSystem`-based `brainpy` API (`brainpy.dyn`, `brainpy.math`, `brainpy.integrators`) is unchanged and fully supported.
1012

1113
## Features
1214

@@ -17,19 +19,11 @@ State-based programming offers an alternative paradigm for defining and managing
1719

1820
## Documentation
1921

20-
For comprehensive documentation on state-based programming in BrainPy, please visit:
21-
22-
- **State-based Documentation**: https://brainx.chaobrain.com/brainpy-state/
23-
- **Main BrainPy Documentation**: https://brainpy.readthedocs.io/
22+
- **State-based Documentation**: https://brainpy.readthedocs.io/state/index.html
23+
- **API Reference**: https://brainpy.readthedocs.io/apis/state.html
2424
- **BrainPy and BrainX**: https://brainx.chaobrain.com/summ/brainpy-to-brainx.html
2525
- **Migration notes**: https://brainx.chaobrain.com/summ/brainpy-migration-notes.html
2626

27-
## Source Repository
28-
29-
This module is maintained in a separate repository:
30-
31-
- **GitHub**: https://github.com/chaobrain/brainpy.state
32-
3327
## Installation
3428

3529
The `brainpy.state` module is included when you install BrainPy:
@@ -38,28 +32,17 @@ The `brainpy.state` module is included when you install BrainPy:
3832
pip install brainpy -U
3933
```
4034

41-
For development or to install the state module separately:
42-
43-
```bash
44-
pip install brainpy.state -U
45-
```
46-
4735
## Usage
4836

49-
Import the state module from BrainPy:
50-
5137
```python
52-
import brainpy as bp
53-
from brainpy import state
38+
import brainpy
5439

55-
# Use state-based components
56-
# (See documentation for detailed examples)
40+
neuron = brainpy.state.LIF(100)
5741
```
5842

5943
## Support
6044

6145
- **Bug Reports**: Please report issues at https://github.com/brainpy/BrainPy/issues
62-
- **State Module Issues**: For state-specific issues, see https://github.com/chaobrain/brainpy.state/issues
6346

6447
## License
6548

‎brainpy/state/__init__.py‎

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,81 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16-
from brainpy_state import *
17-
from brainpy_state import __all__
16+
r"""
17+
State-based brain dynamics models built on ``brainstate``.
1818
19-
if __name__ == '__main__':
20-
print(LIF) # type: ignore[name-defined] # provided by `from brainpy_state import *`
21-
print(__all__)
19+
This module provides composable neuron, synapse, projection, readout, and
20+
input models with explicit ``State`` objects, so they compose with
21+
``brainstate`` transformations (``jit``, ``grad``, ``vmap``, ``for_loop``).
22+
"""
23+
24+
from brainpy.state._base import Dynamics, Neuron, Synapse
25+
from brainpy.state.exponential import Expon, DualExpon
26+
from brainpy.state.hh import HH, MorrisLecar, WangBuzsakiHH
27+
from brainpy.state.inputs import SpikeTime, PoissonSpike, PoissonEncoder, PoissonInput, poisson_input
28+
from brainpy.state.inputs import (SectionInput, ConstantInput, StepInput, RampInput,
29+
SinusoidalInput, OUProcessInput, WienerProcessInput)
30+
from brainpy.state.izhikevich import Izhikevich, IzhikevichRef
31+
from brainpy.state.lif import (
32+
IF, LIF, LIFRef, ALIF,
33+
ExpIF, ExpIFRef,
34+
AdExIF, AdExIFRef,
35+
QuaIF, AdQuaIF, AdQuaIFRef,
36+
Gif, GifRef,
37+
CubaLIF, CobaLIF,
38+
)
39+
from brainpy.state.projection import (
40+
Projection, AlignPostProj, DeltaProj, CurrentProj,
41+
align_pre_projection, align_post_projection,
42+
)
43+
from brainpy.state.readout import LeakyRateReadout
44+
from brainpy.state.reduced import FitzHughNagumo, HindmarshRose
45+
from brainpy.state.stp import STP, STD
46+
from brainpy.state.synapse import Alpha, AMPA, GABAa, BioNMDA
47+
from brainpy.state.synaptic_projection import SymmetryGapJunction, AsymmetryGapJunction
48+
from brainpy.state.synouts import SynOut, COBA, CUBA, MgBlock
49+
50+
__all__ = [
51+
# Base models
52+
'Dynamics', 'Neuron', 'Synapse',
53+
54+
# Neuron models - LIF family
55+
'IF', 'LIF', 'LIFRef', 'ALIF',
56+
'ExpIF', 'ExpIFRef',
57+
'AdExIF', 'AdExIFRef',
58+
'QuaIF', 'AdQuaIF', 'AdQuaIFRef',
59+
'Gif', 'GifRef',
60+
'CubaLIF', 'CobaLIF',
61+
62+
# Neuron models - Hodgkin-Huxley family
63+
'HH', 'MorrisLecar', 'WangBuzsakiHH',
64+
65+
# Neuron models - Izhikevich family
66+
'Izhikevich', 'IzhikevichRef',
67+
68+
# Neuron models - reduced (FitzHugh-Nagumo, Hindmarsh-Rose)
69+
'FitzHughNagumo', 'HindmarshRose',
70+
71+
# Synapse models
72+
'Expon', 'DualExpon',
73+
'Alpha', 'AMPA', 'GABAa', 'BioNMDA',
74+
75+
# Synaptic outputs
76+
'SynOut', 'COBA', 'CUBA', 'MgBlock',
77+
78+
# Short-term plasticity
79+
'STP', 'STD',
80+
81+
# Projections
82+
'Projection', 'AlignPostProj', 'DeltaProj', 'CurrentProj',
83+
'align_pre_projection', 'align_post_projection',
84+
'SymmetryGapJunction', 'AsymmetryGapJunction',
85+
86+
# Readouts
87+
'LeakyRateReadout',
88+
89+
# Input generators
90+
'SpikeTime', 'PoissonSpike', 'PoissonEncoder', 'PoissonInput', 'poisson_input',
91+
'SectionInput', 'ConstantInput', 'StepInput', 'RampInput',
92+
'SinusoidalInput', 'OUProcessInput', 'WienerProcessInput',
93+
]

0 commit comments

Comments
 (0)