submit_systematic_param_scan_1d.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 #-----------------------------------------------------------------------------------------------------------
4 # Script to submit jobs used for evaluating neutrino interaction systematics.
5 #
6 # Syntax:
7 # perl submit_systematic_param_scan_1d.pl <options>
8 #
9 # Options:
10 # --version : GENIE version number.
11 # --input-events : Input event file.
12 # --syst : Systematics for which to submit weight calculation jobs,
13 # eg `--syst MaCCQE', `--syst MaCCQE,MFP_pi', `--syst all' etc.
14 # Alternatively you can use `predefined' lists, eg `--syst standard-t2k-analysis-list'
15 # [--nevents] : Event numbers to process.
16 # To process the first 10000 events, type `--nevents 10000'.
17 # To process the 3000 events between 1000 and 4999, type `--nevents 1000,4999'.
18 # [--output-weights] : Output weight file. Default: weights_<name of systematic>.root
19 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
20 # [--production] : Production name. Default: <version>
21 # [--cycle] : Cycle in current production. Default: 01
22 # [--use-valgrind] : Use Valgrind? Default: off
23 # [--batch-system] : Batch system: <PBS, LSF, slurm, none>. Default: PBS
24 # [--queue] : Batch queue. Default: prod
25 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE/
26 # [--jobs-topdir] : top level dir for job files, default: /opt/ppd/t2k/softw/scratch/GENIE/
27 #
28 # Author:
29 # Costas Andreopoulos <costas.andreopoulos \st stfc.ac.uk>
30 # University of Liverpool & STFC Rutherford Appleton Laboratory
31 #
32 # Copyright:
33 # Copyright (c) 2003-2020, The GENIE Collaboration
34 # For the full text of the license visit http://copyright.genie-mc.org
35 #-----------------------------------------------------------------------------------------------------------
36 #
37 
38 use File::Path;
39 
40 # inputs
41 #
42 $iarg=0;
43 foreach (@ARGV) {
44  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
45  if($_ eq '--syst') { $syst = $ARGV[$iarg+1]; }
46  if($_ eq '--input-events') { $input_events = $ARGV[$iarg+1]; }
47  if($_ eq '--nevents') { $nevents = $ARGV[$iarg+1]; }
48  if($_ eq '--output-weights') { $output_weights = $ARGV[$iarg+1]; }
49  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
50  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
51  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
52  if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
53  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
54  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
55  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
56  if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
57  $iarg++;
58 }
59 die("** Aborting [Undefined GENIE version. Use the --version option]")
60 unless defined $genie_version;
61 die("** Aborting [You need to specify which systematics to study. Use the --syst option]")
62 unless defined $syst;
63 die("** Aborting [You need to specify an input event file. Use the --input-events option]")
64 unless defined $input-events;
65 
66 $use_valgrind = 0 unless defined $use_valgrind;
67 $arch = "SL6.x86_64" unless defined $arch;
68 $production = "$genie_version" unless defined $production;
69 $cycle = "01" unless defined $cycle;
70 $batch_system = "PBS" unless defined $batch_system;
71 $queue = "prod" unless defined $queue;
72 $softw_topdir = "/opt/ppd/t2k/softw/GENIE" unless defined $softw_topdir;
73 $jobs_topdir = "/opt/ppd/t2k/scratch/GENIE/" unless defined $jobs_topdir;
74 $time_limit = "60:00:00";
75 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
76 $jobs_dir = "$jobs_topdir/rwght1scan-$production\_$cycle";
77 $gexec = "grwght1scan";
78 
79 %def_ntwkdials = (
80  'MaNCEL' => '3',
81  'EtaNCEL' => '3',
82  'NormCCQE' => '3',
83  'MaCCQE' => '11',
84  'MaCCQEshape' => '11',
85  'VecFFCCQEshape' => '11',
86  'NormCCRES' => '3',
87  'MaCCRESshape' => '11',
88  'MvCCRESshape' => '11',
89  'MaCCRES' => '11',
90  'MvCCRES' => '11',
91  'NormNCRES' => '3',
92  'MaNCRESshape' => '11',
93  'MvNCRESshape' => '11',
94  'MaNCRES' => '11',
95  'MvNCRES' => '11',
96  'MaCOHpi' => '11',
97  'R0COHpi' => '11',
98  'NonRESBGvpCC1pi' => '3',
99  'NonRESBGvpCC2pi' => '3',
100  'NonRESBGvpNC1pi' => '3',
101  'NonRESBGvpNC2pi' => '3',
102  'NonRESBGvnCC1pi' => '3',
103  'NonRESBGvnCC2pi' => '3',
104  'NonRESBGvnNC1pi' => '3',
105  'NonRESBGvnNC2pi' => '3',
106  'NonRESBGvbarpCC1pi' => '3',
107  'NonRESBGvbarpCC2pi' => '3',
108  'NonRESBGvbarpNC1pi' => '3',
109  'NonRESBGvbarpNC2pi' => '3',
110  'NonRESBGvbarnCC1pi' => '3',
111  'NonRESBGvbarnCC2pi' => '3',
112  'NonRESBGvbarnNC1pi' => '3',
113  'NonRESBGvbarnNC2pi' => '3',
114  'AhtBY' => '11',
115  'BhtBY' => '11',
116  'CV1uBY' => '11',
117  'CV2uBY' => '11',
118  'AhtBYshape' => '11',
119  'BhtBYshape' => '11',
120  'CV1uBYshape' => '11',
121  'CV2uBYshape' => '11',
122  'NormDISCC' => '11',
123  'RnubarnuCC' => '11',
124  'DISNuclMod' => '11',
125  'AGKYxF1pi' => '11',
126  'AGKYpT1pi' => '11',
127  'FormZone' => '11',
128  'MFP_pi' => '11',
129  'MFP_N' => '11',
130  'FrCEx_pi' => '11',
131  'FrElas_pi' => '11',
132  'FrInel_pi' => '11',
133  'FrAbs_pi' => '11',
134  'FrPiProd_pi' => '11',
135  'FrCEx_N' => '11',
136  'FrElas_N' => '11',
137  'FrInel_N' => '11',
138  'FrAbs_N' => '11',
139  'FrPiProd_N' => '11',
140  'CCQEPauliSupViaKF' => '11',
141  'CCQEMomDistroFGtoSF' => '11',
142  'RDecBR1gamma' => '3',
143  'RDecBR1eta' => '3',
144  'Theta_Delta2Npi' => '7'
145 );
146 
147 %used_in_t2k_analysis = (
148  'MaNCEL' => '1',
149  'EtaNCEL' => '1',
150  'NormCCQE' => '0',
151  'MaCCQE' => '1',
152  'MaCCQEshape' => '0',
153  'VecFFCCQEshape' => '1',
154  'NormCCRES' => '0',
155  'MaCCRESshape' => '0',
156  'MvCCRESshape' => '0',
157  'MaCCRES' => '1',
158  'MvCCRES' => '1',
159  'NormNCRES' => '0',
160  'MaNCRESshape' => '0',
161  'MvNCRESshape' => '0',
162  'MaNCRES' => '1',
163  'MvNCRES' => '1',
164  'MaCOHpi' => '1',
165  'R0COHpi' => '1',
166  'NonRESBGvpCC1pi' => '1',
167  'NonRESBGvpCC2pi' => '0',
168  'NonRESBGvpNC1pi' => '1',
169  'NonRESBGvpNC2pi' => '0',
170  'NonRESBGvnCC1pi' => '1',
171  'NonRESBGvnCC2pi' => '0',
172  'NonRESBGvnNC1pi' => '1',
173  'NonRESBGvnNC2pi' => '0',
174  'NonRESBGvbarpCC1pi' => '0',
175  'NonRESBGvbarpCC2pi' => '0',
176  'NonRESBGvbarpNC1pi' => '0',
177  'NonRESBGvbarpNC2pi' => '0',
178  'NonRESBGvbarnCC1pi' => '0',
179  'NonRESBGvbarnCC2pi' => '0',
180  'NonRESBGvbarnNC1pi' => '0',
181  'NonRESBGvbarnNC2pi' => '0',
182  'AhtBY' => '1',
183  'BhtBY' => '1',
184  'CV1uBY' => '1',
185  'CV2uBY' => '1',
186  'AhtBYshape' => '0',
187  'BhtBYshape' => '0',
188  'CV1uBYshape' => '0',
189  'CV2uBYshape' => '0',
190  'NormDISCC' => '0',
191  'RnubarnuCC' => '0',
192  'DISNuclMod' => '0',
193  'AGKYxF1pi' => '1',
194  'AGKYpT1pi' => '1',
195  'FormZone' => '1',
196  'MFP_pi' => '1',
197  'MFP_N' => '1',
198  'FrCEx_pi' => '1',
199  'FrElas_pi' => '1',
200  'FrInel_pi' => '1',
201  'FrAbs_pi' => '1',
202  'FrPiProd_pi' => '1',
203  'FrCEx_N' => '1',
204  'FrElas_N' => '1',
205  'FrInel_N' => '1',
206  'FrAbs_N' => '1',
207  'FrPiProd_N' => '1',
208  'CCQEPauliSupViaKF' => '1',
209  'CCQEMomDistroFGtoSF' => '1',
210  'RDecBR1gamma' => '1',
211  'RDecBR1eta' => '1',
212  'Theta_Delta2Npi' => '1'
213 );
214 
215 # make the jobs directory
216 #
217 mkpath ($jobs_dir, {verbose => 1, mode=>0777});
218 
219 #
220 # submit weight calculation jobs
221 #
222 
223 # systematics loop
224 for my $curr_syst (keys %def_ntwkdials) {
225 
226  # check whether to commit weight calculation run for current systematic
227 # print "checking whether to submit job for systematic: $curr_syst \n";
228 
229  $using_a_std_analysis_syst_list =
230  ($syst eq "standard-t2k-analysis-list");
231  $syst_used_in_given_analysis =
232  ($syst eq "standard-t2k-analysis-list" && $used_in_t2k_analysis{$curr_syst} eq '1');
233 
234  $do_submit =
235  ((($syst=~m/$curr_syst/) || ($syst eq "all")) && ! $using_a_std_analysis_syst_list) ||
236  $syst_used_in_given_analysis;
237 
238  if($do_submit) {
239  print "** submitting weight calculation job \n";
240 
241  $fntemplate = "$jobs_dir/syst-$curr_syst";
242  $grep_pipe = "grep -B 20 -A 30 -i \"warn\\|error\\|fatal\"";
243  $valgrind_cmd = "valgrind --tool=memcheck --error-limit=no --leak-check=yes --show-reachable=yes";
244  $ntwkdials = $def_ntwkdials{$curr_syst};
245  $genie_cmd = "$gexec -f $input_events -s $curr_syst -t $ntwkdials";
246  $genie_cmd = "$genie_cmd -n $nevents" if defined $nevents; # add optional argument
247  $genie_cmd = "$genie_cmd -o $output_weights" if defined $output_weights; # add optional argument
248  $genie_cmd = "$genie_cmd | $grep_pipe &> $fntemplate.log";
249 
250  print "@@ exec: $genie_cmd \n";
251 
252  #
253  # submit
254  #
255 
256  # PBS case
257  if($batch_system eq 'PBS') {
258  $batch_script = "$fntemplate.pbs";
259  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
260  print PBS "#!/bin/bash \n";
261  print PBS "#PBS -N syst-$curr_syst \n";
262  print PBS "#PBS -l cput=$time_limit \n";
263  print PBS "#PBS -o $fntemplate.pbsout.log \n";
264  print PBS "#PBS -e $fntemplate.pbserr.log \n";
265  print PBS "source $genie_setup \n";
266  print PBS "cd $jobs_dir \n";
267  print PBS "$genie_cmd \n";
268  close(PBS);
269  `qsub -q $queue $batch_script`;
270  } #PBS
271 
272  # LSF case
273  if($batch_system eq 'LSF') {
274  $batch_script = "$fntemplate.sh";
275  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
276  print LSF "#!/bin/bash \n";
277  print LSF "#BSUB-j syst-$curr_syst \n";
278  print LSF "#BSUB-q $queue \n";
279  print LSF "#BSUB-c $time_limit \n";
280  print LSF "#BSUB-o $fntemplate.lsfout.log \n";
281  print LSF "#BSUB-e $fntemplate.lsferr.log \n";
282  print LSF "source $genie_setup \n";
283  print LSF "cd $jobs_dir \n";
284  print LSF "$genie_cmd \n";
285  close(LSF);
286  `qsub < $batch_script`;
287  } #LSF
288 
289  # slurm case
290  if($batch_system eq 'slurm') {
291  my $time_lim = `sinfo -h -p batch -o %l`;
292  my ($days, $hours, $remainder) = $time_lim =~ /([0]+)-([0-9]+):(.*)/;
293  my $newhours = $days * 24 + $hours;
294  my $new_time_lim = "$newhours:$remainder";
295  $time_limit = $new_time_lim lt $time_limit ? $new_time_lim : $time_limit;
296  $batch_script = "$fntemplate.sh";
297  open(SLURM, ">$batch_script") or die("Can not create the SLURM batch script");
298  print SLURM "#!/bin/bash \n";
299  print SLURM "#SBATCH-p $queue \n";
300  print SLURM "#SBATCH-o $fntemplate.lsfout.log \n";
301  print SLURM "#SBATCH-e $fntemplate.lsferr.log \n";
302  print SLURM "#SBATCH-t $time_limit \n";
303  print SLURM "source $genie_setup \n";
304  print SLURM "cd $jobs_dir \n";
305  print SLURM "$genie_cmd \n";
306  close(SLURM);
307  `sbatch --job-name=syst-$curr_syst $batch_script`;
308  } #slurm
309 
310  # no batch system, run jobs interactively
311  if($batch_system eq 'none') {
312  system("source $genie_setup; cd $jobs_dir; $genie_cmd");
313  } # interactive mode
314 
315  } #checking whether to submit current systematic
316 } # loop over systematics
317