Belle II Software  release-05-01-25
caf_pbs_backend.py
1 # This steering file shows example setup for
2 # running the CAF using the PBS (qsub) batch system backend with multiple test calibrations.
3 # You will need to have data already from running calibration/examples/1_create_sample_DSTs.sh
4 # or just make your own and change the input data below.
5 
6 # Not all of the configuration is strictly necessary, it's just to show some options
7 
8 import basf2 as b2
9 
10 import os
11 import sys
12 
13 from ROOT.Belle2 import TestCalibrationAlgorithm
14 from caf.framework import Calibration, CAF
15 from caf import backends
16 
17 b2.set_log_level(b2.LogLevel.INFO)
18 
19 
20 def main(argv):
21  if len(argv) == 1:
22  data_dir = argv[0]
23  else:
24  print("Usage: python3 caf_pbs_backend.py <data directory>")
25  sys.exit(1)
26 
27 
31  input_files_test = [os.path.join(os.path.abspath(data_dir), '*.root')]
32 
33  from caf.strategies import SequentialRunByRun
34 
37  calibrations = []
38  for i in range(1, 3):
39  col_test = b2.register_module('CaTest')
40  col_test.set_name('Test{}'.format(i)) # Sets the prefix of the collected data in the datastore
41  col_test.param('spread', 15) # Proportional to the probability of algorithm requesting iteration
42  col_test.param('granularity', 'run') # Allows us to execute algorithm over all data, in one big IoV
43 
44  alg_test = TestCalibrationAlgorithm()
45  # Since we're using several instances of the same test algorithm here, we still want the database entries to have
46  # different names. TestCalibrationAlgorithm outputs to the database using the prefix name so we change it
47  # slightly for each calibration. Not something you'd usually have to do.
48  alg_test.setPrefix('Test{}'.format(i)) # Must be the same as colllector prefix
49 
50  cal_test = Calibration(name='TestCalibration{}'.format(i),
51  collector=col_test,
52  algorithms=alg_test,
53  input_files=input_files_test)
54 
55  # Some optional configuration ####
56  # By default all input files are placed in one big job (-1), this allows you to specify a maxmimum so that
57  # subjobs for each set of input files will be created
58  cal_test.max_files_per_collector_job = 1
59  # Some backends can have arguments passed to them e.g. queue type
60  cal_test.backend_args = {"queue": "short"}
61  # The maximium iteration number you will be allowed to reach before the Calibration just completes
62  cal_test.max_iterations = 2
63  # Since we're using the PBS batch system we'll up the heartbeat from the default to query for when the jobs are all
64  # finished. No point spamming it
65  cal_test.heartbeat = 15
66  # The interval in seconds between full updates of the remaining collector jobs, default = 300
67  # Checking every subjob can be a long process when you have a lot of them so it's best not to do it too often
68  # After this interval the finished/remaining collector jobs will be printed
69  cal_test.collector_full_update_interval = 60
70  # Choosing an AlgorithmStrategy for each algorithm (here we just use the same for all of them)
71  cal_test.strategies = SequentialRunByRun
72  # The collector output file patterns you want to make sure are tracked by the CAF. By default only CollectorOutput.root
73  # is used. All files are passed to the Algorithm.data_input function in order to set the input files of the algorithm
74  cal_test.output_patterns.append("*.mille")
75 
76  calibrations.append(cal_test)
77 
78 
80  cal_fw = CAF()
81  # Add in our list of calibrations
82  for cal in calibrations:
83  cal_fw.add_calibration(cal)
84  # Use the default PBS backend setup, can view the default options in calibration/data/backends.cfg
85  cal_fw.backend = backends.PBS()
86  # Start running
87  cal_fw.run()
88  print("End of CAF processing.")
89 
90 
91 if __name__ == "__main__":
92  main(sys.argv[1:])
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Calibration
Definition: Calibration.py:1
backends.PBS
Definition: backends.py:1304