Skip to content

Commit c0c7910

Browse files
authored
Merge pull request #356 from chaoming0625/master
fix `Array` transform bug
2 parents 00c790a + b0fd30b commit c0c7910

File tree

3 files changed

+13
-146
lines changed

3 files changed

+13
-146
lines changed

brainpy/_src/math/ndarray.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,12 +1655,11 @@ def update(self, value):
16551655

16561656
def _jaxarray_unflatten(aux_data, flat_contents):
16571657
r = Array(*flat_contents)
1658-
r._transform_context = aux_data[0]
16591658
return r
16601659

16611660

16621661
register_pytree_node(Array,
1663-
lambda t: ((t.value,), (t._transform_context,)),
1662+
lambda t: ((t.value,), None),
16641663
_jaxarray_unflatten)
16651664

16661665
register_pytree_node(Variable,

brainpy/_src/tools/package.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
'SUPPORT_NUMBA',
2424
]
2525

26+
_minimal_brainpylib_version = '0.1.7'
27+
2628

2729
def import_numba():
2830
if numba is None:
@@ -35,6 +37,8 @@ def import_brainpylib():
3537
if brainpylib is None:
3638
raise ModuleNotFoundError('brainpylib is needed. Please install brainpylib through:\n'
3739
'> pip install brainpylib\n\n')
40+
if brainpylib.__version__ < _minimal_brainpylib_version:
41+
raise SystemError(f'This version of brainpy needs brainpylib >= {_minimal_brainpylib_version}.')
3842
return brainpylib
3943

4044

changes.md

Lines changed: 8 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,19 @@
11
# Change from Version 2.3.4 to Version 2.3.5
22

33

4-
This release (under the branch of ``brainpy=2.3.x``) continues to add supports for brain-inspired computation.
4+
This release continues to add supports for improving the usability of BrainPy.
55

66

77
## New Features
88

99

10-
### 1. ``brainpy.share`` for sharing data across submodules
10+
1. New data structures for object-oriented transformations.
11+
- ``NodeList`` and ``NodeDict`` for a list/tuple/dict of ``BrainPyObject`` instances.
12+
- ``ListVar`` and ``DictVar`` for a list/tuple/dict of brainpy data.
13+
2. `Clip` transformation for brainpy initializers.
14+
3. All ``brainpylib`` operators are accessible in ``brainpy.math`` module.
15+
4. Enable monitoring GPU models on CPU when setting ``DSRunner(..., memory_efficient=True)``. This setting can usually reduce so much memory usage.
16+
5. ``brainpylib`` wheels on the linux platform support the GPU operators. Users can install gpu version of ``brainpylib`` (require ``brainpylib>=0.1.7``) directly by ``pip install brainpylib``.
1117

12-
In this release, we abstract the shared data as a ``brainpy.share`` object.
1318

14-
This object together with ``brainpy.Delay`` we will introduce below
15-
constitute the support that enable to define SNN models like ANN ones.
16-
17-
18-
### 2. ``brainpy.Delay`` for delay processing
19-
20-
``Delay`` is abstracted as a dynamical system, which can be updated / retrieved by users.
21-
22-
```python
23-
import brainpy as bp
24-
25-
class EINet(bp.DynamicalSystemNS):
26-
def __init__(self, scale=1.0, e_input=20., i_input=20., delay=None):
27-
super().__init__()
28-
29-
self.bg_exc = e_input
30-
self.bg_inh = i_input
31-
32-
# network size
33-
num_exc = int(3200 * scale)
34-
num_inh = int(800 * scale)
35-
36-
# neurons
37-
pars = dict(V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.,
38-
V_initializer=bp.init.Normal(-55., 2.), input_var=False)
39-
self.E = bp.neurons.LIF(num_exc, **pars)
40-
self.I = bp.neurons.LIF(num_inh, **pars)
41-
42-
# synapses
43-
we = 0.6 / scale # excitatory synaptic weight (voltage)
44-
wi = 6.7 / scale # inhibitory synaptic weight
45-
self.E2E = bp.experimental.Exponential(
46-
bp.conn.FixedProb(0.02, pre=self.E.size, post=self.E.size),
47-
g_max=we, tau=5., out=bp.experimental.COBA(E=0.)
48-
)
49-
self.E2I = bp.experimental.Exponential(
50-
bp.conn.FixedProb(0.02, pre=self.E.size, post=self.I.size, ),
51-
g_max=we, tau=5., out=bp.experimental.COBA(E=0.)
52-
)
53-
self.I2E = bp.experimental.Exponential(
54-
bp.conn.FixedProb(0.02, pre=self.I.size, post=self.E.size),
55-
g_max=wi, tau=10., out=bp.experimental.COBA(E=-80.)
56-
)
57-
self.I2I = bp.experimental.Exponential(
58-
bp.conn.FixedProb(0.02, pre=self.I.size, post=self.I.size),
59-
g_max=wi, tau=10., out=bp.experimental.COBA(E=-80.)
60-
)
61-
self.delayE = bp.Delay(self.E.spike, entries={'E': delay})
62-
self.delayI = bp.Delay(self.I.spike, entries={'I': delay})
63-
64-
def update(self):
65-
e_spike = self.delayE.at('E')
66-
i_spike = self.delayI.at('I')
67-
e_inp = self.E2E(e_spike, self.E.V) + self.I2E(i_spike, self.E.V) + self.bg_exc
68-
i_inp = self.I2I(i_spike, self.I.V) + self.E2I(e_spike, self.I.V) + self.bg_inh
69-
self.delayE(self.E(e_inp))
70-
self.delayI(self.I(i_inp))
71-
72-
```
73-
74-
75-
76-
### 3. ``brainpy.checkpoints.save_pytree`` and ``brainpy.checkpoints.load_pytree`` for saving/loading target from the filename
77-
78-
Now we can directly use ``brainpy.checkpoints.save_pytree`` to save a
79-
network state into the filepath we specified.
80-
81-
Similarly, we can use ``brainpy.checkpoints.load_pytree`` to load
82-
states from the given file path.
83-
84-
85-
### 4. More ANN layers
86-
87-
88-
- brainpy.layers.ConvTranspose1d
89-
- brainpy.layers.ConvTranspose2d
90-
- brainpy.layers.ConvTranspose3d
91-
- brainpy.layers.Conv1dLSTMCell
92-
- brainpy.layers.Conv2dLSTMCell
93-
- brainpy.layers.Conv3dLSTMCell
94-
95-
96-
### 5. More compatible dense operators
97-
98-
PyTorch operators:
99-
100-
- brainpy.math.Tensor
101-
- brainpy.math.flatten
102-
- brainpy.math.cat
103-
- brainpy.math.abs
104-
- brainpy.math.absolute
105-
- brainpy.math.acos
106-
- brainpy.math.arccos
107-
- brainpy.math.acosh
108-
- brainpy.math.arccosh
109-
- brainpy.math.add
110-
- brainpy.math.addcdiv
111-
- brainpy.math.addcmul
112-
- brainpy.math.angle
113-
- brainpy.math.asin
114-
- brainpy.math.arcsin
115-
- brainpy.math.asinh
116-
- brainpy.math.arcsin
117-
- brainpy.math.atan
118-
- brainpy.math.arctan
119-
- brainpy.math.atan2
120-
- brainpy.math.atanh
121-
122-
123-
TensorFlow operators:
124-
125-
- brainpy.math.concat
126-
- brainpy.math.reduce_sum
127-
- brainpy.math.reduce_max
128-
- brainpy.math.reduce_min
129-
- brainpy.math.reduce_mean
130-
- brainpy.math.reduce_all
131-
- brainpy.math.reduce_any
132-
- brainpy.math.reduce_logsumexp
133-
- brainpy.math.reduce_prod
134-
- brainpy.math.reduce_std
135-
- brainpy.math.reduce_variance
136-
- brainpy.math.reduce_euclidean_norm
137-
- brainpy.math.unsorted_segment_sqrt_n
138-
- brainpy.math.segment_mean
139-
- brainpy.math.unsorted_segment_sum
140-
- brainpy.math.unsorted_segment_prod
141-
- brainpy.math.unsorted_segment_max
142-
- brainpy.math.unsorted_segment_min
143-
- brainpy.math.unsorted_segment_mean
144-
- brainpy.math.segment_sum
145-
- brainpy.math.segment_prod
146-
- brainpy.math.segment_max
147-
- brainpy.math.segment_min
148-
- brainpy.math.clip_by_value
149-
- brainpy.math.cast
150-
151-
152-
### Others
153-
154-
- Remove the hard requirements of ``brainpylib`` and ``numba``.
15519

0 commit comments

Comments
 (0)