Skip to content

Commit 100ebe2

Browse files
committed
fix(examples): repair 6 broken example scripts (API drift, data path, channels)
Triaged all 24 examples/ scripts. 14 already pass; the following 6 are fixed and verified (construction + forward pass / short sim, or full run): - integrate_flax_into_brainpy: bp.layers.GRUCell -> bp.dyn.GRUCell (relocated) - whole_brain_simulation_with_fhn / _sl_oscillator: load the bundled hcp.npz from the brainpy package (the old ../../tests/simulation/data path no longer exists; the file lives at brainpy/dyn/rates/data/hcp.npz) - Song_2016_EI_RNN / highdim_RNN_Analysis: RandomState(seed=...) -> positional (the kwarg was renamed to seed_or_key) - mnist_ResNet: parameterize ResNet in_channels and pass 1 for 1-channel MNIST (was hardcoded to 3, raising a channel-mismatch ValueError) The remaining 4 are unchanged: they need optional deps or exceed the sandbox time budget -- reservoir-mnist (functional but ~11 min of training), integrate_brainpy_into_flax-{lif,convlstm} (tensorflow_datasets), spikebased_bp_for_cifar10 (torch).
1 parent a5e75b2 commit 100ebe2

6 files changed

Lines changed: 20 additions & 16 deletions

File tree

examples/dynamics_analysis/highdim_RNN_Analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(
3636
self.alpha = 1
3737
else:
3838
self.alpha = dt / self.tau
39-
self.rng = bm.random.RandomState(seed=seed)
39+
self.rng = bm.random.RandomState(seed)
4040

4141
# input weight
4242
self.w_ir = bm.TrainVar(bp.init.parameter(w_ir, (num_input, num_hidden)))

examples/dynamics_simulation/whole_brain_simulation_with_fhn.py

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

33

4+
import os
5+
46
import matplotlib.pyplot as plt
57
import numpy as np
68

@@ -25,11 +27,11 @@ class Network(bp.DynSysGroup):
2527
def __init__(self, signal_speed=20.):
2628
super(Network, self).__init__()
2729

28-
# Please download the processed data "hcp.npz" of the
29-
# ConnectomeDB of the Human Connectome Project (HCP)
30-
# from the following link:
31-
# - https://share.weiyun.com/wkPpARKy
32-
hcp = np.load('../../tests/simulation/data/hcp.npz')
30+
# HCP connectome data ("hcp.npz", processed from the ConnectomeDB of
31+
# the Human Connectome Project) is bundled with BrainPy at
32+
# ``brainpy/dyn/rates/data/hcp.npz``.
33+
hcp_path = os.path.join(os.path.dirname(bp.__file__), 'dyn', 'rates', 'data', 'hcp.npz')
34+
hcp = np.load(hcp_path)
3335
conn_mat = bm.asarray(hcp['Cmat'])
3436
bm.fill_diagonal(conn_mat, 0)
3537
delay_mat = bm.round(hcp['Dmat'] / signal_speed / bm.dt).astype(bm.int_)

examples/dynamics_simulation/whole_brain_simulation_with_sl_oscillator.py

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

3+
import os
4+
35
import matplotlib.pyplot as plt
46
import numpy as np
57

@@ -26,11 +28,11 @@ class Network(bp.DynSysGroup):
2628
def __init__(self, noise=0.14):
2729
super(Network, self).__init__()
2830

29-
# Please download the processed data "hcp.npz" of the
30-
# ConnectomeDB of the Human Connectome Project (HCP)
31-
# from the following link:
32-
# - https://share.weiyun.com/wkPpARKy
33-
hcp = np.load('../../tests/simulation/data/hcp.npz')
31+
# HCP connectome data ("hcp.npz", processed from the ConnectomeDB of
32+
# the Human Connectome Project) is bundled with BrainPy at
33+
# ``brainpy/dyn/rates/data/hcp.npz``.
34+
hcp_path = os.path.join(os.path.dirname(bp.__file__), 'dyn', 'rates', 'data', 'hcp.npz')
35+
hcp = np.load(hcp_path)
3436
conn_mat = bm.asarray(hcp['Cmat'])
3537
bm.fill_diagonal(conn_mat, 0)
3638
gc = 0.6 # global coupling strength

examples/dynamics_training/Song_2016_EI_RNN.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
self.i_size = num_hidden - self.e_size
3939
self.alpha = dt / self.tau
4040
self.sigma_rec = (2 * self.alpha) ** 0.5 * sigma_rec # Recurrent noise
41-
self.rng = bm.random.RandomState(seed=seed)
41+
self.rng = bm.random.RandomState(seed)
4242

4343
# hidden mask
4444
mask = np.tile([1] * self.e_size + [-1] * self.i_size, (num_hidden, 1))

examples/dynamics_training/integrate_flax_into_brainpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Network(bp.DynamicalSystem):
3030
def __init__(self):
3131
super(Network, self).__init__()
3232
self.cnn = bp.layers.FromFlax(CNN(), bm.ones([1, 4, 28, 1]))
33-
self.rnn = bp.layers.GRUCell(256, 100)
33+
self.rnn = bp.dyn.GRUCell(256, 100)
3434
self.linear = bp.layers.Dense(100, 10)
3535

3636
def update(self, x):

examples/training_ann_models/mnist_ResNet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def update(self, s, x):
8989

9090

9191
class ResNet(bp.DynamicalSystem):
92-
def __init__(self, block, num_blocks, num_classes=10, zero_init_residual=False):
92+
def __init__(self, block, num_blocks, num_classes=10, in_channels=3, zero_init_residual=False):
9393
super(ResNet, self).__init__()
9494
self.in_planes = 64
9595

96-
self.conv1 = bp.layers.Conv2D(3, 64, kernel_size=(3, 3), strides=(1, 1), padding=(1, 1),
96+
self.conv1 = bp.layers.Conv2D(in_channels, 64, kernel_size=(3, 3), strides=(1, 1), padding=(1, 1),
9797
w_initializer=weight_init)
9898
self.bn1 = bp.layers.BatchNorm2D(64)
9999
self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=1)
@@ -208,7 +208,7 @@ def main():
208208
y_test = bm.asarray(test_set.targets, dtype=bm.int_)
209209

210210
with bm.training_environment():
211-
net = ResNet18(num_classes=10)
211+
net = ResNet18(num_classes=10, in_channels=1)
212212

213213
# loss function
214214
def loss_fun(X, Y, fit=True):

0 commit comments

Comments
 (0)