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 241 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 245 of file backends.py.

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

Member Function Documentation

◆ __repr__()

__repr__ ( self)
inherited
 

Definition at line 204 of file backends.py.

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

◆ 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 178 of file backends.py.

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

◆ 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 254 of file backends.py.

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

Member Data Documentation

◆ arguments_generator

arguments_generator = arguments_generator
inherited

The ArgumentsGenerator used when creating subjobs.

Definition at line 170 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 252 of file backends.py.


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