submit_hadronization_validation_mc_jobs.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 #---------------------------------------------------------------------------------------------------------------------
4 # Submit jobs to generate all data needed for validating GENIE's hadronization model.
5 # The generated data can be fed into the GENIE/Comparisons `gvld_hadronization' app.
6 #
7 # Syntax:
8 # perl submit_hadronization_validation_mc_jobs.pl <options>
9 #
10 # Options:
11 # --version : GENIE version number
12 # [--config-dir] : Config directory, default is $GENIE/config
13 # [--nsubruns] : number of subruns per run, default: 1
14 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
15 # [--production] : production name, default: routine_validation
16 # [--cycle] : cycle in current production, default: 01
17 # [--use-valgrind] : default: off
18 # [--batch-system] : <PBS, LyonPBS, LSF, slurm, HTCondor, HTCondor_PBS, none>, default: PBS
19 # [--queue] : default: prod. LyonPBS default: P_gdrnu_genie
20 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE/
21 # [--jobs-topdir] : top level dir for job files, default: /opt/ppd/t2k/softw/scratch/GENIE/
22 # [--spline-file] : absoluyte path to xsec_spline_file, default: $softw_topdir/data/job_inputs/xspl/gxspl-vA-$genie_version.xml
23 #
24 #
25 # EVENT SAMPLES:
26 #...................................................................................
27 # run number | init state | energy | event generator | flux
28 # | | (GeV) | list |
29 #...................................................................................
30 #
31 # 1000xx | numu + n | 0.5-80. | HadronizationTest | 1/E
32 # 1100xx | numu + p | 0.5-80. | HadronizationTest | 1/E
33 # 1200xx | numubar + n | 0.5-80. | HadronizationTest | 1/E
34 # 1300xx | numubar + p | 0.5-80. | HadronizationTest | 1/E
35 #
36 # xx : Run ID, 01-99, 100k events each
37 #
38 #
39 # Author:
40 # Costas Andreopoulos <costas.andreopoulos \st stfc.ac.uk>
41 # University of Liverpool & STFC Rutherford Appleton Laboratory
42 #
43 # Copyright:
44 # Copyright (c) 2003-2020, The GENIE Collaboration
45 # For the full text of the license visit http://copyright.genie-mc.org
46 #---------------------------------------------------------------------------------------------------------------------
47 
48 use File::Path;
49 
50 # inputs
51 #
52 $iarg=0;
53 foreach (@ARGV) {
54  if($_ eq '--nsubruns') { $nsubruns = $ARGV[$iarg+1]; }
55  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
56  if($_ eq '--config-dir') { $config_dir = $ARGV[$iarg+1]; }
57  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
58  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
59  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
60  if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
61  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
62  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
63  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
64  if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
65  if($_ eq '--spline-file') { $xspl_file = $ARGV[$iarg+1]; }
66  $iarg++;
67 }
68 die("** Aborting [Undefined GENIE version. Use the --version option]")
69 unless defined $genie_version;
70 
71 $config_dir = "" unless defined $config_dir;
72 $nsubruns = 1 unless defined $nsubruns;
73 $use_valgrind = 0 unless defined $use_valgrind;
74 $arch = "SL6.x86_64" unless defined $arch;
75 $production = "routine_validation" unless defined $production;
76 $cycle = "01" unless defined $cycle;
77 $batch_system = "PBS" unless defined $batch_system;
78 $queue_default = "prod" ;
79 if ( $batch_system eq 'LyonPBS' ) {
80  $queue_default = "P_gdrnu_genie" ;
81 }
82 $queue = $queue_default unless defined $queue;
83 $softw_topdir = "/opt/ppd/t2k/softw/GENIE/" unless defined $softw_topdir;
84 $jobs_topdir = "/opt/ppd/t2k/scratch/GENIE/" unless defined $jobs_topdir;
85 $xspl_file = "$softw_topdir/data/job_inputs/xspl/gxspl-vA-$genie_version.xml" unless defined $xspl_file ;
86 $time_limit = "60:00:00";
87 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
88 $jobs_dir = "$jobs_topdir/$genie_version-$production\_$cycle-hadronization";
89 $mcseed = 210921029;
90 $nev_per_subrun = 100000;
91 
92 # inputs for event generation jobs
93 %evg_nupdg_hash = (
94  '1000' => '14',
95  '1100' => '14',
96  '1200' => '-14',
97  '1300' => '-14'
98 );
99 %evg_tgtpdg_hash = (
100  '1000' => '1000000010',
101  '1100' => '1000010010',
102  '1200' => '1000000010',
103  '1300' => '1000010010'
104 );
105 %evg_energy_hash = (
106  '1000' => '0.5,80.0',
107  '1100' => '0.5,80.0',
108  '1200' => '0.5,80.0',
109  '1300' => '0.5,80.0',
110 );
111 %evg_gevgl_hash = (
112  '1000' => 'HadronizationTest',
113  '1100' => 'HadronizationTest',
114  '1200' => 'HadronizationTest',
115  '1300' => 'HadronizationTest',
116 );
117 %evg_fluxopt_hash = (
118  '1000' => '-f \'1/x\'',
119  '1100' => '-f \'1/x\'',
120  '1200' => '-f \'1/x\'',
121  '1300' => '-f \'1/x\'',
122 );
123 
124 # make the jobs directory
125 #
126 mkpath ($jobs_dir, {verbose => 1, mode=>0777});
127 
128 # submit event generation jobs
129 #
130 for my $curr_runnu (keys %evg_gevgl_hash) {
131 
132  # uncomment if you want to include a cmd line input to specify specific runs (and fill-in $runnu)
133  # if($runnu=~m/$curr_runnu/ || $runnu eq "all") {
134 
135  print "** submitting event generation run: $curr_runnu \n";
136 
137  #
138  # get runnu-dependent info
139  #
140  $nu = $evg_nupdg_hash {$curr_runnu};
141  $tgt = $evg_tgtpdg_hash {$curr_runnu};
142  $en = $evg_energy_hash {$curr_runnu};
143  $gevgl = $evg_gevgl_hash {$curr_runnu};
144  $fluxopt = $evg_fluxopt_hash {$curr_runnu};
145 
146  # submit subruns
147  for($isubrun = 0; $isubrun < $nsubruns; $isubrun++) {
148 
149  $curr_subrunnu = 100 * $curr_runnu + $isubrun;
150  $curr_seed = $mcseed + $isubrun;
151  $jobname = "hadro-$curr_subrunnu";
152  $filename_template = "$jobs_dir/$jobname";
153 # $grep_pipe = "grep -B 20 -A 30 -i \"warn\\|error\\|fatal\"";
154  $grep_pipe = "grep -B 20 -A 30 -i fatal";
155  $valgrind_cmd = "valgrind --tool=memcheck --error-limit=no --leak-check=yes --show-reachable=yes";
156  $evgen_opt = "-n $nev_per_subrun -e $en -p $nu -t $tgt $fluxopt -r $curr_subrunnu --seed $curr_seed --cross-sections $xspl_file --event-generator-list $gevgl";
157  $evgen_cmd = "gevgen $evgen_opt | $grep_pipe &> $filename_template.evgen.log";
158 
159  print "@@ exec: $evgen_cmd \n";
160 
161  #
162  # submit
163  #
164 
165  # PBS case
166  if($batch_system eq 'PBS' || $batch_system eq 'HTCondor_PBS') {
167  $batch_script = "$filename_template.pbs";
168  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
169  print PBS "#!/bin/bash \n";
170  print PBS "#PBS -N $jobname \n";
171  print PBS "#PBS -l cput=$time_limit \n";
172  print PBS "#PBS -o $filename_template.pbsout.log \n";
173  print PBS "#PBS -e $filename_template.pbserr.log \n";
174  print PBS "source $genie_setup $config_dir \n";
175  print PBS "cd $jobs_dir \n";
176  print PBS "$evgen_cmd \n";
177  close(PBS);
178  $job_submission_command = "qsub";
179  if($batch_system eq 'HTCondor_PBS') {
180  $job_submission_command = "condor_qsub";
181  }
182  `$job_submission_command -q $queue $batch_script`;
183  }#PBS
184 
185  # LyonPBS case
186  if($batch_system eq 'LyonPBS' ) {
187  $batch_script = "$filename_template.pbs";
188  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
189  print PBS "#!/bin/bash \n";
190  print PBS "#\$ -P $queue \n";
191  print PBS "#\$ -N $jobname \n";
192  print PBS "#\$ -o $filename_template.pbsout.log \n";
193  print PBS "#\$ -e $filename_template.pbserr.log \n";
194  print PBS "#\$ -l ct=6:00:00,sps=1 \n";
195  print PBS "source $genie_setup $config_dir \n";
196  print PBS "cd $jobs_dir \n";
197  print PBS "$evgen_cmd \n";
198  close(PBS);
199  $job_submission_command = "qsub";
200  `$job_submission_command $batch_script`;
201  } #LyonPBS
202 
203  # LSF case
204  if($batch_system eq 'LSF') {
205  $batch_script = "$filename_template.sh";
206  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
207  print LSF "#!/bin/bash \n";
208  print PBS "#BSUB-j $jobname \n";
209  print LSF "#BSUB-q $queue \n";
210  print LSF "#BSUB-c $time_limit \n";
211  print LSF "#BSUB-o $filename_template.lsfout.log \n";
212  print LSF "#BSUB-e $filename_template.lsferr.log \n";
213  print LSF "source $genie_setup $config_dir\n";
214  print LSF "cd $jobs_dir \n";
215  print LSF "$evgen_cmd \n";
216  close(LSF);
217  `bsub < $batch_script`;
218  }#LSF
219 
220  # HTCondor
221  if($batch_system eq 'HTCondor') {
222  $batch_script = "$filename_template.htc";
223  open(HTC, ">$batch_script") or die("Can not create the Condor submit description file: $batch_script");
224  print HTC "Universe = vanilla \n";
225  print HTC "Executable = $softw_topdir/generator/builds/$arch/$genie_version/src/scripts/production/batch/htcondor_exec.sh \n";
226  print HTC "Arguments = $genie_setup $jobs_dir $evgen_cmd \n";
227  print HTC "Log = $filename_template.log \n";
228  print HTC "Output = $filename_template.out \n";
229  print HTC "Error = $filename_template.err \n";
230  print HTC "Request_memory = 2 GB \n";
231  print HTC "Queue \n";
232  close(HTC);
233  `condor_submit $batch_script`;
234  } #HTCondor
235 
236  # slurm case
237  if($batch_system eq 'slurm') {
238  $batch_script = "$filename_template.sh";
239  open(SLURM, ">$batch_script") or die("Can not create the SLURM batch script");
240  print SLURM "#!/bin/bash \n";
241  print SLURM "#SBATCH-p $queue \n";
242  print SLURM "#SBATCH-o $filename_template.lsfout.log \n";
243  print SLURM "#SBATCH-e $filename_template.lsferr.log \n";
244  print SLURM "source $genie_setup $config_dir\n";
245  print SLURM "cd $jobs_dir \n";
246  print SLURM "$evgen_cmd \n";
247  close(SLURM);
248  `sbatch --job-name=$jobname $batch_script`;
249  }#slurm
250 
251  } # loop over subruns
252  # } #checking whether to submit current run
253 } # loop over runs
254