Skip to content

Commit 297701e

Browse files
authored
SISGraph.{jobs,find,jobs_sorted} update_graph option (#293)
1 parent dec9ab9 commit 297701e

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

sisyphus/graph.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,28 +355,32 @@ def job_directory_structure(self):
355355
def job_by_id(self, sis_id):
356356
return self.id_to_job_dict().get(sis_id)
357357

358-
def jobs(self) -> List[Job]:
358+
def jobs(self, *, update_graph: bool = True) -> List[Job]:
359359
"""
360-
:return ([Job, ...]): List with all jobs in grpah
360+
:param update_graph: if True, update all nodes/jobs (calling :func:`Job._sis_runnable`)
361+
while running through the graph to get the most current dependency graph.
362+
:return ([Job, ...]): List with all jobs in graph
361363
"""
362364
job_list = []
363365

364366
def f(job):
365367
job_list.append(job)
366368
return True
367369

368-
self.for_all_nodes(f)
370+
self.for_all_nodes(f, update_graph=update_graph)
369371
return job_list
370372

371-
def find(self, pattern, mode="all"):
373+
def find(self, pattern: str, mode: str = "all", *, update_graph: bool = True):
372374
"""Returns a list with all jobs and paths that partly match the pattern
373375
374-
:param pattern(str): Pattern to match
375-
:param mode(str): Select if jobs, paths or both should be returned. Possible values: all, path, job
376+
:param pattern: Pattern to match
377+
:param mode: Select if jobs, paths or both should be returned. Possible values: all, path, job
378+
:param update_graph: if True, update all nodes/jobs (calling :func:`Job._sis_runnable`)
379+
while running through the graph to get the most current dependency graph.
376380
:return ([Job/Path, ...]): List with all matching jobs/paths
377381
"""
378382
out = set()
379-
for j in self.jobs():
383+
for j in self.jobs(update_graph=update_graph):
380384
if mode in ("all", "job"):
381385
vis_name = j.get_vis_name()
382386
aliases = j._sis_aliases if j._sis_aliases is not None else set()
@@ -392,10 +396,12 @@ def find(self, pattern, mode="all"):
392396
out.add(p)
393397
return list(out)
394398

395-
def jobs_sorted(self):
399+
def jobs_sorted(self, *, update_graph: bool = True):
396400
"""Yields jobs in a order so that for each jop all jobs
397401
it depends on are already finished
398402
403+
:param update_graph: if True, update all nodes/jobs (calling :func:`Job._sis_runnable`)
404+
while running through the graph to get the most current dependency graph.
399405
:return (generator Node): jobs sorted by dependency
400406
"""
401407
id_to_job = {}
@@ -406,7 +412,7 @@ def get_job(sis_id):
406412
return id_to_job[sis_id]
407413

408414
stack = []
409-
for job in self.jobs():
415+
for job in self.jobs(update_graph=update_graph):
410416
node = get_job(job._sis_id())
411417
node.job = job
412418
for i in job._sis_inputs:

sisyphus/toolkit.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@
5050
import subprocess
5151
import importlib
5252

53-
from sisyphus.tools import sh, extract_paths
54-
import sisyphus.block
55-
from sisyphus.block import block, sub_block, set_root_block
56-
from sisyphus.async_workflow import async_run, async_gather, async_context
57-
from sisyphus.delayed_ops import Delayed
58-
from sisyphus import cleaner
59-
60-
from sisyphus.job_path import AbstractPath, Path, Variable
53+
from sisyphus.tools import sh, extract_paths # noqa: F401
54+
import sisyphus.block # noqa: F401
55+
from sisyphus.block import block, sub_block, set_root_block # noqa: F401
56+
from sisyphus.async_workflow import async_run, async_gather, async_context # noqa: F401
57+
from sisyphus.delayed_ops import Delayed # noqa: F401
58+
from sisyphus import cleaner # noqa: F401
59+
60+
from sisyphus.job_path import AbstractPath, Path, Variable # noqa: F401
6161
from sisyphus.job import Job
6262
from sisyphus import graph
6363
import sisyphus.global_settings as gs
6464

65-
from sisyphus.loader import config_manager
65+
from sisyphus.loader import config_manager # noqa: F401
6666

6767

6868
class BlockedWorkflow(Exception):
@@ -478,8 +478,8 @@ def import_directory(job):
478478
# run once before to unsure inputs are updated at least once
479479
sis_graph.for_all_nodes(import_directory, bottom_up=True)
480480
# run until no new jobs are added. This could be solved more efficient, but this is works...
481-
while number_of_jobs != len(sis_graph.jobs()):
482-
number_of_jobs = len(sis_graph.jobs())
481+
while number_of_jobs != len(sis_graph.jobs(update_graph=False)):
482+
number_of_jobs = len(sis_graph.jobs(update_graph=False))
483483
sis_graph.for_all_nodes(import_directory, bottom_up=True)
484484

485485

0 commit comments

Comments
 (0)