def run_reneg(): v = VPICReader(sys.argv[1]) n = v.get_num_ranks() print("Ranks: ", n) global TSIDX TSIDX = int(sys.argv[2]) print("TS: ", v.get_ts(TSIDX)) global all_loads all_loads = [0] * 32 read_into_global(v) gen_anim_frames() gen_hist(0.01) fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.clear() #animate(v, ax1, len(anim_frames) - 1) # ani = animation.FuncAnimation(fig, lambda x: animate_reneg( # v, ax1, x), interval=10, frames=len(anim_frames)) animate_reneg(v, ax1, len(anim_frames) - 1) plt.show()
def run(): v = VPICReader(sys.argv[1]) n = v.get_num_ranks() print("Ranks: ", n) global TSIDX TSIDX = int(sys.argv[2]) read_into_global(v) gen_anim_frames() gen_hist(1.0) fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) ax1.clear() #animate(v, ax1, len(anim_frames) - 1) ani = animation.FuncAnimation(fig, lambda x: animate(v, ax1, x), interval=10, frames=len(anim_frames)) #plt.show() fname = 'vis/loadbalance.finbins.%s.512samples.gif' % (v.get_ts(TSIDX)) print(fname) ani.save(fname, writer='imagemagick', fps=30, dpi=200)
def generate_distribution_violin(data_path: str, num_ranks: int, timesteps: int, bw_value: float): num_ranks = 2 vpic_reader = VPICReader(data_path, num_ranks=num_ranks) fig = go.Figure() for tsidx in range(0, timesteps): data = vpic_reader.read_global(tsidx) print(len(data)) # plotted_data = np.random.choice(data, 50000) plotted_data = np.random.choice(data, 500) head_cutoff = 0.5 head_cutoff_2 = 4 tail_cutoff = 10 head_data = len([i for i in plotted_data if i < head_cutoff]) head_data_2 = len([i for i in plotted_data if i < head_cutoff_2]) tail_data = len([i for i in plotted_data if i > tail_cutoff]) percent_head = head_data * 100.0 / len(plotted_data) percent_head_2 = head_data_2 * 100.0 / len(plotted_data) percent_tail = tail_data * 100.0 / len(plotted_data) print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff, percent_head)) print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff_2, percent_head_2)) print('TS {0}, > {1}: {2:.2f}'.format(tsidx, tail_cutoff, percent_tail)) plotted_data = list(map(lambda x: log_tailed(x, 10), plotted_data)) ts_name = 'Timestep {0}'.format(vpic_reader.get_ts(tsidx), ) violin_data = go.Violin(y=plotted_data, box_visible=False, meanline_visible=False, name=ts_name, side='positive', points=False, bandwidth=bw_value, scalemode='width', line=dict(width=1)) fig.add_trace(violin_data) fig.update_traces(width=1.8) fig.update_layout( title_text='Energy distribution from 4 timesteps of a VPIC simulation' ' (tail is logarithmic)', yaxis=dict(tickmode='array', tickvals=list(range(0, 18, 2)), ticktext=[ '{0:.0f}'.format(log_tailed_reverse(x, 10)) for x in range(0, 18, 2) ]), ) fig.show()
def generate_distribution_box(data_path: str, num_ranks: int, timesteps: int): # num_ranks = 4 vpic_reader = VPICReader(data_path, num_ranks=num_ranks) fig = go.Figure() for tsidx in range(0, timesteps): data = vpic_reader.read_global(tsidx) print(len(data)) plotted_data = np.random.choice(data, 50000) head_cutoff = 2 tail_cutoff = 10 head_data = len([i for i in plotted_data if i < head_cutoff]) tail_data = len([i for i in plotted_data if i > tail_cutoff]) percent_head = head_data * 100.0 / len(plotted_data) percent_tail = tail_data * 100.0 / len(plotted_data) print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff, percent_head)) print('TS {0}, > {1}: {2:.2f}'.format(tsidx, tail_cutoff, percent_tail)) plotted_data = list(map(lambda x: log_tailed(x, 10), plotted_data)) ts_name = 'Timestep {0}'.format(vpic_reader.get_ts(tsidx), ) box_data = go.Box(y=plotted_data, name=ts_name, line_width=1, marker=dict(size=4, line=dict(width=0))) fig.add_trace(box_data) fig.update_layout( title_text='Energy distribution from 4 timesteps of a VPIC simulation' ' (tail is logarithmic)', yaxis=dict(tickmode='array', tickvals=list(range(0, 18, 2)), ticktext=[ '{0:.0f}'.format(log_tailed_reverse(x, 10)) for x in range(0, 18, 2) ]), ) # fig.show() fig.write_image('../vis/poster/vpic32.distrib.box.pdf')
class TestVPICReader(unittest.TestCase): def setUp(self): self.vpicReader = VPICReader('.') self.assertEqual(self.vpicReader.get_num_ranks(), 32) return def teardown(self): return
def plot_hist_4(): v = VPICReader(sys.argv[1]) n = v.get_num_ranks() print("Ranks: ", n) fig, axes = plt.subplots(2, 2) for row in range(2): for col in range(2): plot_simple_hist(v, axes[row][col], row * 2 + col) # break # break plt.ylim([0, 0.5]) plt.tight_layout() # plt.show() plt.savefig("vis/ASCR/vpic_distrib.pdf") return
def test_2_rank_pivots(self): vpicReader = VPICReader('.') rank = Rank(vpicReader, 2) rank.insert(range(20)) pivots, pivot_width = rank.compute_pivots(5) self.assertEqual(pivots, [0, 5, 10, 15, 19]) self.assertAlmostEqual(pivot_width, 5.0) return
def test_1_insert_init(self): self.vpicReader = VPICReader('.') self.rank = Rank(self.vpicReader, 2) self.rank.insert(range(20)) self.assertEqual(len(self.rank.oob_left), 20, msg="init insertion not okay") self.assertEqual(len(self.rank.oob_right), 0, msg="init insertion not okay") self.assertIsNone(self.rank.pivots) self.assertIsNone(self.rank.pivot_counts)
def _test_num_pivots(self, num_pivots): vpic_reader = VPICReader('../data') reneg = Renegotiation(32, 0, vpic_reader) reneg.set_NUM_PIVOTS(num_pivots) reneg.read_all() reneg.insert(0.05) reneg.plot() del vpic_reader del reneg vpic_reader = None reneg = None
def setUp(self): self.vpicReader = VPICReader('.') self.assertEqual(self.vpicReader.get_num_ranks(), 32) return
def run(): vpicReader = VPICReader(data_path) rank0 = Rank(vpicReader, 0) print(rank0.get_id()) rank0.read(0)
def generate_distribution_violin_alt(data_path: str, fig_path: str, num_ranks: int = None, bw_value: float = 0.03): # num_ranks = 4 vpic_reader = VPICReader(data_path, num_ranks=num_ranks) ranks = vpic_reader.get_num_ranks() timesteps = vpic_reader.get_num_ts() print('[VPICReader] Ranks: {0}, ts: {1}'.format(ranks, timesteps)) fig = go.Figure() all_shapes = [] all_annotations = [] timestamps = [ vpic_reader.get_ts(i) for i in range(vpic_reader.get_num_ts()) ] for tsidx in range(0, timesteps): data = vpic_reader.sample_global(tsidx) print('Read: ', len(data)) plotted_data = data head_cutoff = 0.5 head_cutoff_2 = 4 tail_cutoff = 10 head_data = len([i for i in plotted_data if i < head_cutoff]) head_data_2 = len([i for i in plotted_data if i < head_cutoff_2]) tail_data = len([i for i in plotted_data if i > tail_cutoff]) percent_head = head_data * 100.0 / len(plotted_data) percent_head_2 = head_data_2 * 100.0 / len(plotted_data) percent_tail = tail_data * 100.0 / len(plotted_data) print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff, percent_head)) print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff_2, percent_head_2)) print('TS {0}, > {1}: {2:.2f}'.format(tsidx, tail_cutoff, percent_tail)) plotted_data = list(map(lambda x: log_tailed(x, 10), plotted_data)) ts_name = 'Timestep {0}'.format(vpic_reader.get_ts(tsidx), ) violin_data = go.Violin(y=plotted_data, box_visible=False, meanline_visible=False, name=ts_name, side='positive', points=False, bandwidth=bw_value, scalemode='width', line=dict(width=1)) fig.add_trace(violin_data) label = 'Tail Mass: <br /> {0:.1f}%'.format(100 - percent_head_2) print(label) gen_annotation(all_shapes, all_annotations, label, tsidx + 0.1, 4, max(plotted_data)) fig.update_traces(width=1.8) fig.update_layout(xaxis=dict( title=dict(text="Simulation Time (s)", ), ticktext=timestamps, tickvals=[x + 0.2 for x in range(timesteps)], color='#000', linecolor='#444', ), yaxis=dict(title=dict(text='Particle Energy (eV)', ), tickmode='array', tickvals=list(range(0, 18, 2)), ticktext=[ '{0:.0f}'.format(log_tailed_reverse( x, 10)) for x in range(0, 18, 2) ], linecolor='#444', showgrid=True, gridcolor='#ddd'), plot_bgcolor='#fff', shapes=all_shapes, annotations=all_annotations, showlegend=False, legend=dict(x=0.87, y=1), font=dict(size=18)) # fig.show() # fig.write_image( # '../vis/poster/vpic32.distrib.violin.alt.{0}.pdf'.format(bw_value)) fig.write_image(fig_path)