From 9eb9fba0600bda1276a53ac7b4c568159e17ab89 Mon Sep 17 00:00:00 2001 From: Espen Hagen <2492641+espenhgn@users.noreply.github.com> Date: Mon, 22 Mar 2021 11:50:13 +0100 Subject: [PATCH] fixed gathering of somavs if number of cells < MPI::Size (#323) --- examples/example_network/example_network.py | 40 ++++++++++++++----- .../example_network_to_file.py | 40 ++++++++++++++----- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/examples/example_network/example_network.py b/examples/example_network/example_network.py index 9bdfdd79..36418ba4 100644 --- a/examples/example_network/example_network.py +++ b/examples/example_network/example_network.py @@ -315,6 +315,7 @@ def draw_lineplot( if RANK == 0: somavs = [] for i, name in enumerate(population_names): + somavs_pop = None # avoid undeclared variable for j, cell in enumerate(network.populations[name].cells): if j == 0: somavs_pop = cell.somav @@ -322,8 +323,17 @@ def draw_lineplot( somavs_pop = np.vstack((somavs_pop, cell.somav)) if RANK == 0: for j in range(1, SIZE): - somavs_pop = np.vstack((somavs_pop, - COMM.recv(source=j, tag=15))) + recv = COMM.recv(source=j, tag=15) + if somavs_pop is None: + if recv is not None: + somavs_pop = recv + else: + continue + else: + if recv is not None: + somavs_pop = np.vstack((somavs_pop, recv)) + if somavs_pop.ndim == 1: + somavs_pop = somavs_pop.reshape((1, -1)) somavs.append(somavs_pop) else: COMM.send(somavs_pop, dest=0, tag=15) @@ -342,7 +352,7 @@ def draw_lineplot( for spt, gid in zip(spts, gids): t = np.r_[t, spt] g = np.r_[g, np.zeros(spt.size) + gid] - ax.plot(t[t >= 200], g[t >= 200], '.', label=name) + ax.plot(t[t >= 200], g[t >= 200], '.', ms=3, label=name) ax.legend(loc=1) remove_axis_junk(ax, lines=['right', 'top']) ax.set_xlabel('t (ms)') @@ -354,11 +364,16 @@ def draw_lineplot( # somatic potentials fig = plt.figure() - gs = GridSpec(5, 1) - ax = fig.add_subplot(gs[:4]) + gs = GridSpec(4, 1) + ax = fig.add_subplot(gs[:2]) + if somavs[0].shape[0] > 10: + somavs_pop = ss.decimate(somavs[0][:10], q=16, axis=-1, + zero_phase=True) + else: + somavs_pop = ss.decimate(somavs[0], q=16, axis=-1, + zero_phase=True) draw_lineplot(ax, - ss.decimate(somavs[0][::4], q=16, axis=-1, - zero_phase=True), + somavs_pop, dt=network.dt * 16, T=(200, 1200), scaling_factor=1., @@ -376,10 +391,15 @@ def draw_lineplot( ax.set_title('somatic potentials') ax.set_xlabel('') - ax = fig.add_subplot(gs[4]) + ax = fig.add_subplot(gs[2:]) + if somavs[1].shape[0] > 10: + somavs_pop = ss.decimate(somavs[1][:10], q=16, axis=-1, + zero_phase=True) + else: + somavs_pop = ss.decimate(somavs[1], q=16, axis=-1, + zero_phase=True) draw_lineplot(ax, - ss.decimate(somavs[1][::4], q=16, axis=-1, - zero_phase=True), + somavs_pop, dt=network.dt * 16, T=(200, 1200), scaling_factor=1., diff --git a/examples/example_network/example_network_to_file.py b/examples/example_network/example_network_to_file.py index 16df12f8..8535bab6 100644 --- a/examples/example_network/example_network_to_file.py +++ b/examples/example_network/example_network_to_file.py @@ -319,6 +319,7 @@ def draw_lineplot( if RANK == 0: somavs = [] for i, name in enumerate(population_names): + somavs_pop = None # avoid undeclared variable for j, cell in enumerate(network.populations[name].cells): if j == 0: somavs_pop = cell.somav @@ -326,8 +327,17 @@ def draw_lineplot( somavs_pop = np.vstack((somavs_pop, cell.somav)) if RANK == 0: for j in range(1, SIZE): - somavs_pop = np.vstack((somavs_pop, - COMM.recv(source=j, tag=15))) + recv = COMM.recv(source=j, tag=15) + if somavs_pop is None: + if recv is not None: + somavs_pop = recv + else: + continue + else: + if recv is not None: + somavs_pop = np.vstack((somavs_pop, recv)) + if somavs_pop.ndim == 1: + somavs_pop = somavs_pop.reshape((1, -1)) somavs.append(somavs_pop) else: COMM.send(somavs_pop, dest=0, tag=15) @@ -346,7 +356,7 @@ def draw_lineplot( for spt, gid in zip(spts, gids): t = np.r_[t, spt] g = np.r_[g, np.zeros(spt.size) + gid] - ax.plot(t[t >= 200], g[t >= 200], '.', label=name) + ax.plot(t[t >= 200], g[t >= 200], '.', ms=3, label=name) ax.legend(loc=1) remove_axis_junk(ax, lines=['right', 'top']) ax.set_xlabel('t (ms)') @@ -358,11 +368,16 @@ def draw_lineplot( # somatic potentials fig = plt.figure() - gs = GridSpec(5, 1) - ax = fig.add_subplot(gs[:4]) + gs = GridSpec(4, 1) + ax = fig.add_subplot(gs[:2]) + if somavs[0].shape[0] > 10: + somavs_pop = ss.decimate(somavs[0][:10], q=16, axis=-1, + zero_phase=True) + else: + somavs_pop = ss.decimate(somavs[0], q=16, axis=-1, + zero_phase=True) draw_lineplot(ax, - ss.decimate(somavs[0][::4], q=16, axis=-1, - zero_phase=True), + somavs_pop, dt=network.dt * 16, T=(200, 1200), scaling_factor=1., @@ -380,10 +395,15 @@ def draw_lineplot( ax.set_title('somatic potentials') ax.set_xlabel('') - ax = fig.add_subplot(gs[4]) + ax = fig.add_subplot(gs[2:]) + if somavs[1].shape[0] > 10: + somavs_pop = ss.decimate(somavs[1][:10], q=16, axis=-1, + zero_phase=True) + else: + somavs_pop = ss.decimate(somavs[1], q=16, axis=-1, + zero_phase=True) draw_lineplot(ax, - ss.decimate(somavs[1][::4], q=16, axis=-1, - zero_phase=True), + somavs_pop, dt=network.dt * 16, T=(200, 1200), scaling_factor=1.,