Skip to content

Commit 414b635

Browse files
chaoming0625oujago
andauthored
Update documentation and examples (#785)
* fix(docs): clean up conf.py formatting and add static image copying * fix(docs): update static file handling and logo paths in documentation configuration * refactor(docs): remove deprecated error classes and update documentation installation instructions * add copyright to each python file * refactor(docs): reorganize delay handling and update related classes in documentation * refactor(docs): reorganize example scripts and add new neuron models * refactor(docs): update documentation configuration and improve module imports * refactor(docs): update import statements for mixin module * refactor(docs): update import statement for Mode class to use brainpy.mixin * refactor(docs): update Sphinx configuration and add custom theme styles * refactor(docs): update import statements for brainpy and add changelog file * refactor(docs): clean up import statements and improve code formatting * change ecosystem name * refactor(docs): update import statements to use brainpy.mixin and add .gitignore entry for build artifacts * refactor(docs): update documentation files and improve Sphinx configuration * refactor(docs): update neuron imports to use brainpy.version2.dynold and improve module structure * refactor(mixin): initialize bm with brainpy.version2.math if None * refactor(mixin): add DynamicalSystem variable initialization --------- Co-authored-by: oujago <oujago@gmail.com>
1 parent 292243a commit 414b635

453 files changed

Lines changed: 12919 additions & 1519 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.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,7 @@ cython_debug/
229229
/bugs/
230230
/dev/
231231
/.claude/
232+
/docs_version2/_static/logos/
233+
/docs/_static/logos/
234+
/docs/_build/
235+
/docs/changelog.md

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build:
1313
post_checkout:
1414
# Copy the appropriate conf.py based on project name
1515
- |
16-
if [ "$READTHEDOCS_PROJECT" = "brainpy-version2" ]; then
16+
if [ "$PROJECT_VERSION" = "brainpy-version2" ]; then
1717
mkdir -p docs_build
1818
cp -r docs_version2/* docs_build/
1919
else

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ We provide a Binder environment for BrainPy. You can use the following button to
7474

7575
## Citing
7676

77-
If you are using ``brainpy``, please consider citing the corresponding paper:
77+
If you are using ``brainpy >= 2.0``, please consider citing the corresponding paper:
7878

7979
```bibtex
8080
@article {10.7554/eLife.86365,

brainpy/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
__version__ = "3.0.0"
1717
__version_info__ = (3, 0, 0)
1818

19+
from . import mixin
1920
from . import version2
2021
from ._base import *
2122
from ._base import __all__ as base_all
@@ -40,7 +41,7 @@
4041
from ._synouts import *
4142
from ._synouts import __all__ as synout_all
4243

43-
__main__ = ['version2'] + errors_all + inputs_all + neuron_all + readout_all + stp_all + synapse_all
44+
__main__ = ['version2', 'mixin'] + errors_all + inputs_all + neuron_all + readout_all + stp_all + synapse_all
4445
__main__ = __main__ + synout_all + base_all + exp_all + proj_all + synproj_all
4546
del errors_all, inputs_all, neuron_all, readout_all, stp_all, synapse_all, synout_all, base_all
4647
del exp_all, proj_all, synproj_all
@@ -81,7 +82,7 @@ def __dir__():
8182
_deprecated_modules = [
8283
'math', 'check', 'tools', 'connect', 'initialize', 'init', 'conn',
8384
'optim', 'losses', 'measure', 'inputs', 'encoding', 'checkpoints',
84-
'mixin', 'algorithms', 'integrators', 'ode', 'sde', 'fde',
85+
'algorithms', 'integrators', 'ode', 'sde', 'fde',
8586
'dnn', 'layers', 'dyn', 'running', 'train', 'analysis',
8687
'channels', 'neurons', 'rates', 'synapses', 'synouts', 'synplast',
8788
'visualization', 'visualize', 'types', 'modes', 'context',
@@ -96,4 +97,3 @@ def __dir__():
9697
del _sys, _mod_name, _deprecated_modules
9798

9899
version2.__version__ = __version__
99-

brainpy/_base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import Callable, Optional
1717

1818
import braintools
19+
1920
import brainstate
2021

2122
__all__ = [
@@ -43,12 +44,12 @@ class Neuron(brainstate.nn.Dynamics):
4344
for multi-dimensional input (e.g., ``100`` or ``(28, 28)``).
4445
spk_fun : Callable, optional
4546
Surrogate gradient function for the non-differentiable spike generation operation.
46-
Default is ``brainstate.surrogate.InvSquareGrad()``. Common alternatives include:
47+
Default is ``braintools.surrogate.InvSquareGrad()``. Common alternatives include:
4748
48-
- ``brainstate.surrogate.ReluGrad()``
49-
- ``brainstate.surrogate.SigmoidGrad()``
50-
- ``brainstate.surrogate.GaussianGrad()``
51-
- ``brainstate.surrogate.ATan()``
49+
- ``braintools.surrogate.ReluGrad()``
50+
- ``braintools.surrogate.SigmoidGrad()``
51+
- ``braintools.surrogate.GaussianGrad()``
52+
- ``braintools.surrogate.ATan()``
5253
spk_reset : str, optional
5354
Reset mechanism applied after spike generation. Default is ``'soft'``.
5455
@@ -149,7 +150,7 @@ class Neuron(brainstate.nn.Dynamics):
149150
... in_size=100,
150151
... tau=10*u.ms,
151152
... V_th=1.0*u.mV,
152-
... spk_fun=brainstate.surrogate.ReluGrad(),
153+
... spk_fun=braintools.surrogate.ReluGrad(),
153154
... spk_reset='soft'
154155
... )
155156
>>>
@@ -304,7 +305,7 @@ class Synapse(brainstate.nn.Dynamics):
304305
305306
**Alignment Patterns**
306307
307-
Some synapse models inherit from ``brainstate.mixin.AlignPost`` to enable
308+
Some synapse models inherit from :class:`AlignPost` to enable
308309
event-driven computation where synaptic variables are aligned with postsynaptic
309310
neurons. This is particularly efficient for sparse connectivity patterns.
310311

brainpy/_base_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 BDP Ecosystem Limited. All Rights Reserved.
1+
# Copyright 2025 BrainX Ecosystem Limited. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -29,12 +29,11 @@
2929

3030
import unittest
3131

32-
import brainstate
3332
import braintools
3433
import brainunit as u
35-
import jax
3634
import jax.numpy as jnp
3735

36+
import brainstate
3837
from brainpy._base import Neuron, Synapse
3938

4039

brainpy/_errors.py

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
'MonitorError',
3434
'MathError',
3535
'JaxTracerError',
36-
'ConcretizationTypeError',
3736
'GPUOperatorNotFound',
3837
'SharedArgError',
3938
]
@@ -128,120 +127,6 @@ class MathError(BrainPyError):
128127
__module__ = 'brainpy'
129128

130129

131-
class MPACheckpointingRequiredError(BrainPyError):
132-
"""To optimally save and restore a multiprocess array (GDA or jax Array outputted from pjit), use GlobalAsyncCheckpointManager.
133-
134-
You can create an GlobalAsyncCheckpointManager at top-level and pass it as
135-
argument::
136-
137-
from jax.experimental.gda_serialization import serialization as gdas
138-
gda_manager = gdas.GlobalAsyncCheckpointManager()
139-
brainpy.checkpoints.save(..., gda_manager=gda_manager)
140-
"""
141-
__module__ = 'brainpy'
142-
143-
def __init__(self, path, step):
144-
super().__init__(
145-
f'Checkpoint failed at step: "{step}" and path: "{path}": Target '
146-
'contains a multiprocess array should be saved/restored with a '
147-
'GlobalAsyncCheckpointManager.')
148-
149-
150-
class MPARestoreTargetRequiredError(BrainPyError):
151-
"""Provide a valid target when restoring a checkpoint with a multiprocess array.
152-
153-
Multiprocess arrays need a sharding (global meshes and partition specs) to be
154-
initialized. Therefore, to restore a checkpoint that contains a multiprocess
155-
array, make sure the ``target`` you passed contains valid multiprocess arrays
156-
at the corresponding tree structure location. If you cannot provide a full
157-
valid ``target``, consider ``allow_partial_mpa_restoration=True``.
158-
"""
159-
__module__ = 'brainpy'
160-
161-
def __init__(self, path, step, key=None):
162-
error_msg = (
163-
f'Restore checkpoint failed at step: "{step}" and path: "{path}": '
164-
'Checkpoints containing a multiprocess array need to be restored with '
165-
'a target with pre-created arrays. If you cannot provide a full valid '
166-
'target, consider ``allow_partial_mpa_restoration=True``. ')
167-
if key:
168-
error_msg += f'This error fired when trying to restore array at {key}.'
169-
super().__init__(error_msg)
170-
171-
172-
class MPARestoreDataCorruptedError(BrainPyError):
173-
"""A multiprocess array stored in Google Cloud Storage doesn't contain a "commit_success.txt" file, which should be written at the end of the save.
174-
175-
Failure of finding it could indicate a corruption of your saved GDA data.
176-
"""
177-
__module__ = 'brainpy'
178-
179-
def __init__(self, step, path):
180-
super().__init__(
181-
f'Restore checkpoint failed at step: "{step}" on multiprocess array at '
182-
f' "{path}": No "commit_success.txt" found on this "_gda" directory. '
183-
'Was its save halted before completion?')
184-
185-
186-
class MPARestoreTypeNotMatchError(BrainPyError):
187-
"""Make sure the multiprocess array type you use matches your configuration in jax.config.jax_array.
188-
189-
If you turned `jax.config.jax_array` on, you should use
190-
`jax.experimental.array.Array` everywhere, instead of using
191-
`GlobalDeviceArray`. Otherwise, avoid using jax.experimental.array
192-
to restore your checkpoint.
193-
"""
194-
__module__ = 'brainpy'
195-
196-
def __init__(self, step, gda_path):
197-
super().__init__(
198-
f'Restore checkpoint failed at step: "{step}" on multiprocess array at '
199-
f' "{gda_path}": The array type provided by the target does not match '
200-
'the JAX global configuration, namely the jax.config.jax_array.')
201-
202-
203-
class AlreadyExistsError(BrainPyError):
204-
"""Attempting to overwrite a file via copy.
205-
206-
You can pass ``overwrite=True`` to disable this behavior and overwrite
207-
existing files in.
208-
"""
209-
__module__ = 'brainpy'
210-
211-
def __init__(self, path):
212-
super().__init__(f'Trying overwrite an existing file: "{path}".')
213-
214-
215-
class InvalidCheckpointError(BrainPyError):
216-
"""A checkpoint cannot be stored in a directory that already has
217-
218-
a checkpoint at the current or a later step.
219-
220-
You can pass ``overwrite=True`` to disable this behavior and
221-
overwrite existing checkpoints in the target directory.
222-
"""
223-
__module__ = 'brainpy'
224-
225-
def __init__(self, path, step):
226-
super().__init__(
227-
f'Trying to save an outdated checkpoint at step: "{step}" and path: "{path}".'
228-
)
229-
230-
231-
class InvalidCheckpointPath(BrainPyError):
232-
"""A checkpoint cannot be stored in a directory that already has
233-
234-
a checkpoint at the current or a later step.
235-
236-
You can pass ``overwrite=True`` to disable this behavior and
237-
overwrite existing checkpoints in the target directory.
238-
"""
239-
__module__ = 'brainpy'
240-
241-
def __init__(self, path):
242-
super().__init__(f'Invalid checkpoint at "{path}".')
243-
244-
245130
class JaxTracerError(MathError):
246131
__module__ = 'brainpy'
247132

@@ -271,22 +156,6 @@ def __init__(self, variables=None):
271156
super(JaxTracerError, self).__init__(msg)
272157

273158

274-
class ConcretizationTypeError(Exception):
275-
__module__ = 'brainpy'
276-
277-
def __init__(self):
278-
super(ConcretizationTypeError, self).__init__(
279-
'This problem may be caused by several ways:\n'
280-
'1. Your if-else conditional statement relies on instances of brainpy.math.Variable. \n'
281-
'2. Your if-else conditional statement relies on functional arguments which do not '
282-
'set in "static_argnames" when applying JIT compilation. More details please see '
283-
'https://jax.readthedocs.io/en/latest/errors.html#jax.errors.ConcretizationTypeError\n'
284-
'3. The static variables which set in the "static_argnames" are provided '
285-
'as arguments, not keyword arguments, like "jit_f(v1, v2)" [<- wrong]. '
286-
'Please write it as "jit_f(static_k1=v1, static_k2=v2)" [<- right].'
287-
)
288-
289-
290159
class GPUOperatorNotFound(Exception):
291160
__module__ = 'brainpy'
292161

brainpy/_exponential.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 BDP Ecosystem Limited. All Rights Reserved.
1+
# Copyright 2024 BrainX Ecosystem Limited. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -18,18 +18,20 @@
1818

1919
from typing import Optional, Callable
2020

21-
from brainstate.typing import Size, ArrayLike
22-
import brainstate
2321
import braintools
2422
import brainunit as u
23+
24+
import brainstate
25+
from brainstate.typing import Size, ArrayLike
2526
from ._base import Synapse
27+
from .mixin import AlignPost
2628

2729
__all__ = [
28-
'Expon', 'DualExpon',
30+
'Expon', 'DualExpon',
2931
]
3032

3133

32-
class Expon(Synapse, brainstate.mixin.AlignPost):
34+
class Expon(Synapse, AlignPost):
3335
r"""
3436
Exponential decay synapse model.
3537
@@ -97,7 +99,7 @@ def update(self, x=None):
9799
return self.g.value
98100

99101

100-
class DualExpon(Synapse, brainstate.mixin.AlignPost):
102+
class DualExpon(Synapse, AlignPost):
101103
r"""
102104
Dual exponential synapse model.
103105

brainpy/_inputs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 BDP Ecosystem Limited. All Rights Reserved.
1+
# Copyright 2024 BrainX Ecosystem Limited. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -21,9 +21,8 @@
2121
import numpy as np
2222

2323
import brainstate
24-
from brainstate.typing import ArrayLike, Size, DTypeLike
2524
from brainpy._misc import set_module_as
26-
25+
from brainstate.typing import ArrayLike, Size, DTypeLike
2726

2827
__all__ = [
2928
'SpikeTime',

brainpy/_lif.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 BDP Ecosystem Limited. All Rights Reserved.
1+
# Copyright 2024 BrainX Ecosystem Limited. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -17,16 +17,16 @@
1717

1818
from typing import Callable
1919

20-
import brainstate
20+
import braintools
2121
import brainunit as u
2222
import jax
23-
from brainstate.typing import ArrayLike, Size
2423

25-
import braintools
24+
import brainstate
25+
from brainstate.typing import ArrayLike, Size
2626
from ._base import Neuron
2727

2828
__all__ = [
29-
'IF', 'LIF', 'LIFRef', 'ALIF',
29+
'IF', 'LIF', 'LIFRef', 'ALIF',
3030
]
3131

3232

0 commit comments

Comments
 (0)