Coverage for pySDC/projects/Performance/visualize.py: 0%

41 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 14:51 +0000

1import glob 

2import json 

3import numpy as np 

4import pySDC.helpers.plot_helper as plt_helper 

5 

6 

7def joint_plots(list_of_result_paths): 

8 # get result data from JUBE tables 

9 results = [] 

10 for result_path in list_of_result_paths: 

11 results.append(np.genfromtxt(result_path, names=True, skip_header=1, delimiter='|', dtype=float, comments='--')) 

12 

13 # fill arrays with data 

14 ncores = np.concatenate(results)['ntasks'] * np.concatenate(results)['nnodes'] 

15 timings_space = results[0]['timing_pat'] 

16 timings_spacetime = results[1]['timing_pat'] 

17 ideal = [timings_space[0] / (c / ncores[0]) for c in np.unique(ncores)] 

18 

19 # setup and fill plots 

20 plt_helper.setup_mpl() 

21 plt_helper.newfig(textwidth=238.96, scale=1.0) 

22 

23 plt_helper.plt.loglog(np.unique(ncores), ideal, 'k--', label='ideal') 

24 plt_helper.plt.loglog( 

25 ncores[0 : len(results[0])], 

26 timings_space, 

27 lw=1, 

28 ls='-', 

29 color='b', 

30 marker='o', 

31 markersize=4, 

32 markeredgecolor='k', 

33 label='parallel-in-space', 

34 ) 

35 plt_helper.plt.loglog( 

36 ncores[-len(results[1]) :], 

37 timings_spacetime, 

38 lw=1, 

39 ls='-', 

40 color='r', 

41 marker='d', 

42 markersize=4, 

43 markeredgecolor='k', 

44 label='parallel-in-space-time', 

45 ) 

46 

47 plt_helper.plt.grid() 

48 plt_helper.plt.legend(loc=3, ncol=1) 

49 plt_helper.plt.xlabel('Number of cores') 

50 plt_helper.plt.ylabel('Time [s]') 

51 

52 # save plot, beautify 

53 fname = 'data/scaling' 

54 plt_helper.savefig(fname) 

55 

56 

57def plot_data(name=''): 

58 """ 

59 Visualization using numpy arrays (written via MPI I/O) and json description 

60 

61 Produces one png file per time-step, combine as movie via e.g. 

62 > ffmpeg -i data/name_%08d.png name.mp4 

63 

64 Args: 

65 name (str): name of the simulation (expects data to be in data path) 

66 """ 

67 

68 # get data and json files 

69 json_files = sorted(glob.glob(f'./data/{name}_*.json')) 

70 data_files = sorted(glob.glob(f'./data/{name}_*.dat')) 

71 

72 # setup plotting 

73 plt_helper.setup_mpl() 

74 

75 for json_file, data_file in zip(json_files, data_files): 

76 with open(json_file, 'r') as fp: 

77 obj = json.load(fp) 

78 

79 index = json_file.split('_')[1].split('.')[0] 

80 print(f'Working on step {index}...') 

81 

82 # get data and format 

83 array = np.fromfile(data_file, dtype=obj['datatype']) 

84 array = array.reshape(obj['shape'], order='C') 

85 

86 # plot 

87 plt_helper.newfig(textwidth=238.96, scale=1.0) 

88 plt_helper.plt.imshow(array, vmin=0, vmax=1, extent=[-2, 2, -2, 2], origin='lower') 

89 

90 plt_helper.plt.yticks(range(-2, 3)) 

91 cbar = plt_helper.plt.colorbar() 

92 cbar.set_label('concentration') 

93 # plt_helper.plt.title(f"Time: {obj['time']:6.4f}") 

94 

95 # save plot, beautify 

96 fname = f'data/{name}_{index}' 

97 plt_helper.savefig(fname, save_pgf=False, save_png=False) 

98 

99 

100if __name__ == '__main__': 

101 list_of_result_paths = [ 

102 'data/bench_run_SPxTS/000004/result/result.dat', 

103 'data/bench_run_SPxTP/000002/result/result.dat', 

104 ] 

105 

106 # joint_plots(list_of_result_paths) 

107 plot_data(name='AC-bench-noforce')