|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | # Copyright 2025 BrainX Ecosystem Limited. All Rights Reserved. |
2 | 3 | # |
3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
|
13 | 14 | # limitations under the License. |
14 | 15 | # ============================================================================== |
15 | 16 |
|
16 | | -__version__ = "3.0.0" |
17 | | -__version_info__ = (3, 0, 0) |
18 | | - |
19 | | -from . import mixin |
20 | | -from . import version2 |
21 | | -from ._base import * |
22 | | -from ._base import __all__ as base_all |
23 | | -from ._errors import * |
24 | | -from ._errors import __all__ as errors_all |
25 | | -from ._exponential import * |
26 | | -from ._exponential import __all__ as exp_all |
27 | | -from ._inputs import * |
28 | | -from ._inputs import __all__ as inputs_all |
29 | | -from ._lif import * |
30 | | -from ._lif import __all__ as neuron_all |
31 | | -from ._projection import * |
32 | | -from ._projection import __all__ as proj_all |
33 | | -from ._readout import * |
34 | | -from ._readout import __all__ as readout_all |
35 | | -from ._stp import * |
36 | | -from ._stp import __all__ as stp_all |
37 | | -from ._synapse import * |
38 | | -from ._synapse import __all__ as synapse_all |
39 | | -from ._synaptic_projection import * |
40 | | -from ._synaptic_projection import __all__ as synproj_all |
41 | | -from ._synouts import * |
42 | | -from ._synouts import __all__ as synout_all |
43 | | - |
44 | | -__main__ = ['version2', 'mixin'] + errors_all + inputs_all + neuron_all + readout_all + stp_all + synapse_all |
45 | | -__main__ = __main__ + synout_all + base_all + exp_all + proj_all + synproj_all |
46 | | -del errors_all, inputs_all, neuron_all, readout_all, stp_all, synapse_all, synout_all, base_all |
47 | | -del exp_all, proj_all, synproj_all |
48 | | - |
49 | | - |
50 | | -# Deprecation warnings for brainpy.xxx -> brainpy.version2.xxx |
51 | | -def __getattr__(name): |
52 | | - """Provide deprecation warnings for moved modules.""" |
53 | | - import warnings |
54 | | - |
55 | | - if hasattr(version2, name): |
56 | | - warnings.warn( |
57 | | - f"Accessing 'brainpy.{name}' is deprecated. " |
58 | | - f"Please use 'brainpy.version2.{name}' instead.", |
59 | | - DeprecationWarning, |
60 | | - stacklevel=2 |
61 | | - ) |
62 | | - return getattr(version2, name) |
63 | | - |
64 | | - raise AttributeError(f"'brainpy' has no attribute '{name}'") |
65 | | - |
66 | | - |
67 | | -def __dir__(): |
68 | | - """Return list of attributes including deprecated ones for tab completion.""" |
69 | | - # Get the default attributes |
70 | | - default_attrs = list(globals().keys()) |
71 | | - |
72 | | - # Add all public attributes from version2 for discoverability |
73 | | - version2_attrs = [attr for attr in dir(version2) if not attr.startswith('_')] |
74 | | - |
75 | | - # Combine and return unique attributes |
76 | | - return sorted(set(default_attrs + version2_attrs)) |
77 | | - |
78 | | - |
79 | | -# Register deprecated modules in sys.modules to support "import brainpy.xxx" syntax |
80 | | -import sys as _sys |
81 | | - |
82 | | -_deprecated_modules = [ |
83 | | - 'math', 'check', 'tools', 'connect', 'initialize', 'init', 'conn', |
84 | | - 'optim', 'losses', 'measure', 'inputs', 'encoding', 'checkpoints', |
85 | | - 'algorithms', 'integrators', 'ode', 'sde', 'fde', |
86 | | - 'dnn', 'layers', 'dyn', 'running', 'train', 'analysis', |
87 | | - 'channels', 'neurons', 'rates', 'synapses', 'synouts', 'synplast', |
88 | | - 'visualization', 'visualize', 'types', 'modes', 'context', |
89 | | - 'helpers', 'delay', 'dynsys', 'runners', 'transform', 'dynold' |
90 | | -] |
91 | | - |
92 | | -# Create wrapper modules that show deprecation warnings |
93 | | -for _mod_name in _deprecated_modules: |
94 | | - if hasattr(version2, _mod_name): |
95 | | - _sys.modules[f'brainpy.{_mod_name}'] = getattr(version2, _mod_name) |
96 | | - |
97 | | -del _sys, _mod_name, _deprecated_modules |
98 | | - |
99 | | -version2.__version__ = __version__ |
| 17 | +__version__ = "3.0.1" |
| 18 | +__version_info__ = (3, 0, 1) |
| 19 | + |
| 20 | + |
| 21 | +from brainpy import _errors as errors |
| 22 | +from brainpy import mixin |
| 23 | +# fundamental supporting modules |
| 24 | +from brainpy import check, tools |
| 25 | +# Part: Math Foundation # |
| 26 | +# ----------------------- # |
| 27 | +# math foundation |
| 28 | +from brainpy import math |
| 29 | +# Part: Toolbox # |
| 30 | +# --------------- # |
| 31 | +# modules of toolbox |
| 32 | +from . import ( |
| 33 | + connect, # synaptic connection |
| 34 | + initialize, # weight initialization |
| 35 | + optim, # gradient descent optimizers |
| 36 | + losses, # loss functions |
| 37 | + measure, # methods for data analysis |
| 38 | + inputs, # methods for generating input currents |
| 39 | + encoding, # encoding schema |
| 40 | + checkpoints, # checkpoints |
| 41 | + check, # error checking |
| 42 | + algorithms, # online or offline training algorithms |
| 43 | +) |
| 44 | +from .math import BrainPyObject |
| 45 | + |
| 46 | +# convenient alias |
| 47 | +conn = connect |
| 48 | +init = initialize |
| 49 | + |
| 50 | +# numerical integrators |
| 51 | +from brainpy import integrators |
| 52 | +from brainpy.integrators import ode, sde, fde |
| 53 | +from brainpy.integrators.base import (Integrator as Integrator) |
| 54 | +from brainpy.integrators.joint_eq import (JointEq as JointEq) |
| 55 | +from brainpy.integrators.runner import (IntegratorRunner as IntegratorRunner) |
| 56 | +from brainpy.integrators.ode.generic import (odeint as odeint) |
| 57 | +from brainpy.integrators.sde.generic import (sdeint as sdeint) |
| 58 | +from brainpy.integrators.fde.generic import (fdeint as fdeint) |
| 59 | + |
| 60 | +# Part: Models # |
| 61 | +# -------------- # |
| 62 | + |
| 63 | +# base classes |
| 64 | +from brainpy.dynsys import ( |
| 65 | + DynamicalSystem as DynamicalSystem, |
| 66 | + DynSysGroup as DynSysGroup, # collectors |
| 67 | + Sequential as Sequential, |
| 68 | + Dynamic as Dynamic, # category |
| 69 | + Projection as Projection, |
| 70 | + receive_update_input, # decorators |
| 71 | + receive_update_output, |
| 72 | + not_receive_update_input, |
| 73 | + not_receive_update_output, |
| 74 | +) |
| 75 | + |
| 76 | +DynamicalSystemNS = DynamicalSystem |
| 77 | +Network = DynSysGroup |
| 78 | +# delays |
| 79 | +from brainpy.delay import ( |
| 80 | + VarDelay as VarDelay, |
| 81 | +) |
| 82 | + |
| 83 | +# building blocks |
| 84 | +from brainpy import ( |
| 85 | + dnn, layers, # module for dnn layers |
| 86 | + dyn, # module for modeling dynamics |
| 87 | +) |
| 88 | + |
| 89 | +NeuGroup = NeuGroupNS = dyn.NeuDyn |
| 90 | +dyn.DynamicalSystem = DynamicalSystem |
| 91 | + |
| 92 | +# common tools |
| 93 | +from brainpy.context import (share as share) |
| 94 | +from brainpy.helpers import ( |
| 95 | + reset_level as reset_level, |
| 96 | + reset_state as reset_state, |
| 97 | + save_state as save_state, |
| 98 | + load_state as load_state, |
| 99 | + clear_input as clear_input |
| 100 | +) |
| 101 | + |
| 102 | +# Part: Running # |
| 103 | +# --------------- # |
| 104 | +from brainpy.runners import (DSRunner as DSRunner) |
| 105 | +from brainpy.transform import (LoopOverTime as LoopOverTime, ) |
| 106 | +from brainpy import (running as running) |
| 107 | + |
| 108 | +# Part: Training # |
| 109 | +# ---------------- # |
| 110 | +from brainpy.train.base import (DSTrainer as DSTrainer, ) |
| 111 | +from brainpy.train.back_propagation import (BPTT as BPTT, |
| 112 | + BPFF as BPFF, ) |
| 113 | +from brainpy.train.online import (OnlineTrainer as OnlineTrainer, |
| 114 | + ForceTrainer as ForceTrainer, ) |
| 115 | +from brainpy.train.offline import (OfflineTrainer as OfflineTrainer, |
| 116 | + RidgeTrainer as RidgeTrainer, ) |
| 117 | + |
| 118 | +# Part: Analysis # |
| 119 | +# ---------------- # |
| 120 | +from brainpy import (analysis as analysis) |
| 121 | + |
| 122 | +# Part: Others # |
| 123 | +# ---------------- # |
| 124 | +import brainpy.visualization as visualize |
| 125 | + |
| 126 | +# Part: Deprecations # |
| 127 | +# -------------------- # |
| 128 | +from brainpy import train |
| 129 | +from brainpy import ( |
| 130 | + channels, # channel models |
| 131 | + neurons, # neuron groups |
| 132 | + synapses, # synapses |
| 133 | + rates, # rate models |
| 134 | + synouts, # synaptic output |
| 135 | + synplast, # synaptic plasticity |
| 136 | +) |
| 137 | +from brainpy.math.object_transform.base import ( |
| 138 | + Base as Base, |
| 139 | +) |
| 140 | + |
| 141 | +from brainpy.math.object_transform.collectors import ( |
| 142 | + ArrayCollector as ArrayCollector, |
| 143 | + Collector as Collector, |
| 144 | +) |
| 145 | + |
| 146 | + |
| 147 | +from brainpy.deprecations import deprecation_getattr |
| 148 | + |
| 149 | +optimizers = optim |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +if __name__ == '__main__': |
| 154 | + connect |
| 155 | + initialize, # weight initialization |
| 156 | + optim, # gradient descent optimizers |
| 157 | + losses, # loss functions |
| 158 | + measure, # methods for data analysis |
| 159 | + inputs, # methods for generating input currents |
| 160 | + encoding, # encoding schema |
| 161 | + checkpoints, # checkpoints |
| 162 | + check, # error checking |
| 163 | + mixin, # mixin classes |
| 164 | + algorithms, # online or offline training algorithms |
| 165 | + check, tools, errors, math |
| 166 | + BrainPyObject, |
| 167 | + integrators, ode, sde, fde |
| 168 | + Integrator, JointEq, IntegratorRunner, odeint, sdeint, fdeint |
| 169 | + DynamicalSystem, DynSysGroup, Sequential, Dynamic, Projection |
| 170 | + receive_update_input, receive_update_output, not_receive_update_input, not_receive_update_output |
| 171 | + VarDelay |
| 172 | + dnn, layers, dyn |
| 173 | + NeuGroup, NeuGroupNS |
| 174 | + share |
| 175 | + reset_level, reset_state, save_state, load_state, clear_input |
| 176 | + DSRunner, LoopOverTime, running |
| 177 | + DSTrainer, BPTT, BPFF, OnlineTrainer, ForceTrainer, |
| 178 | + OfflineTrainer, RidgeTrainer |
| 179 | + analysis |
| 180 | + visualize |
| 181 | + train |
| 182 | + channels, neurons, synapses, rates, state_based, synouts, synplast |
| 183 | + modes |
| 184 | + Base |
| 185 | + ArrayCollector, Collector, errors |
0 commit comments