Skip to content

Commit 7160d65

Browse files
authored
Docs update and bugs fixed (#247)
Docs update and bugs fixed
2 parents 1edfce5 + 417c1ed commit 7160d65

Some content is hidden

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

63 files changed

+6502
-5328
lines changed

.github/workflows/MacOS_CI.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ jobs:
2828
run: |
2929
python -m pip install --upgrade pip
3030
python -m pip install flake8 pytest
31-
# python -m pip install https://github.com/google/jax/archive/refs/tags/jax-v0.3.14.tar.gz
31+
python -m pip install jax==0.3.14
32+
python -m pip install jaxlib==0.3.14
3233
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
3334
python setup.py install
3435
- name: Lint with flake8

brainpy/algorithms/offline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import brainpy.math as bm
99
from brainpy.base import Base
10-
from brainpy.types import Tensor
10+
from brainpy.types import Array
1111
from .utils import (Sigmoid,
1212
Regularization, L1Regularization, L1L2Regularization, L2Regularization,
1313
polynomial_features, normalize)
@@ -60,7 +60,7 @@ def __call__(self, identifier, target, input, output):
6060
"""
6161
return self.call(identifier, target, input, output)
6262

63-
def call(self, identifier, targets, inputs, outputs) -> Tensor:
63+
def call(self, identifier, targets, inputs, outputs) -> Array:
6464
"""The training procedure.
6565
6666
Parameters
@@ -355,7 +355,7 @@ def __init__(
355355
self.gradient_descent = gradient_descent
356356
self.sigmoid = Sigmoid()
357357

358-
def call(self, identifier, targets, inputs, outputs=None) -> Tensor:
358+
def call(self, identifier, targets, inputs, outputs=None) -> Array:
359359
# prepare data
360360
inputs = _check_data_2d_atls(bm.asarray(inputs))
361361
targets = _check_data_2d_atls(bm.asarray(targets))

brainpy/analysis/highdim/slow_points.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from brainpy.dyn.runners import build_inputs, check_and_format_inputs
1919
from brainpy.errors import AnalyzerError, UnsupportedError
2020
from brainpy.tools.others.dicts import DotDict
21-
from brainpy.types import Tensor
21+
from brainpy.types import Array
2222

2323
__all__ = [
2424
'SlowPointFinder',
@@ -295,7 +295,7 @@ def selected_ids(self, val):
295295

296296
def find_fps_with_gd_method(
297297
self,
298-
candidates: Union[Tensor, Dict[str, Tensor]],
298+
candidates: Union[Array, Dict[str, Array]],
299299
tolerance: Union[float, Dict[str, float]] = 1e-5,
300300
num_batch: int = 100,
301301
num_opt: int = 10000,
@@ -305,7 +305,7 @@ def find_fps_with_gd_method(
305305
306306
Parameters
307307
----------
308-
candidates : Tensor, dict
308+
candidates : Array, dict
309309
The array with the shape of (batch size, state dim) of hidden states
310310
of RNN to start training for fixed points.
311311
@@ -402,14 +402,14 @@ def batch_train(start_i, n_batch):
402402

403403
def find_fps_with_opt_solver(
404404
self,
405-
candidates: Union[Tensor, Dict[str, Tensor]],
405+
candidates: Union[Array, Dict[str, Array]],
406406
opt_solver: str = 'BFGS'
407407
):
408408
"""Optimize fixed points with nonlinear optimization solvers.
409409
410410
Parameters
411411
----------
412-
candidates: Tensor, dict
412+
candidates: Array, dict
413413
The candidate (initial) fixed points.
414414
opt_solver: str
415415
The solver of the optimization.
@@ -536,7 +536,7 @@ def exclude_outliers(self, tolerance: float = 1e0):
536536

537537
def compute_jacobians(
538538
self,
539-
points: Union[Tensor, Dict[str, Tensor]],
539+
points: Union[Array, Dict[str, Array]],
540540
stack_dict_var: bool = True,
541541
plot: bool = False,
542542
num_col: int = 4,

brainpy/dyn/base.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from brainpy.integrators import odeint, sdeint
1919
from brainpy.modes import Mode, TrainingMode, BatchingMode, normal, training
2020
from brainpy.tools.others import to_size, size2num
21-
from brainpy.types import Tensor, Shape
21+
from brainpy.types import Array, Shape
2222

2323
__all__ = [
2424
# general class
@@ -70,17 +70,17 @@ def __init__(
7070
name: str = None,
7171
mode: Optional[Mode] = None,
7272
):
73-
super(DynamicalSystem, self).__init__(name=name)
74-
75-
# local delay variables
76-
self.local_delay_vars: Dict[str, bm.LengthDelay] = Collector()
77-
7873
# mode setting
7974
if mode is None: mode = normal
8075
if not isinstance(mode, Mode):
8176
raise ValueError(f'Should be instance of {Mode.__name__}, but we got {type(Mode)}: {Mode}')
8277
self._mode = mode
8378

79+
super(DynamicalSystem, self).__init__(name=name)
80+
81+
# local delay variables
82+
self.local_delay_vars: Dict[str, bm.LengthDelay] = Collector()
83+
8484
# fitting parameters
8585
self.online_fit_by = None
8686
self.offline_fit_by = None
@@ -106,9 +106,9 @@ def __call__(self, *args, **kwargs):
106106
def register_delay(
107107
self,
108108
identifier: str,
109-
delay_step: Optional[Union[int, Tensor, Callable, Initializer]],
109+
delay_step: Optional[Union[int, Array, Callable, Initializer]],
110110
delay_target: bm.Variable,
111-
initial_delay_data: Union[Initializer, Callable, Tensor, float, int, bool] = None,
111+
initial_delay_data: Union[Initializer, Callable, Array, float, int, bool] = None,
112112
):
113113
"""Register delay variable.
114114
@@ -317,14 +317,14 @@ def offline_init(self):
317317

318318
@tools.not_customized
319319
def online_fit(self,
320-
target: Tensor,
321-
fit_record: Dict[str, Tensor]):
320+
target: Array,
321+
fit_record: Dict[str, Array]):
322322
raise NoImplementationError('Subclass must implement online_fit() function when using OnlineTrainer.')
323323

324324
@tools.not_customized
325325
def offline_fit(self,
326-
target: Tensor,
327-
fit_record: Dict[str, Tensor]):
326+
target: Array,
327+
fit_record: Dict[str, Array]):
328328
raise NoImplementationError('Subclass must implement offline_fit() function when using OfflineTrainer.')
329329

330330
def clear_input(self):
@@ -482,7 +482,7 @@ def f(x):
482482
entries = '\n'.join(f' [{i}] {f(x)}' for i, x in enumerate(self))
483483
return f'{self.__class__.__name__}(\n{entries}\n)'
484484

485-
def update(self, sha: dict, x: Any) -> Tensor:
485+
def update(self, sha: dict, x: Any) -> Array:
486486
"""Update function of a sequential model.
487487
488488
Parameters
@@ -494,7 +494,7 @@ def update(self, sha: dict, x: Any) -> Tensor:
494494
495495
Returns
496496
-------
497-
y: Tensor
497+
y: Array
498498
The output tensor.
499499
"""
500500
for node in self.implicit_nodes.values():
@@ -686,7 +686,7 @@ def __init__(
686686
self,
687687
pre: NeuGroup,
688688
post: NeuGroup,
689-
conn: Union[TwoEndConnector, Tensor, Dict[str, Tensor]] = None,
689+
conn: Union[TwoEndConnector, Array, Dict[str, Array]] = None,
690690
name: str = None,
691691
mode: Mode = normal,
692692
):
@@ -904,7 +904,7 @@ def __init__(
904904
self,
905905
pre: NeuGroup,
906906
post: NeuGroup,
907-
conn: Union[TwoEndConnector, Tensor, Dict[str, Tensor]] = None,
907+
conn: Union[TwoEndConnector, Array, Dict[str, Array]] = None,
908908
output: SynOut = NullSynOut(),
909909
stp: SynSTP = NullSynSTP(),
910910
ltp: SynLTP = NullSynLTP(),
@@ -946,10 +946,10 @@ def __init__(
946946

947947
def init_weights(
948948
self,
949-
weight: Union[float, Tensor, Initializer, Callable],
949+
weight: Union[float, Array, Initializer, Callable],
950950
comp_method: str,
951951
sparse_data: str = 'csr'
952-
) -> Union[float, Tensor]:
952+
) -> Union[float, Array]:
953953
if comp_method not in ['sparse', 'dense']:
954954
raise ValueError(f'"comp_method" must be in "sparse" and "dense", but we got {comp_method}')
955955
if sparse_data not in ['csr', 'ij']:
@@ -1061,11 +1061,11 @@ def __init__(
10611061
self,
10621062
size: Shape,
10631063
keep_size: bool = False,
1064-
C: Union[float, Tensor, Initializer, Callable] = 1.,
1065-
A: Union[float, Tensor, Initializer, Callable] = 1e-3,
1066-
V_th: Union[float, Tensor, Initializer, Callable] = 0.,
1067-
V_initializer: Union[Initializer, Callable, Tensor] = Uniform(-70, -60.),
1068-
noise: Union[float, Tensor, Initializer, Callable] = None,
1064+
C: Union[float, Array, Initializer, Callable] = 1.,
1065+
A: Union[float, Array, Initializer, Callable] = 1e-3,
1066+
V_th: Union[float, Array, Initializer, Callable] = 0.,
1067+
V_initializer: Union[Initializer, Callable, Array] = Uniform(-70, -60.),
1068+
noise: Union[float, Array, Initializer, Callable] = None,
10691069
method: str = 'exp_auto',
10701070
name: str = None,
10711071
mode: Mode = normal,

0 commit comments

Comments
 (0)