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

Public Member Functions

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

Public Attributes

 max_subjobs = max_subjobs
 If we try to create more than this many subjobs we throw an exception, if None then there is no maximum.
 
 arguments_generator = arguments_generator
 The ArgumentsGenerator used when creating subjobs.
 

Detailed Description

Creates SubJobs based on the given argument generator. The generator will be called until a `StopIteration` is issued.
Be VERY careful to not accidentally give an infinite generator! Otherwise it will simply create SubJobs until you run out
of memory. You can set the `ArgumentsSplitter.max_subjobs` parameter to try and prevent this and throw an exception.

This splitter is useful for MC production jobs where you don't have any input files, but you want to control the exp/run
numbers of subjobs. If you do have input files set for the parent `Job` objects, then the same input files will be
assigned to every `SubJob`.

Parameters:
    arguments_generator (ArgumentsGenerator): The standard ArgumentsGenerator that is used to assign arguments

Definition at line 287 of file backends.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
* ,
arguments_generator = None,
max_subjobs = None )
 

Definition at line 301 of file backends.py.

301 def __init__(self, *, arguments_generator=None, max_subjobs=None):
302 """
303 """
304 super().__init__(arguments_generator=arguments_generator)
305
306 self.max_subjobs = max_subjobs
307

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 subjobs until the
`SubjobSplitter.arguments_generator` finishes.

If `ArgumentsSplitter.max_subjobs` is set, then it will throw an exception if more than this number of
subjobs are created.

Reimplemented from SubjobSplitter.

Definition at line 308 of file backends.py.

308 def create_subjobs(self, job):
309 """
310 This function creates subjobs for the parent job passed in. It creates subjobs until the
311 `SubjobSplitter.arguments_generator` finishes.
312
313 If `ArgumentsSplitter.max_subjobs` is set, then it will throw an exception if more than this number of
314 subjobs are created.
315 """
316 arg_gen = self.arguments_generator.generator
317 for i in count():
318 # Reached the maximum?
319 if i >= self.max_subjobs:
320 raise SplitterError(f"{self} tried to create more subjobs than the maximum (={self.max_subjobs}).")
321 try:
322 subjob = SubJob(job, i, job.input_files) # We manually create it because we might not need it
323 args = arg_gen.send(subjob) # Might throw StopIteration
324 B2INFO(f"Creating {job}.{subjob}")
325 B2DEBUG(29, f"Arguments for {subjob}: {args}")
326 subjob.args = args
327 job.subjobs[i] = subjob
328 except StopIteration:
329 break
330 B2INFO(f"{self} created {i+1} Subjobs for {job}")
331
332

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

If we try to create more than this many subjobs we throw an exception, if None then there is no maximum.

Definition at line 306 of file backends.py.


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