vA_spline_generator.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 
3 #----------------------------------------------------------------------------------------------------------------
4 # Submit jobs for calculating GENIE x-section splines for all nuclear targets and at the energy range required
5 # for generating the GENIE release validation samples. Note that other scripts are available for generating
6 # x-section splines for the larger array of targets found in detector geometry descriptions of given expts.
7 # If needed, use the GENIE gspladd utility to merge the job outputs.
8 #
9 # Syntax:
10 # shell% perl submit_vA_xsec_calc_jobs.pl <options>
11 #
12 # Options:
13 # --version : GENIE version number
14 # [--config-dir] : Config directory, default is $GENIE/config
15 # [--tune] : tune to be used for genie configuration
16 # [--arch] : <SL4.x86_32, SL5.x86_64, SL6.x86_64, ...>, default: SL6.x86_64
17 # [--production] : default: routine_validation
18 # [--cycle] : default: 01
19 # [--use-valgrind] : default: off
20 # [--batch-system] : <PBS, LyonPBS, LSF, slurm, HTCondor, HTCondor_PBS, none>, default: PBS
21 # [--queue] : default: prod. LyonPBS default: P_gdrnu_genie
22 # [--softw-topdir] : top level dir for softw installations, default: /opt/ppd/t2k/softw/GENIE/
23 # [--jobs-topdir] : top level dir for job files, default: $PWD
24 # [--freenucsplines] : Absolute path to free nucleon splines, default: $softw_topdir/data/job_inputs/xspl/gxspl-vN-$genie_version.xml
25 # [--free-nuc-dir] : Absolute path to free nuclear spline directory
26 # [--gen-list] : comma separated list of event generator list, default all
27 # [--target-list] : comma separated list of targets' PDGs, default De,He4,C12,O16,Ar40,Fe56,Pb207.
28 # Note that it needs the PDG code, not chemical name.
29 # [--nu-list] : comma separeted list of neutrino flavors. Both PDGs or names like vmubar,ve,vtau. Default all
30 # [--e-max] : maxmium energy of the splines in GeV. Default 200 GeV.
31 # [--n-knots] : number of knots per spline. Default 100.
32 # [--with-priority] : (boolean) set a prioirty to optimize bulk productions. Default false
33 # [--run-one] : (boolean) If called, one of the jobs is run as part of the script instead of submitted
34 # via the batch system. Default all the jobs are submitted
35 #
36 #
37 # Author:
38 # Costas Andreopoulos <costas.andreopoulos \st stfc.ac.uk>
39 # University of Liverpool & STFC Rutherford Appleton Laboratory
40 #
41 # Copyright:
42 # Copyright (c) 2003-2020, The GENIE Collaboration
43 # For the full text of the license visit http://copyright.genie-mc.org
44 #----------------------------------------------------------------------------------------------------------------
45 
46 use File::Path;
47 use File::Basename;
48 
49 # inputs
50 #
51 $iarg=0;
52 foreach (@ARGV) {
53  if($_ eq '--version') { $genie_version = $ARGV[$iarg+1]; }
54  if($_ eq '--config-dir') { $config_dir = $ARGV[$iarg+1]; }
55  if($_ eq '--tune') { $tune = $ARGV[$iarg+1]; }
56  if($_ eq '--arch') { $arch = $ARGV[$iarg+1]; }
57  if($_ eq '--production') { $production = $ARGV[$iarg+1]; }
58  if($_ eq '--cycle') { $cycle = $ARGV[$iarg+1]; }
59  if($_ eq '--use-valgrind') { $use_valgrind = $ARGV[$iarg+1]; }
60  if($_ eq '--batch-system') { $batch_system = $ARGV[$iarg+1]; }
61  if($_ eq '--queue') { $queue = $ARGV[$iarg+1]; }
62  if($_ eq '--softw-topdir') { $softw_topdir = $ARGV[$iarg+1]; }
63  if($_ eq '--jobs-topdir') { $jobs_topdir = $ARGV[$iarg+1]; }
64  if($_ eq '--freenucsplines') { $freenucsplines = $ARGV[$iarg+1]; }
65  if($_ eq '--free-nuc-dir' ) { $free_nuc_dir = $ARGV[$iarg+1]; }
66  if($_ eq '--gen-list' ) { $req_gen_list = $ARGV[$iarg+1]; }
67  if($_ eq '--target-list' ) { $target_list = $ARGV[$iarg+1]; }
68  if($_ eq '--nu-list' ) { $req_nu_list = $ARGV[$iarg+1]; }
69  if($_ eq '--e-max' ) { $e_max = $ARGV[$iarg+1]; }
70  if($_ eq '--n-knots' ) { $n_knots = $ARGV[$iarg+1]; }
71  if($_ eq '--with-priority' ) { $priority = 1; }
72  if($_ eq '--run-one' ) { $run_one = 1; }
73  $iarg++;
74 }
75 die("** Aborting [Undefined GENIE version. Use the --version option]")
76 unless defined $genie_version;
77 
78 $config_dir = "" unless defined $config_dir;
79 $use_valgrind = 0 unless defined $use_valgrind;
80 $arch = "SL6.x86_64" unless defined $arch;
81 $production = "routine_validation" unless defined $production;
82 $cycle = "01" unless defined $cycle;
83 $batch_system = "PBS" unless defined $batch_system;
84 $queue_default = "prod";
85 if ( $batch_system eq 'LyonPBS' ) {
86  $queue_default = "P_gdrnu_genie" ;
87 }
88 $queue = $queue_default unless defined $queue;
89 $softw_topdir = "/opt/ppd/t2k/softw/GENIE/" unless defined $softw_topdir;
90 $jobs_topdir = $ENV{'PWD'} unless defined $jobs_topdir;
91 $freenucsplines = "$softw_topdir/data/job_inputs/xspl/gxspl-vN-$genie_version.xml" unless defined $freenucsplines;
92 $priority = 0 unless defined $priority ;
93 $e_max = 200 unless defined $e_max ;
94 $n_knots = 100 unless defined $n_knots ;
95 
96 
97 $genie_setup = "$softw_topdir/generator/builds/$arch/$genie_version-setup";
98 $jobs_dir = "$jobs_topdir/$genie_version-$production\_$cycle-xsec\_vA";
99 
100 %nu_pdg_def = ( 've' => 12,
101  'vebar' => -12,
102  'vmu' => 14,
103  'vmubar' => -14,
104  'vtau' => 16,
105  'vtaubar' => -16 );
106 
107 %nu_name_def = ( 12 => 've' ,
108  -12 => 'vebar' ,
109  14 => 'vmu' ,
110  -14 => 'vmubar' ,
111  16 => 'vtau' ,
112  -16 => 'vtaubar' );
113 
114 ##create the list of neutrino to be produced
115 if ( defined $req_nu_list ) {
116  my @nu_temp_list = split( ",", $req_nu_list );
117  @nu_list = ();
118  foreach my $nu ( @nu_temp_list ) {
119  if ( exists $nu_pdg_def{$nu} ) { push @nu_list, $nu ; }
120  if ( exists $nu_name_def{$nu} ) { push @nu_list, $nu_name_def{$nu} ; }
121  }
122 }
123 else {
124  @nu_list = values %nu_name_def;
125 }
126 print "\n Neutrino List: @nu_list \n";
127 
128 
129 @nuclei_proc = ( 'none',
130  'WeakMEC',
131  'CCCOHPION', 'NCCOHPION',
132  'Fast',
133  'FastWithMEC' ## this is supposed to be better with G16_01 comprehensive models
134  );
135 
136 
137 @nuclei_proc_def = ( 'none',
138  'WeakMEC',
139  'CCCOHPION', 'NCCOHPION',
140  'Fast'
141  );
142 
143 # create the lsit of processes to be generated for composite nuclei
144 if ( defined $req_gen_list ) {
145  my @temp_list = split( ",", $req_gen_list );
146  @nuclei_proc_list = ();
147  foreach my $proc ( @temp_list ) {
148  if ( grep {$_ eq $proc} @nuclei_proc ) { push @nuclei_proc_list, $proc ; }
149  }
150 }
151 else {
152  @nuclei_proc_list = @nuclei_proc_def ;
153 }
154 print "\n List of processes on composite nuclei: @nuclei_proc_list \n";
155 
156 if ( defined $target_list ) {
157 @tgt_pdg = split( ",", $target_list );
158 }
159 else {
160 @tgt_pdg = ( 1000060120, #C12
161  1000080160, #O16
162  1000100200, #Ne20
163  1000130270, #Al27
164  1000140300, #Si30
165  1000180400, #Ar40
166  1000260560, #Fe56
167  1000822070 #Pb207
168  );
169 }
170 print "\n Target List: @tgt_pdg \n";
171 
172 
173 #
174 # make the jobs directory
175 #
176 mkpath ($jobs_dir, {verbose => 1, mode=>0777});
177 
178 @batch_commands = ();
179 @direct_commands = () ;
180 
181 foreach $nu ( @nu_list ) {
182  foreach $tgt ( @tgt_pdg ) {
183  foreach $proc ( @nuclei_proc_list ) {
184 
185  if ( $proc eq "none" ) {
186  next ;
187  }
188 
189  if ( $proc eq 'Fast' ) {
190  $event_gen_list = 'FastOnNuclei' ;
191  }
192  else {
193  $event_gen_list = $proc ;
194  }
195 
196 
197  $jobname = $nu."_on_".$tgt."_$proc";
198  $filename_template = "$jobs_dir/$jobname";
199  $grep_pipe = "grep -B 100 -A 30 -i \"warn\\|error\\|fatal\"";
200  if ( defined $free_nuc_dir ) {
201  $in_splines=$free_nuc_dir."/"."total_xsec.xml";
202  }
203  else {
204  $in_splines = $freenucsplines;
205  }
206  $gmkspl_opt = "-p $nu_pdg_def{$nu} -t $tgt -n $n_knots -e $e_max --input-cross-sections $in_splines --output-cross-sections $filename_template.xml --event-generator-list $event_gen_list --no-copy";
207  $gmkspl_opt .= " --tune $tune " if ( defined $tune ) ;
208  $gmkspl_cmd = "gmkspl $gmkspl_opt ";
209  print "@@ exec: $gmkspl_cmd \n";
210 
211 
212  # create sh file
213  $shell_script = "$filename_template.sh";
214  open(COMMANDS, ">$shell_script") or die("Can not create the bash script");
215  print COMMANDS "#!/bin/bash \n";
216  print COMMANDS "cd $jobs_dir \n";
217  print COMMANDS "source $genie_setup $config_dir \n";
218  print COMMANDS "$gmkspl_cmd \n";
219  close(COMMANDS);
220 
221  # set executing privileges to the script
222  `chmod ugo+x $filename_template.sh` ;
223 
224  #
225  # submit
226  #
227 
228  push( @direct_commands, "bash $shell_script " ) ;
229 
230 
231  # PBS case
232  if($batch_system eq 'PBS' || $batch_system eq 'HTCondor_PBS') {
233  $batch_script = "$filename_template.pbs";
234  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
235  print PBS "#!/bin/bash \n";
236  print PBS "#PBS -N $jobname \n";
237  print PBS "#PBS -o $filename_template.pbsout.log \n";
238  print PBS "#PBS -e $filename_template.pbserr.log \n";
239  print PBS "source $shell_script \n";
240  close(PBS);
241  $job_submission_command = "qsub";
242  if($batch_system eq 'HTCondor_PBS') {
243  $job_submission_command = "condor_qsub";
244  }
245 
246  push( @batch_commands, "$job_submission_command -q $queue $batch_script" ) ;
247 
248  } #PBS
249 
250  # LyonPBS case
251  if($batch_system eq 'LyonPBS' ) {
252  $batch_script = "$filename_template.pbs";
253  open(PBS, ">$batch_script") or die("Can not create the PBS batch script");
254  print PBS "#!/bin/bash \n";
255  print PBS "#\$ -P $queue \n";
256  print PBS "#\$ -N $jobname \n";
257  print PBS "#\$ -o $filename_template.pbsout.log \n";
258  print PBS "#\$ -e $filename_template.pbserr.log \n";
259  print PBS "#\$ -l ct=30:00:00,sps=1,s_rss=4G \n";
260  print PBS "#\$ -p -1 \n" if ( $priority ) ;
261  print PBS "source $shell_script \n";
262  close(PBS);
263  $job_submission_command = "qsub";
264 
265  push( @batch_commands, "$job_submission_command $batch_script " ) ;
266 
267  } #LyonPBS
268 
269  # LSF case
270  if($batch_system eq 'LSF') {
271  $batch_script = "$filename_template.sh";
272  open(LSF, ">$batch_script") or die("Can not create the LSF batch script");
273  print LSF "#!/bin/bash \n";
274  print LSF "#BSUB-j $jobname \n";
275  print LSF "#BSUB-o $filename_template.lsfout.log \n";
276  print LSF "#BSUB-e $filename_template.lsferr.log \n";
277  print LSF "source $shell_script \n";
278  close(LSF);
279 
280  push( @batch_commands, "bsub < $batch_script" ) ;
281  } #LSF
282 
283  # HTCondor
284  if($batch_system eq 'HTCondor') {
285  $batch_script = "$filename_template.htc";
286  open(HTC, ">$batch_script") or die("Can not create the Condor submit description file: $batch_script");
287  print HTC "Universe = vanilla \n";
288  print HTC "Executable = $shell_script \n";
289  print HTC "Log = $filename_template.log \n";
290  print HTC "Output = $filename_template.out \n";
291  print HTC "Error = $filename_template.err \n";
292  print HTC "priority = -1 \n" if ( $priority ) ;
293  print HTC "Request_memory = 4 GB \n";
294  print HTC "requirements = (Opsys =?= \"LINUX\") && (AccessToData =?= True) && (OpSysAndVer =?= \"CentOS7\") \n";
295  print HTC "Queue \n";
296  close(HTC);
297 
298  push( @batch_commands, "condor_submit $batch_script" ) ;
299 
300  } #HTCondor
301 
302  # slurm case
303  if($batch_system eq 'slurm') {
304  $batch_script = "$filename_template.sh";
305  open(SLURM, ">$batch_script") or die("Can not create the SLURM batch script");
306  print SLURM "#!/bin/bash \n";
307  print SLURM "#SBATCH-p $queue \n";
308  print SLURM "#SBATCH-o $filename_template.lsfout.log \n";
309  print SLURM "#SBATCH-e $filename_template.lsferr.log \n";
310  print SLURM "source $shell_script \n";
311  close(SLURM);
312 
313  push( @batch_commands, "sbatch --job-name=$jobname $batch_script" );
314  } #slurm
315 
316  # run interactively
317  }
318  }
319 }
320 
321 
322 if ( $batch_system eq 'none' ) {
323  ## run all of them interactively
324 
325  for my $run_cmd ( @direct_commands ) {
326  print "Executin: $run_cmd \n" ;
327  `$run_cmd` ;
328  }
329 }
330 else {
331  ## submit all except the first
332  foreach my $i ( 1 .. $#batch_commands ) {
333  `$batch_commands[$i]` ;
334  }
335 
336  # handle the first according to script options
337  if ( defined $run_one ) {
338  print "\nExecuting: $direct_commands[0] \n" ;
339  `$direct_commands[0]` ;
340  }
341  else {
342  `$batch_commands[0]` ;
343  }
344 
345 }