Python wrapper for running instances of trisurf-ng
Samo Penic
2017-01-14 f49271578b8fac02db14966e7aab121879f9b736
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
101 def plotrunningavg(run, **kwargs):
102     import matplotlib.pyplot as plt
103     table=trisurf.Statistics(run.Dir.fullpath(),filename='data_tspoststat.csv').getTable()
104     def running_avg(col):
105         import numpy as np
106         avg=[]    
107         for i in range(0,len(col)):
108             avg.append(np.average(col[:-i]))
109         return avg
110     ra=running_avg(table['hbar'])
111     plt.plot(ra)
112     plt.title('Running average')
113     plt.ylabel('1/n sum_i=niter^n(hbar_i)')
114     plt.xlabel('n')
115     plt.show()
116
117 #start manager with configured runs
118 tsmgr.start(Runs, analyses={'analyze1':analyze, 'plotrunningavg':plotrunningavg, 'plothbar':plothbar})
119
120 #statistics.combine(Runs)
121 #statistics.combine([Runs[1],Runs[2]])