LALInference  4.1.6.1-c9a8ef6
lalinference_review_test.py
Go to the documentation of this file.
1 import argparse
2 import shutil
3 import os
4 import sys
5 import subprocess
6 import glob
7 import lalinference
8 
9 from configparser import ConfigParser
10 
11 prefix=''
12 try:
13  prefix=os.environ['LALINFERENCE_DATADIR']
14 except KeyError:
15  prefix=''
16 
17 parser = argparse.ArgumentParser(description="Runs review tests of lalinference using lalinference_pipe_example.ini.")
18 
19 parser.add_argument('-i','--ini_file', type=str, nargs='?',
20  default=os.path.join(prefix,'lalinference_pipe_example.ini'),
21  help='lalinference_pipe ini file to process.')
22 
23 parser.add_argument('--bns-injection', type=str, nargs='?',
24  default=False,
25  const=os.path.join(prefix,'fiducialBNS.xml'),
26  help='injection file for fiducial BNS analysis.')
27 
28 parser.add_argument('--gracedb', action='store_true',
29  default=False,
30  help='Runs the analysis for the GraceDB test event T169545.')
31 
32 parser.add_argument('--analytic-tests', action='store_true',
33  default=False,
34  help='Run on the unmodal and bimodial Gaussian and Rosenbrock test functions.')
35 
36 parser.add_argument('--analytic-csv-dir', type=str,
37  default=prefix,
38  help='Directory containing the CSVs describing the analytic tests.')
39 
40 parser.add_argument('--pptest', action='store_true',
41  default=False,
42  help='Runs a P-P analysis. Must specify a single engine.')
43 
44 parser.add_argument('--pp-approximant', action='store', type=str,
45  default='IMRPhenomPv2pseudoFourPN,SEOBNRv4_ROMpseudoFourPN',
46  help='Approximant(s) used for the P-P analysis.')
47 
48 parser.add_argument('--bbh-injection', type=str, nargs='?',
49  default=False,
50  const=os.path.join(prefix,'fiducialBBH.xml'),
51  help='injection file for fiducial BBH analysis.')
52 
53 parser.add_argument('-e','--engine', type=str, nargs='?',
54  default='lalinferencemcmc,lalinferencenest',
55  help='lalinference engine to run with.')
56 
57 parser.add_argument('-o','--output', type=str, nargs='?',
58  default=None,
59  help='output directory.')
60 
61 parser.add_argument('--condor-submit', action='store_true',
62  default=False,
63  help='submits the test suite.')
64 
65 args = parser.parse_args()
66 
67 args.ini_file = os.path.abspath(args.ini_file)
68 
69 if 'UNCLEAN' in lalinference.InferenceVCSInfo.vcsId:
70  default_outputdir=os.getenv('HOME')+'/lalinference_testrun/'+lalinference.InferenceVCSInfo.vcsId+'_UNCLEAN/'+args.engine+'/'
71 else:
72  default_outputdir=os.getenv('HOME')+'/lalinference_testrun/'+lalinference.InferenceVCSInfo.vcsId+'/'+args.engine.replace(',','_')+'/'
73 
74 if args.output == None:
75  web_outputdir=default_outputdir
76  args.output=os.path.abspath(default_outputdir)
77 else:
78  web_outputdir=os.path.abspath(args.output)
79  args.output=os.path.abspath(args.output)
80 
81 os.makedirs(args.output)
82 
83 if args.bns_injection:
84  args.bns_injection=os.path.abspath(args.bns_injection)
85 if args.bbh_injection:
86  args.bbh_injection=os.path.abspath(args.bbh_injection)
87 
88 analytic_csv_dir = os.path.abspath(args.analytic_csv_dir)
89 if args.analytic_tests:
90  csvs = glob.glob(analytic_csv_dir+"/*csv")
91  for csv in csvs:
92  shutil.copy(csv,args.output+'/'+os.path.basename(csv))
93 
94 os.chdir(args.output)
95 
96 lalinf_prefix=''
97 try:
98  lalinf_prefix=os.environ['LALINFERENCE_PREFIX']
99 except KeyError:
100  print('LALINFERENCE_PREFIX variable not defined, could not find LALInference installation.')
101  sys.exit()
102 
103 def init_ini_file(file=args.ini_file):
104  cp=ConfigParser()
105  fp=open(file)
106  cp.optionxform = str
107  try:
108  cp.read_file(fp)
109  except AttributeError:
110  cp.readfp(fp)
111  fp.close()
112 
113  cp.set('condor','lalsuite-install',lalinf_prefix)
114  cp.set('analysis','engine',args.engine)
115  cp.remove_option('analysis','nparallel')
116 
117  return cp
118 
119 ############################################################
120 
122 
123  cp.set('lalinference','fake-cache',"{'H1':'LALSimAdLIGO','L1':'LALSimAdLIGO','V1':'LALSimAdVirgo'}")
124  cp.set('analysis','dataseed','1234')
125  cp.set('engine','0noise','')
126 
127  cp.set('paths','webdir',web_outputdir+'/fiducialBNS/webdir/')
128  cp.set('lalinference','flow',"{'H1':40,'L1':40,'V1':40}")
129  cp.set('engine','approx','SEOBNRv4_ROMpseudoFourPN')
130  cp.set('resultspage','deltaLogP','5')
131  cp.set('engine','comp-max','3.5')
132  cp.set('engine','comp-min','0.5')
133  cp.remove_option('engine','disable-spin')
134  cp.set('engine','a_spin1-max','0.1')
135  cp.set('engine','a_spin1-min','-0.1')
136  cp.set('engine','a_spin2-max','0.1')
137  cp.set('engine','a_spin2-min','-0.1')
138  cp.set('engine','alignedspin-zprior','')
139  cp.set('engine','distance-max','500')
140  cp.set('engine','neff','500')
141  cp.set('engine','nlive','512')
142 
143  return cp
144 
145 if args.bns_injection:
146 
147  os.makedirs(args.output+'/fiducialBNS/')
148  os.chdir(args.output+'/fiducialBNS/')
149 
150  shutil.copy(args.bns_injection,args.output+'/fiducialBNS/')
151  BNS_ini_file=os.path.join(args.output,'fiducialBNS','BNS.ini')
152 
154  with open(BNS_ini_file,'w') as cpfile:
155  cpBNS.write(cpfile)
156 
157  lalinferenceargs = [ 'lalinference_pipe'
158  , '-I'
159  , args.bns_injection
160  , '-r'
161  , './run'
162  , '-p'
163  , './daglog'
164  , BNS_ini_file ]
165 
166  if args.condor_submit:
167  lalinferenceargs.append('--condor-submit')
168 
169  subprocess.call(lalinferenceargs)
170 
171 ###################################################
172 
173 def set_GraceDB(cp):
174 
175  cp.set('analysis','upload-to-gracedb','True')
176  cp.set('paths','webdir',web_outputdir+'/GraceDB/webdir/')
177 
178  cp.set('datafind','types',"{'H1':'H1_HOFT_C00','L1':'L1_HOFT_C00','V1':'V1Online'}")
179  cp.set('data','channels',"{'H1':'H1:GDS-CALIB_STRAIN','L1':'L1:GDS-CALIB_STRAIN','V1':'V1:FAKE_h_16384Hz_4R'}")
180 
181  cp.set('engine','distance-max','300')
182 
183  return cp
184 
185 if args.gracedb:
186 
187  os.makedirs(args.output+'/GraceDB/')
188  os.chdir(args.output+'/GraceDB/')
189 
190  GDB_ini_file=os.path.join(args.output,'GraceDB','GDB.ini')
191 
193  with open(GDB_ini_file,'w') as cpfile:
194  cpGDB.write(cpfile)
195 
196  lalinferenceargs = [ 'lalinference_pipe'
197  , '--gid'
198  , 'T169545'
199  , '-r'
200  , './run'
201  , '-p'
202  , './daglog'
203  , GDB_ini_file ]
204 
205  if args.condor_submit:
206  lalinferenceargs.append('--condor-submit')
207 
208  subprocess.call(lalinferenceargs)
209 
210 ############################################################
211 
213 
214  cp.set('lalinference','fake-cache',"{'H1':'LALSimAdLIGO','L1':'LALSimAdLIGO','V1':'LALSimAdVirgo'}")
215  cp.set('analysis','dataseed','1234')
216  cp.set('engine','0noise','')
217  cp.remove_option('engine','margphi')
218 
219  cp.set('paths','webdir',web_outputdir+'/fiducialBBH/webdir/')
220  #cp.set('lalinference','flow',"{'H1':40,'L1':40,'V1':40}")
221  cp.set('engine','approx','IMRPhenomPv2pseudoFourPN')
222  cp.set('analysis','roq','True')
223  cp.remove_option('engine','disable-spin')
224  cp.set('resultspage','deltaLogP','6')
225  cp.set('engine','distance-max','1000')
226  cp.set('engine','inj-fref','100')
227 
228  cp.set('engine','neff','500')
229  cp.set('engine','nlive','512')
230 
231  return cp
232 
233 if args.bbh_injection:
234 
235  os.makedirs(args.output+'/fiducialBBH/')
236  os.chdir(args.output+'/fiducialBBH/')
237 
238  shutil.copy(args.bbh_injection,args.output+'/fiducialBBH/')
239  BBH_ini_file=os.path.join(args.output,'fiducialBBH','BBH.ini')
240 
242  with open(BBH_ini_file,'w') as cpfile:
243  cpBBH.write(cpfile)
244 
245  lalinferenceargs = [ 'lalinference_pipe'
246  , '-I'
247  , args.bbh_injection
248  , '-r'
249  , './run'
250  , '-p'
251  , './daglog'
252  , BBH_ini_file ]
253 
254  if args.condor_submit:
255  lalinferenceargs.append('--condor-submit')
256 
257  subprocess.call(lalinferenceargs)
258 
259 ############################################################
260 def set_analytic_test(cp, test_func):
261 
262  cp.set('paths','webdir',web_outputdir+'/'+test_func+'/webdir/')
263  cp.set('lalinference','fake-cache',"{'H1':'LALSimAdLIGO','L1':'LALSimAdLIGO','V1':'LALSimAdVirgo'}")
264  cp.set('analysis','dataseed','1234')
265 
266  cp.set('input','analyse-all-time','True')
267  cp.set('input','gps-start-time','0')
268  cp.set('input','gps-end-time','2')
269  cp.set('input','segment-overlap','0')
270  cp.set('input','psd-length','1')
271 
272  cp.set('engine','seglen','1')
273  cp.set('engine','approx','SpinTaylorT4')
274  cp.set('engine',test_func,'')
275  cp.set('engine','neff','10000')
276  cp.set('engine','nlive','2048')
277 
278  cp.set('resultspage','deltaLogP','7')
279  if test_func != "rosenbrockLikelihood":
280  csv = args.output+'/'+test_func+'_means.csv'
281  if os.path.isfile(csv):
282  cp.set('resultspage','meanVectors',csv)
283  csv = args.output+'/'+'test_correlation_matrix.csv'
284  if os.path.isfile(csv):
285  cp.set('resultspage','covarianceMatrix',csv)
286 
287  return cp
288 
289 if args.analytic_tests:
290  test_funcs = ['correlatedGaussianLikelihood', 'bimodalGaussianLikelihood', 'rosenbrockLikelihood']
291  for test_func in test_funcs:
292  os.makedirs(args.output+'/' + test_func + '/')
293  os.chdir(args.output+'/' + test_func + '/')
294 
295 
296  analytic_ini_file=os.path.join(args.output,test_func,'analytic.ini')
297 
298  cpanalytic=set_analytic_test(init_ini_file(), test_func)
299  with open(analytic_ini_file,'w') as cpfile:
300  cpanalytic.write(cpfile)
301 
302  lalinferenceargs = [ 'lalinference_pipe'
303  , '-r'
304  , './run'
305  , '-p'
306  , './daglog'
307  , analytic_ini_file ]
308 
309  if args.condor_submit:
310  lalinferenceargs.append('--condor-submit')
311 
312  subprocess.call(lalinferenceargs)
313 
314 ############################################################
315 
316 def set_pptest(cp, engine, approximant):
317 
318  cp.set('paths','webdir', os.path.join(web_outputdir, 'pptest', engine, approximant, 'webdir/'))
319  cp.set('ppanalysis','webdir', os.path.join(web_outputdir, 'PPcheck', engine, approximant + '/'))
320  cp.set('lalinference','fake-cache',"{'H1':'LALSimAdLIGO','L1':'LALSimAdLIGO','V1':'LALSimAdVirgo'}")
321  cp.set('analysis','dataseed','1234')
322  cp.set('analysis', 'engine', engine)
323 
324  cp.remove_option('engine','margphi')
325  cp.set('engine','margtime','')
326  cp.set('engine','amporder','-1')
327  cp.set('engine','fref','0')
328  cp.set('engine','distance-max','2000')
329  cp.set('engine', 'approx', approximant)
330 
331  cp.set('resultspage','deltaLogP','7')
332 
333  return cp
334 
335 if args.pptest:
336 
337  # The PP test needs a single engine to be specified
338  for engine in args.engine.split(','):
339  for approximant in args.pp_approximant.split(','):
340  os.makedirs(os.path.join(args.output, 'pptest', engine, approximant + '/'))
341  os.chdir(os.path.join(args.output, 'pptest', engine, approximant + '/'))
342 
343  pptest_ini_file=os.path.join(args.output, 'pptest', engine, approximant, 'pptest.ini')
344 
345  cppptest=set_pptest(init_ini_file(), engine=engine,
346  approximant=approximant)
347  with open(pptest_ini_file,'w') as cpfile:
348  cppptest.write(cpfile)
349 
350  lalinferenceargs = [ 'lalinference_pp_pipe'
351  , '-r'
352  , './run'
353  , '-N'
354  , '100'
355  , pptest_ini_file ]
356 
357  subprocess.call(lalinferenceargs)
358 
359  if args.condor_submit:
360  condor_submit_dag = ['condor_submit_dag', os.path.join(args.output, 'pptest', engine, approximant, 'run/priortest.dag')]
361  subprocess.call(condor_submit_dag)
362 
def set_pptest(cp, engine, approximant)
def init_ini_file(file=args.ini_file)