Skip to content

Commit dc2f81e

Browse files
authored
Merge branch 'brainpy:master' into master
2 parents 5b68b71 + 6b86740 commit dc2f81e

File tree

163 files changed

+7291
-4898
lines changed

Some content is hidden

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

163 files changed

+7291
-4898
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ publishment.md
33
.vscode
44
io_test_tmp*
55

6-
brainpy/base/tests/io_test_tmp*
6+
brainpy/math/brainpy_object/tests/io_test_tmp*
77

88
development
99

@@ -217,3 +217,7 @@ cython_debug/
217217
/docs/apis/simulation/generated/
218218
!/brainpy/dyn/tests/data/
219219
/examples/dynamics_simulation/data/
220+
/examples/training_snn_models/logs/T100_b64_lr0.001/
221+
/examples/training_snn_models/logs/
222+
/examples/training_snn_models/data/
223+
/docs/tutorial_advanced/data/

brainpy/__init__.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,8 @@
66
# fundamental modules
77
from . import errors, check, tools
88

9-
# "base" module
10-
from . import base
11-
from .base import (
12-
# base class
13-
Base,
14-
BrainPyObject,
15-
16-
# collector
17-
Collector,
18-
ArrayCollector,
19-
TensorCollector,
20-
)
21-
229
# math foundation
2310
from . import math
24-
from . import modes
2511

2612
# toolboxes
2713
from . import (
@@ -69,7 +55,7 @@
6955
synouts, # synaptic output
7056
synplast, # synaptic plasticity
7157

72-
# base classes
58+
# brainpy_object classes
7359
DynamicalSystem,
7460
Container,
7561
Sequential,
@@ -113,9 +99,7 @@
11399

114100
# running
115101
from . import running
116-
from .running import (
117-
Runner
118-
)
102+
from .running import (Runner)
119103

120104
# "visualization" module, will be removed soon
121105
from .visualization import visualize
@@ -124,3 +108,15 @@
124108
conn = connect
125109
init = initialize
126110
optim = optimizers
111+
112+
from . import experimental
113+
114+
115+
# deprecated
116+
from . import base
117+
# use ``brainpy.math.*`` instead
118+
from brainpy.math.object_transform.base_object import (Base, BrainPyObject,)
119+
# use ``brainpy.math.*`` instead
120+
from brainpy.math.object_transform.collector import (Collector, ArrayCollector, TensorCollector,)
121+
# use ``brainpy.math.*`` instead
122+
from . import modes

brainpy/algorithms/offline.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
from jax.lax import while_loop
77

88
import brainpy.math as bm
9-
from brainpy.base import BrainPyObject
109
from brainpy.types import ArrayType
1110
from .utils import (Sigmoid,
1211
Regularization, L1Regularization, L1L2Regularization, L2Regularization,
1312
polynomial_features, normalize)
1413

1514
__all__ = [
16-
# base class for offline training algorithm
15+
# brainpy_object class for offline training algorithm
1716
'OfflineAlgorithm',
1817

1918
# training methods
@@ -33,7 +32,7 @@
3332
name2func = dict()
3433

3534

36-
class OfflineAlgorithm(BrainPyObject):
35+
class OfflineAlgorithm(bm.BrainPyObject):
3736
"""Base class for offline training algorithm."""
3837

3938
def __init__(self, name=None):

brainpy/algorithms/online.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# -*- coding: utf-8 -*-
22

33
import brainpy.math as bm
4-
from brainpy.base import BrainPyObject
54
from jax import vmap
65
import jax.numpy as jnp
76

87
__all__ = [
9-
# base class
8+
# brainpy_object class
109
'OnlineAlgorithm',
1110

1211
# online learning algorithms
@@ -21,7 +20,7 @@
2120
name2func = dict()
2221

2322

24-
class OnlineAlgorithm(BrainPyObject):
23+
class OnlineAlgorithm(bm.BrainPyObject):
2524
"""Base class for online training algorithm."""
2625

2726
def __init__(self, name=None):

brainpy/analysis/highdim/slow_points.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import brainpy.math as bm
1414
from brainpy import optimizers as optim, losses
1515
from brainpy.analysis import utils, base, constants
16-
from brainpy.base import ArrayCollector
1716
from brainpy.dyn.base import DynamicalSystem
1817
from brainpy.dyn.runners import check_and_format_inputs, _f_ops
1918
from brainpy.errors import AnalyzerError, UnsupportedError
@@ -133,11 +132,11 @@ def __init__(
133132

134133
# update function
135134
if target_vars is None:
136-
self.target_vars = ArrayCollector()
135+
self.target_vars = bm.ArrayCollector()
137136
else:
138137
if not isinstance(target_vars, dict):
139138
raise TypeError(f'"target_vars" must be a dict but we got {type(target_vars)}')
140-
self.target_vars = ArrayCollector(target_vars)
139+
self.target_vars = bm.ArrayCollector(target_vars)
141140
excluded_vars = () if excluded_vars is None else excluded_vars
142141
if isinstance(excluded_vars, dict):
143142
excluded_vars = tuple(excluded_vars.values())

brainpy/analysis/lowdim/lowdim_analyzer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from brainpy import errors, tools
1313
from brainpy.analysis import constants as C, utils
1414
from brainpy.analysis.base import DSAnalyzer
15-
from brainpy.base.collector import Collector
1615

1716
pyplot = None
1817

@@ -91,7 +90,7 @@ def __init__(
9190
if not isinstance(target_vars, dict):
9291
raise errors.AnalyzerError('"target_vars" must be a dict, with the format of '
9392
'{"var1": (var1_min, var1_max)}.')
94-
self.target_vars = Collector(target_vars)
93+
self.target_vars = bm.Collector(target_vars)
9594
self.target_var_names = list(self.target_vars.keys()) # list of target vars
9695
for key in self.target_vars.keys():
9796
if key not in self.model.variables:
@@ -110,7 +109,7 @@ def __init__(
110109
for key in fixed_vars.keys():
111110
if key not in self.model.variables:
112111
raise ValueError(f'{key} is not a dynamical variable in {self.model}.')
113-
self.fixed_vars = Collector(fixed_vars)
112+
self.fixed_vars = bm.Collector(fixed_vars)
114113

115114
# check duplicate
116115
for key in self.fixed_vars.keys():
@@ -125,7 +124,7 @@ def __init__(
125124
if not isinstance(pars_update, dict):
126125
raise errors.AnalyzerError('"pars_update" must be a dict with the format '
127126
'of {"par1": val1, "par2": val2}.')
128-
pars_update = Collector(pars_update)
127+
pars_update = bm.Collector(pars_update)
129128
for key in pars_update.keys():
130129
if key not in self.model.parameters:
131130
raise errors.AnalyzerError(f'"{key}" is not a valid parameter in "{self.model}" model.')
@@ -144,7 +143,7 @@ def __init__(
144143
raise errors.AnalyzerError(
145144
f'The range of parameter {key} is reversed, which means {value[0]} should be smaller than {value[1]}.')
146145

147-
self.target_pars = Collector(target_pars)
146+
self.target_pars = bm.Collector(target_pars)
148147
self.target_par_names = list(self.target_pars.keys()) # list of target_pars
149148

150149
# check duplicate

brainpy/base/__init__.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
The ``base`` module for whole BrainPy ecosystem.
5-
6-
- This module provides the most fundamental class ``BrainPyObject``,
7-
and its associated helper class ``Collector`` and ``ArrayCollector``.
8-
- For each instance of "BrainPyObject" class, users can retrieve all
9-
the variables (or trainable variables), integrators, and nodes.
10-
- This module also provides a ``FunAsObject`` class to wrap user-defined
11-
functions. In each function, maybe several nodes are used, and
12-
users can initialize a ``FunAsObject`` by providing the nodes used
13-
in the function. Unfortunately, ``FunAsObject`` class does not have
14-
the ability to gather nodes automatically.
15-
- This module provides ``io`` helper functions to help users save/load
16-
model states, or share user's customized model with others.
17-
- This module provides ``naming`` tools to guarantee the unique nameing
18-
for each BrainPyObject object.
19-
20-
Details please see the following.
4+
This module is deprecated since version 2.3.1.
5+
Please use ``brainpy.math.*`` instead.
216
"""
227

23-
from brainpy.base.base import *
24-
from brainpy.base.collector import *
25-
from brainpy.base.function import *
26-
from brainpy.base.io import *
27-
from brainpy.base.naming import *
8+
9+
from .base import *
10+
from .collector import *
11+
from .function import *
12+
from .io import *
13+
from .naming import *
2814

0 commit comments

Comments
 (0)