Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching support for CWL #5187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/toil/cwl/cwltoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4177,8 +4177,12 @@ def main(args: Optional[list[str]] = None, stdout: TextIO = sys.stdout) -> int:
runtime_context.move_outputs = "leave"
runtime_context.rm_tmpdir = False
runtime_context.streaming_allowed = not options.disable_streaming
if options.cachedir is not None:
runtime_context.cachedir = os.path.abspath(options.cachedir)
if options.mpi_config_file is not None:
runtime_context.mpi_config = MpiConfig.load(options.mpi_config_file)
if cwltool.main.check_working_directories(runtime_context) is not None:
return 1
setattr(runtime_context, "bypass_file_store", options.bypass_file_store)
if options.bypass_file_store and options.destBucket:
# We use the file store to write to buckets, so we can't do this (yet?)
Expand Down Expand Up @@ -4360,7 +4364,12 @@ def main(args: Optional[list[str]] = None, stdout: TextIO = sys.stdout) -> int:
if not options.bypass_file_store:
# If we're using the file store we need to start moving output
# files now.
runtime_context.move_outputs = "move"
# But if caching is enabled we have to leave files in the cache directory,
# so do a copy if so.
if runtime_context.cachedir is not None:
runtime_context.move_outputs = "copy"
else:
runtime_context.move_outputs = "move"

# We instantiate an early builder object here to populate indirect
# secondaryFile references using cwltool's library because we need
Expand Down
9 changes: 9 additions & 0 deletions src/toil/options/cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,12 @@ def add_cwl_options(parser: ArgumentParser, suppress: bool = True) -> None:
type=str,
help=suppress_help or "Specify a cloud bucket endpoint for output files.",
)
parser.add_argument(
"--cachedir",
type=str,
help=suppress_help
or "Directory to cache intermediate workflow outputs to avoid "
"recomputing steps. Can be very helpful in the development and "
"troubleshooting of CWL documents.",
dest="cachedir"
)
24 changes: 24 additions & 0 deletions src/toil/test/cwl/cwlTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,30 @@ def path_with_bogus_rev() -> str:
except subprocess.CalledProcessError:
pass

def test_caching(self) -> None:
log.info("Running CWL Test Cache.")
from toil.cwl import cwltoil

outDir = self._createTempDir()
cwlDir = os.path.join(self._projectRootPath(), "src", "toil", "test", "cwl")
cmd = [
"--outdir",
outDir,
"--jobStore",
os.path.join(outDir, "jobStore"),
"--no-container",
"--cachedir",
"cache",
os.path.join(cwlDir, "revsort.cwl"),
os.path.join(cwlDir, "revsort-job.json"),
]
# Finish the job with a correct PATH
st = StringIO()
ret = cwltoil.main(cmd, stdout=st)
assert ret == 0
# cwltool hashes certain steps into directories, ensure it exists
assert os.path.exists(os.path.join(cwlDir, "cache", "9da28e219a61b062824576503f88b863"))

@needs_aws_s3
def test_streamable(self, extra_args: Optional[list[str]] = None) -> None:
"""
Expand Down
Loading