Python wrapper for running instances of trisurf-ng
Samo Penic
2017-01-14 5f0a3578dc6208fede1dc0da0d35fac03e5474d7
commit | author | age
8c3c29 1 #!/usr/bin/python3
SP 2 from trisurf import tsmgr
3 from trisurf import trisurf
4 from trisurf import statistics
5
6 print("Running trisurf version "+ tsmgr.getTrisurfVersion())
7 Runs=[]
8 Nshell=25
9
10 #--------- F = 0 ------------
11 #kapa_list=[10,20,30,40,50]
12 #p=[5,10,15,20,25]
13
14 #N=5*Nshell**2+2
15 #Nc_list=[int(N*pp/100)  for pp in p]
16
17 #for kapa in kapa_list:
18 #    for Nc in Nc_list:
19 #        run=trisurf.Runner(tape='tape_Nc'+str(Nc)+'_k'+str(kapa))
20 #        run.setMaindir(("N", "k", "V", "_Nc", "_c","_w"),  ("nshell","xk0","constvolswitch","number_of_vertices_with_c0","c0", "w"))
21 #        run.setSubdir("run0")
22 #        Runs.append(run)
23
24 #----------------------------
25 #--------- F = 0 ------------
26 kapa_list=[15,16,17,18,19,20,21,22]
27 #p=[5,7.5,10,12.5]
28 p=[8,8.5,9,9.5,10.5,11,11.5,12]
29
30 N=5*Nshell**2+2
31 Nc_list=[int(N*pp/100)  for pp in p]
32 #print(Nc_list)
33
34 #spremenil sem, ker nimam vseh podatkov!!!
35 kapa_list=[15,16,18,19,20,21,21,22]
36 Nc_list=[156,234,312,390]
37
38 for kapa in kapa_list:
39     for Nc in Nc_list:
40         #print('tape_Nc'+str(Nc)+'_k'+str(kapa))
41         run=trisurf.Runner(tape='tape_Nc'+str(Nc)+'_k'+str(kapa))
42         run.setMaindir(("N", "k", "V", "_Nc", "_c","_w"),  ("nshell","xk0","constvolswitch","number_of_vertices_with_c0","c0", "w"))
43         run.setSubdir("run0")
44         Runs.append(run)
45
46 #----------------------------
47
48 #kapa_list=[20,30]
49 #p=[10]
50 #
51 #N=5*Nshell**2+2
52 #Nc_list=[int(N*pp/100)  for pp in p]
53 #
54 #for kapa in kapa_list:
55 #    for Nc in Nc_list:
56 #        run=trisurf.Runner(snapshot='is_from_N25k'+str(kapa)+'V0_Nc312_c1.0.vtu')
57 #        run.setMaindir(("N", "k", "V", "_Nc", "_c","_w","_F"),  ("nshell","xk0","constvolswitch","number_of_vertices_with_c0","c0", "w","F"))
58 #        run.setSubdir("run0")
59 #
60 #        Runs.append(run)
61
62 #----------------------------
63
64
65
66 #Nov format:
67 #hosts=({'name':'Hestia','address':'127.0.0.1', 'runs':Runs,  'username':'samo'},)
68
69 def analyze(run, **kwargs):
70     host=kwargs.get('host', None)
71     print("Demo analysis")
72     print("Analysis on host "+host['name']+" for run "+run.Dir.fullpath()+" completed")
1c8250 73     print("here comes info on the run variable:")
SP 74     print(run)
75     print("here comes info on the host variable:")
76     print(host)
77     print("here comes info on the args variable:")
78     print(kwargs.get('args',None))
8c3c29 79
SP 80 def plothbar(run, **kwargs):
81     import matplotlib.pyplot as plt
82
83     def smooth(y, box_pts):
84         import numpy as np
85         box = np.ones(box_pts)/box_pts
86         y_smooth = np.convolve(y, box, mode='same')
87         return y_smooth
88     table=trisurf.Statistics(run.Dir.fullpath(),filename='data_tspoststat.csv').getTable()
89     plt.plot(table['hbar'], '.')
90     plt.title(run.Dir.fullpath())
91     plt.xlabel('Iteration')
92     plt.ylabel('hbar')
93     smooth_window=10
94     smoothed=smooth(table['hbar'],smooth_window)
95     plt.plot(tuple(range(int(smooth_window/2),len(smoothed)-int(smooth_window/2))),smoothed[int(smooth_window/2):-int(smooth_window/2)])
96     plt.show()
97     print
98     #if return False or no return statement, the analysis will continue with next running instance in the list. if return True, the analysis will stop after this run.
99     return False
100
5f0a35 101 def plotrunningavginteractive(run, **kwargs):
8c3c29 102     import matplotlib.pyplot as plt
5f0a35 103     from trisurf import VTKRendering as vtk
SP 104     import math
8c3c29 105     table=trisurf.Statistics(run.Dir.fullpath(),filename='data_tspoststat.csv').getTable()
SP 106     def running_avg(col):
107         import numpy as np
108         avg=[]    
109         for i in range(0,len(col)):
110             avg.append(np.average(col[:-i]))
111         return avg
5f0a35 112     fig=plt.figure(1)
8c3c29 113     ra=running_avg(table['hbar'])
SP 114     plt.plot(ra)
115     plt.title('Running average')
116     plt.ylabel('1/n sum_i=niter^n(hbar_i)')
117     plt.xlabel('n')
5f0a35 118     def onclick(event):
SP 119         print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (event.button, event.x, event.y, event.xdata, event.ydata))
120         vtk.Renderer(kwargs.get('args', None),kwargs.get('host',None),run, math.floor(event.xdata))
121     cid = fig.canvas.mpl_connect('button_press_event', onclick)
8c3c29 122     plt.show()
5f0a35 123     plt.close(1)
8c3c29 124 #start manager with configured runs
5f0a35 125 tsmgr.start(Runs, analyses={'analyze1':analyze, 'plotrunningavg':plotrunningavginteractive, 'plothbar':plothbar})
8c3c29 126
SP 127 #statistics.combine(Runs)
128 #statistics.combine([Runs[1],Runs[2]])