Skip to content

Commit 77b65f2

Browse files
committed
refactor: Reorganize import statements for improved structure and readability
1 parent d6c4cf0 commit 77b65f2

1 file changed

Lines changed: 56 additions & 64 deletions

File tree

brainpy/__init__.py

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,31 @@
33

44
__version__ = "3.0.0"
55

6+
# Part: Toolbox #
7+
# --------------- #
8+
# modules of toolbox
9+
from brainpy import (
10+
connect, # synaptic connection
11+
initialize, # weight initialization
12+
optim, # gradient descent optimizers
13+
losses, # loss functions
14+
measure, # methods for data analysis
15+
inputs, # methods for generating input currents
16+
encoding, # encoding schema
17+
checkpoints, # checkpoints
18+
check, # error checking
19+
mixin, # mixin classes
20+
algorithms, # online or offline training algorithms
21+
)
622
# fundamental supporting modules
723
from brainpy import errors, check, tools
824

9-
try:
10-
import jaxlib
11-
del jaxlib
12-
except ModuleNotFoundError:
13-
raise ModuleNotFoundError(tools.jaxlib_install_info) from None
14-
15-
# Part: Math Foundation #
16-
# ----------------------- #
17-
1825
# math foundation
1926
from brainpy import math
2027
from .math import BrainPyObject
2128

22-
# Part: Toolbox #
23-
# --------------- #
24-
# modules of toolbox
25-
from brainpy import (
26-
connect, # synaptic connection
27-
initialize, # weight initialization
28-
optim, # gradient descent optimizers
29-
losses, # loss functions
30-
measure, # methods for data analysis
31-
inputs, # methods for generating input currents
32-
encoding, # encoding schema
33-
checkpoints, # checkpoints
34-
check, # error checking
35-
mixin, # mixin classes
36-
algorithms, # online or offline training algorithms
37-
)
29+
# Part: Math Foundation #
30+
# ----------------------- #
3831

3932
# convenient alias
4033
conn = connect
@@ -50,34 +43,35 @@
5043
from brainpy._src.integrators.sde.generic import (sdeint as sdeint)
5144
from brainpy._src.integrators.fde.generic import (fdeint as fdeint)
5245

53-
5446
# Part: Models #
5547
# -------------- #
5648

5749
# base classes
5850
from brainpy._src.dynsys import (
59-
DynamicalSystem as DynamicalSystem,
60-
DynSysGroup as DynSysGroup, # collectors
61-
Sequential as Sequential,
62-
Dynamic as Dynamic, # category
63-
Projection as Projection,
64-
receive_update_input, # decorators
65-
receive_update_output,
66-
not_receive_update_input,
67-
not_receive_update_output,
51+
DynamicalSystem as DynamicalSystem,
52+
DynSysGroup as DynSysGroup, # collectors
53+
Sequential as Sequential,
54+
Dynamic as Dynamic, # category
55+
Projection as Projection,
56+
receive_update_input, # decorators
57+
receive_update_output,
58+
not_receive_update_input,
59+
not_receive_update_output,
6860
)
61+
6962
DynamicalSystemNS = DynamicalSystem
7063
Network = DynSysGroup
7164
# delays
7265
from brainpy._src.delay import (
73-
VarDelay as VarDelay,
66+
VarDelay as VarDelay,
7467
)
7568

7669
# building blocks
7770
from brainpy import (
78-
dnn, layers, # module for dnn layers
79-
dyn, # module for modeling dynamics
71+
dnn, layers, # module for dnn layers
72+
dyn, # module for modeling dynamics
8073
)
74+
8175
NeuGroup = NeuGroupNS = dyn.NeuDyn
8276

8377
# common tools
@@ -94,60 +88,58 @@
9488
from brainpy._src.transform import (LoopOverTime as LoopOverTime, )
9589
from brainpy import (running as running)
9690

97-
9891
# Part: Training #
9992
# ---------------- #
10093
from brainpy._src.train.base import (DSTrainer as DSTrainer, )
10194
from brainpy._src.train.back_propagation import (BPTT as BPTT,
102-
BPFF as BPFF,)
95+
BPFF as BPFF, )
10396
from brainpy._src.train.online import (OnlineTrainer as OnlineTrainer,
10497
ForceTrainer as ForceTrainer, )
10598
from brainpy._src.train.offline import (OfflineTrainer as OfflineTrainer,
10699
RidgeTrainer as RidgeTrainer, )
107100

108-
109101
# Part: Analysis #
110102
# ---------------- #
111103
from brainpy import (analysis as analysis)
112104

113-
114105
# Part: Others #
115106
# ---------------- #
116107
from brainpy._src.visualization import (visualize as visualize)
117108

118-
119109
# Part: Deprecations #
120110
# -------------------- #
121111
from brainpy._src import train
122112
from brainpy import (
123-
channels, # channel models
124-
neurons, # neuron groups
125-
synapses, # synapses
126-
rates, # rate models
127-
experimental,
128-
synouts, # synaptic output
129-
synplast, # synaptic plasticity
113+
channels, # channel models
114+
neurons, # neuron groups
115+
synapses, # synapses
116+
rates, # rate models
117+
experimental,
118+
synouts, # synaptic output
119+
synplast, # synaptic plasticity
130120
)
131121
from brainpy._src import modes
132-
from brainpy._src.math.object_transform.base import (Base as Base,
133-
ArrayCollector as ArrayCollector,
134-
Collector as Collector, )
122+
from brainpy._src.math.object_transform.base import (
123+
Base as Base,
124+
ArrayCollector as ArrayCollector,
125+
Collector as Collector,
126+
)
135127

136128
# deprecated
137129
from brainpy._add_deprecations import deprecation_getattr2
138130

139131
__deprecations = {
140-
'Module': ('brainpy.Module', 'brainpy.DynamicalSystem', DynamicalSystem),
141-
'Channel': ('brainpy.Channel', 'brainpy.dyn.IonChannel', dyn.IonChannel),
142-
'SynConn': ('brainpy.SynConn', 'brainpy.dyn.SynConn', dyn.SynConn),
143-
'Container': ('brainpy.Container', 'brainpy.DynSysGroup', DynSysGroup),
144-
145-
'optimizers': ('brainpy.optimizers', 'brainpy.optim', optim),
146-
'TensorCollector': ('brainpy.TensorCollector', 'brainpy.ArrayCollector', ArrayCollector),
147-
'SynSTP': ('brainpy.SynSTP', 'brainpy.synapses.SynSTP', synapses.SynSTP),
148-
'SynOut': ('brainpy.SynOut', 'brainpy.synapses.SynOut', synapses.SynOut),
149-
'TwoEndConn': ('brainpy.TwoEndConn', 'brainpy.synapses.TwoEndConn', synapses.TwoEndConn),
150-
'CondNeuGroup': ('brainpy.CondNeuGroup', 'brainpy.dyn.CondNeuGroup', dyn.CondNeuGroup),
132+
'Module': ('brainpy.Module', 'brainpy.DynamicalSystem', DynamicalSystem),
133+
'Channel': ('brainpy.Channel', 'brainpy.dyn.IonChannel', dyn.IonChannel),
134+
'SynConn': ('brainpy.SynConn', 'brainpy.dyn.SynConn', dyn.SynConn),
135+
'Container': ('brainpy.Container', 'brainpy.DynSysGroup', DynSysGroup),
136+
137+
'optimizers': ('brainpy.optimizers', 'brainpy.optim', optim),
138+
'TensorCollector': ('brainpy.TensorCollector', 'brainpy.ArrayCollector', ArrayCollector),
139+
'SynSTP': ('brainpy.SynSTP', 'brainpy.synapses.SynSTP', synapses.SynSTP),
140+
'SynOut': ('brainpy.SynOut', 'brainpy.synapses.SynOut', synapses.SynOut),
141+
'TwoEndConn': ('brainpy.TwoEndConn', 'brainpy.synapses.TwoEndConn', synapses.TwoEndConn),
142+
'CondNeuGroup': ('brainpy.CondNeuGroup', 'brainpy.dyn.CondNeuGroup', dyn.CondNeuGroup),
151143
}
152144
__getattr__ = deprecation_getattr2('brainpy', __deprecations)
153145

0 commit comments

Comments
 (0)