Belle II Software development
MaxSubjobsSplitter Class Reference
Inheritance diagram for MaxSubjobsSplitter:
SubjobSplitter

Public Member Functions

 __init__ (self, *, arguments_generator=None, max_subjobs=1000)
 
 create_subjobs (self, job)
 
 assign_arguments (self, job)
 
 __repr__ (self)
 

Public Attributes

 max_subjobs = max_subjobs
 The maximum number of SubJob objects to be created, input files are split evenly between them.
 
 arguments_generator = arguments_generator
 The ArgumentsGenerator used when creating subjobs.
 

Detailed Description

 

Definition at line 243 of file backends.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
* ,
arguments_generator = None,
max_subjobs = 1000 )
Parameters:
    max_subjobs (int): The maximum number ofsubjobs that will be created.

Definition at line 248 of file backends.py.

248 def __init__(self, *, arguments_generator=None, max_subjobs=1000):
249 """
250 Parameters:
251 max_subjobs (int): The maximum number ofsubjobs that will be created.
252 """
253 super().__init__(arguments_generator=arguments_generator)
254
255 self.max_subjobs = max_subjobs
256

Member Function Documentation

◆ __repr__()

__repr__ ( self)
inherited
 

Definition at line 205 of file backends.py.

205 def __repr__(self):
206 """
207 """
208 return f"{self.__class__.__name__}"
209
210

◆ assign_arguments()

assign_arguments ( self,
job )
inherited
Use the `arguments_generator` (if one exists) to assign the argument tuples to the
subjobs.

Definition at line 179 of file backends.py.

179 def assign_arguments(self, job):
180 """
181 Use the `arguments_generator` (if one exists) to assign the argument tuples to the
182 subjobs.
183 """
184 if self.arguments_generator:
185 arg_gen = self.arguments_generator.generator
186 generating = True
187 for subjob in sorted(job.subjobs.values(), key=lambda sj: sj.id):
188 if generating:
189 try:
190 args = arg_gen.send(subjob)
191 except StopIteration:
192 B2ERROR(f"StopIteration called when getting args for {subjob}, "
193 "setting all subsequent subjobs to have empty argument tuples.")
194 args = tuple() # If our generator finishes before the subjobs we use empty argument tuples
195 generating = False
196 else:
197 args = tuple()
198 B2DEBUG(29, f"Arguments for {subjob}: {args}")
199 subjob.args = args
200 return
201
202 B2INFO(f"No ArgumentsGenerator assigned to the {self} so subjobs of {job} "
203 "won't automatically have arguments assigned.")
204

◆ create_subjobs()

create_subjobs ( self,
job )
This function creates subjobs for the parent job passed in. It creates as many subjobs as required
by the number of input files up to the maximum set by `MaxSubjobsSplitter.max_subjobs`. If there are
more input files than `max_subjobs` it instead groups files by the minimum number per subjob in order to
respect the subjob limit e.g. If you have 11 input files and a maximum number of subjobs of 4, then it
will create 4 subjobs, 3 of them with 3 input files, and one with 2 input files.

Reimplemented from SubjobSplitter.

Definition at line 257 of file backends.py.

257 def create_subjobs(self, job):
258 """
259 This function creates subjobs for the parent job passed in. It creates as many subjobs as required
260 by the number of input files up to the maximum set by `MaxSubjobsSplitter.max_subjobs`. If there are
261 more input files than `max_subjobs` it instead groups files by the minimum number per subjob in order to
262 respect the subjob limit e.g. If you have 11 input files and a maximum number of subjobs of 4, then it
263 will create 4 subjobs, 3 of them with 3 input files, and one with 2 input files.
264 """
265 if not job.input_files:
266 B2WARNING(f"Subjob splitting by input files requested, but no input files exist for {job}. No subjobs created.")
267 return
268
269 # Since we will be popping from the left of the input file list, we construct a deque
270 remaining_input_files = deque(job.input_files)
271 # The initial number of available subjobs, will go down as we create them
272 available_subjobs = self.max_subjobs
273 subjob_i = 0
274 while remaining_input_files:
275 # How many files should we use for this subjob?
276 num_input_files = ceil(len(remaining_input_files) / available_subjobs)
277 # Pop them from the remaining files
278 subjob_input_files = []
279 for i in range(num_input_files):
280 subjob_input_files.append(remaining_input_files.popleft())
281 # Create the actual subjob
282 job.create_subjob(subjob_i, input_files=subjob_input_files)
283 subjob_i += 1
284 available_subjobs -= 1
285
286 self.assign_arguments(job)
287 B2INFO(f"{self} created {subjob_i} Subjobs for {job}")
288
289

Member Data Documentation

◆ arguments_generator

arguments_generator = arguments_generator
inherited

The ArgumentsGenerator used when creating subjobs.

Definition at line 171 of file backends.py.

◆ max_subjobs

max_subjobs = max_subjobs

The maximum number of SubJob objects to be created, input files are split evenly between them.

Definition at line 255 of file backends.py.


The documentation for this class was generated from the following file: