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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 304 of file backends.py.

304 def __init__(self, *, arguments_generator=None, max_subjobs=None):
305 """
306 """
307 super().__init__(arguments_generator=arguments_generator)
308
309 self.max_subjobs = max_subjobs
310

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

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

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

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

Definition at line 309 of file backends.py.


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