in dora/grid.py [0:0]
def monitor(args: tp.Any, main: DecoratedMain, explorer: Explorer, herd: tp.List[Sheep],
maybe_print: tp.Callable) -> bool:
"""Single iteration of monitoring of the jobs in a Grid.
Returns `True` if all jobs are done or failed, and `False` otherwise.
"""
names, base_name = main.get_names([sheep.xp for sheep in herd])
histories = [main.get_xp_history(sheep.xp) for sheep in herd]
trim = None
if args.trim is not None:
trim = len(histories[args.trim])
elif args.trim_last:
trim = min(len(metrics) for metrics in histories)
if trim is not None:
histories = [metrics[:trim] for metrics in histories]
lines = []
finished = True
for index, (sheep, history, name) in enumerate(zip(herd, histories, names)):
state = sheep.state()
if not sheep.is_done():
finished = False
if state is None:
state = "N/A"
else:
state = state[:3]
meta = {
'name': name,
'index': index,
'sid': sheep.job.job_id if sheep.job else '',
'sig': sheep.xp.sig,
'state': state,
}
line = {}
line['Meta'] = meta
try:
other = explorer.process_sheep(sheep, history)
except NotImplementedError:
other = explorer.process_history(history)
line.update(other)
lines.append(line)
if base_name:
maybe_print("Base name: ", base_name)
table = tt.table(
shorten=True,
groups=[
tt.group("Meta", explorer.get_grid_meta()),
] + explorer.get_grid_metrics()
)
maybe_print(tt.treetable(lines, table, colors=explorer.get_colors()))
return finished