19 warnings.filterwarnings(
"ignore", message=
'"is" with a literal', category=SyntaxWarning)
22 from Configurables
import CPUCruncher, Gaudi__Sequencer
27 if not os.path.exists(filePath):
28 __fullFilePath__ = os.path.realpath(
30 os.environ.get(
"ENV_PROJECT_SOURCE_DIR",
""),
36 if not os.path.exists(__fullFilePath__):
37 __fullFilePath__ = os.path.realpath(
39 os.environ.get(
"ENV_PROJECT_SOURCE_DIR",
""),
46 if not os.path.exists(__fullFilePath__):
48 "\nERROR: invalid file path '%s'. "
49 "It must be either absolute, or relative to "
50 "'$ENV_PROJECT_SOURCE_DIR/GaudiHive/data/' or to "
51 "'$ENV_PROJECT_SOURCE_DIR/Gaudi/GaudiHive/data/'." % filePath
55 __fullFilePath__ = filePath
57 return __fullFilePath__
61 """A class to manage uniform algorithm timing"""
67 def get(self, algoName=""):
68 """Get time and its variance (in a tuple) for a given algorithm name"""
74 """A class to manage real algorithm timing"""
76 def __init__(self, path, defaultTime, factor=1):
78 defaultTime -- run time, assigned to an algorithm if no time is found in provided timing library
79 (and it will also be scaled by the 'factor' argument)
90 def get(self, algoName=""):
91 """Get time for a given algorithm name"""
94 time = float(self.
timings[algoName])
96 capAlgoName = algoName[0].upper() + algoName[1 : len(algoName)]
99 time = float(self.
timings[capAlgoName])
103 "WARNING: Timing for %s (or %s) not found in the provided library, using default one: %s"
104 % (algoName, capAlgoName, time)
121 """Provides randomly ordered set of boolean values with requested proportion of True and False."""
126 pattern -- either a dictionary describing proportion of True and False (e.g., {True:5,False:15}), or
127 a list/tuple containing a pattern to be used as-is (e.g., [False,True,True,False])
128 seed -- an int, long or other hashable object to initialize random number generator (passed to random.shuffle as-is)
131 if isinstance(pattern, dict):
134 length = proportion[
True] + proportion[
False]
136 raise "ERROR: Wrong set length requested: %i " % length
139 True for i
in range(proportion[
True])
147 elif isinstance(pattern, (list, tuple)):
150 raise "ERROR: unknown pattern type"
166 """Constructs the sequence tree of CPUCrunchers with provided control flow and data flow precedence rules."""
168 unique_sequencers = []
174 unique_data_objects = []
191 timeValue -- timeValue object to set algorithm execution time
192 BlockingBoolValue -- *BooleanValue object to set whether an algorithm has to experience CPU-blocking execution
193 cfgPath -- relative to $ENV_PROJECT_SOURCE_DIR/GaudiHive/data path to GRAPHML file with control flow dependencies
194 dfgPath -- relative to $ENV_PROJECT_SOURCE_DIR/GaudiHive/data path to GRAPHML file with data flow dependencies
195 showStat -- print out statistics on precedence graph
214 print(
"\n===== Statistics on Algorithms =====")
216 "Total number of algorithm nodes: ",
220 print(
"Number of unique algorithms: ", len(self.
unique_algos))
224 "of them being re-used with the following distribution: ",
229 print(
"\n===== Statistics on Sequencers =====")
231 "Total number of sequencers: ",
239 "of them being re-used with the following distribution: ",
245 print(
"\n===== Statistics on DataObjects =====")
254 """Declare data inputs and outputs for a given algorithm."""
257 for inNode, outNode
in self.
dfg.in_edges(algo_name):
262 if dataName
not in algo.inpKeys:
263 algo.inpKeys.append(dataName)
266 for inNode, outNode
in self.
dfg.out_edges(algo_name):
271 if dataName
not in algo.outKeys:
272 algo.outKeys.append(dataName)
275 """Assemble the tree of sequencers."""
278 seq = Gaudi__Sequencer(name, ShortCircuit=
False)
280 for n
in self.
cfg[name]:
282 algo_name = n.split(
"/")[1]
if "/" in n
else n
284 if "type" in self.
cfg.nodes[n]:
286 algo_type = self.
cfg.nodes[n].
get(
"type")
290 algo_type = n.split(
"/")[0]
if "/" in n
else "Algorithm"
292 if algo_type
in [
"GaudiSequencer",
"AthSequencer",
"ProcessPhase"]:
293 if algo_name
in [
"RecoITSeq",
"RecoOTSeq",
"RecoTTSeq"]:
304 seq_daughter = Gaudi__Sequencer(algo_name, OutputLevel=INFO)
305 if self.
cfg.nodes[n].
get(
"ModeOR") ==
"True":
307 seq_daughter.ModeOR =
True
310 seq_daughter.ShortCircuit =
False
311 if seq_daughter
not in seq.Members:
312 seq.Members += [seq_daughter]
328 algo_daughter = CPUCruncher(
332 varRuntime=varRuntime,
333 avgRuntime=avgRuntime,
342 if algo_daughter
not in seq.Members:
343 seq.Members += [algo_daughter]