本文整理汇总了Python中networkx.DiGraph.node[job_id]['CP']方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.node[job_id]['CP']方法的具体用法?Python DiGraph.node[job_id]['CP']怎么用?Python DiGraph.node[job_id]['CP']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.node[job_id]['CP']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gantt
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import node[job_id]['CP'] [as 别名]
def gantt(job_list, context, filename='gantt.html'):
"""
"""
db = context.get_compmake_db()
if not job_list:
# job_list = list(top_targets(db))
job_list = all_jobs(db)
# plus all the jobs that were defined by them
job_list = set(job_list)
# job_list.update(definition_closure(job_list, db))
from networkx import DiGraph
G = DiGraph()
cq = CacheQueryDB(db)
for job_id in job_list:
cache = cq.get_job_cache(job_id)
length = cache.int_make.get_cputime_used()
attr_dict = dict(cache=cache, length=length)
G.add_node(job_id, **attr_dict)
dependencies = cq.direct_children(job_id)
for c in dependencies:
G.add_edge(c, job_id)
defined = cq.jobs_defined(job_id)
for c in defined:
G.add_edge(job_id, c)
order = topological_sort(G)
for job_id in order:
length = G.node[job_id]['length']
pre = list(G.predecessors(job_id))
# print('%s pred %s' % (job_id, pre))
if not pre:
T0 = 0
G.node[job_id]['CP'] = None
else:
# find predecessor with highest T1
import numpy as np
T1s = list(G.node[_]['T1'] for _ in pre)
i = np.argmax(T1s)
T0 = T1s[i]
G.node[job_id]['CP'] = pre[i]
T1 = T0 + length
G.node[job_id]['T0'] = T0
G.node[job_id]['T1'] = T1
G.node[job_id]['critical'] = False
sg_ideal = SimpleGantt()
by_ideal_completion = sorted(order, key=lambda _: G.node[_]['T1'])
last = by_ideal_completion[-1]
path = []
while last is not None:
path.append(last)
G.node[last]['critical'] = True
last = G.node[last]['CP']
print('Critical path:')
for job_id in reversed(path):
length = G.node[job_id]['length']
print('- %.1f s %s' % (length, job_id))
for job_id in by_ideal_completion:
T0 = G.node[job_id]['T0']
T1 = G.node[job_id]['T1']
# length = G.node[job_id]['length']
dependencies = list(G.predecessors(job_id))
# cache = G.node[job_id]['cache']
periods = OrderedDict()
periods['ideal'] = (T0, T1)
critical = G.node[job_id]['critical']
sg_ideal.add_job(job_id, dependencies, periods=periods, critical=critical)
sg_actual = SimpleGantt()
order_actual = sorted(order, key=lambda _: G.node[_]['cache'].int_make.t0)
for job_id in order_actual:
cache = G.node[job_id]['cache']
critical = G.node[job_id]['critical']
dependencies = list(G.predecessors(job_id))
periods = OrderedDict()
periods['make'] = cache.int_make.walltime_interval()
sg_actual.add_job(job_id, dependencies, periods=periods, critical=critical)
sg_actual_detailed = SimpleGantt()
for job_id in order_actual:
cache = G.node[job_id]['cache']
critical = G.node[job_id]['critical']
periods = OrderedDict()
periods['load'] = cache.int_load_results.walltime_interval()
periods['compute'] = cache.int_compute.walltime_interval()
periods['gc'] = cache.int_gc.walltime_interval()
periods['save'] = cache.int_save_results.walltime_interval()
#.........这里部分代码省略.........