Skip to content

Commit 611c806

Browse files
kinowmr-c
andauthored
Document more features of cwltool (#246)
* Show cwltool --make-template to users in the chapter where we introduce the inputs objects * Add a troubleshooting section for the cachedir docs Co-authored-by: Michael R. Crusoe <[email protected]>
1 parent df4a7a2 commit 611c806

File tree

8 files changed

+174
-1
lines changed

8 files changed

+174
-1
lines changed

.github/workflows/gh-pages.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
- name: Install apt packages
1919
run: |
20-
sudo apt-get install -y graphviz
20+
sudo apt-get install -y graphviz tree
2121
2222
- name: Set up Python
2323
uses: actions/setup-python@v4

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _site
1010
.Rhistory
1111
.RData
1212
_build/
13+
build/
1314
*.egg-info/
1415

1516
src/_includes/cwl/**/output.txt

.readthedocs.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build:
99
nodejs: "16"
1010
apt_packages:
1111
- graphviz
12+
- tree
1213

1314
sphinx:
1415
configuration: src/conf.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
cwlVersion: v1.2
2+
class: Workflow
3+
4+
inputs:
5+
text:
6+
type: string
7+
default: 'Hello World'
8+
outputs:
9+
reversed_message:
10+
type: string
11+
outputSource: step_b/reversed_message
12+
13+
steps:
14+
step_a:
15+
run:
16+
class: CommandLineTool
17+
stdout: stdout.txt
18+
inputs:
19+
text: string
20+
outputs:
21+
step_a_stdout:
22+
type: File
23+
outputBinding:
24+
glob: 'stdout.txt'
25+
baseCommand: echo
26+
arguments: [ '-n', '$(inputs.text)' ]
27+
in:
28+
text: text
29+
out: [step_a_stdout]
30+
step_b:
31+
run:
32+
class: CommandLineTool
33+
stdout: stdout.txt
34+
inputs:
35+
step_a_stdout: File
36+
outputs:
37+
reversed_message:
38+
type: string
39+
outputBinding:
40+
glob: stdout.txt
41+
loadContents: true
42+
outputEval: $(self[0].contents)
43+
baseCommand: rev
44+
arguments: [ $(inputs.step_a_stdout) ]
45+
in:
46+
step_a_stdout:
47+
source: step_a/step_a_stdout
48+
out: [reversed_message]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cwlVersion: v1.2
2+
class: Workflow
3+
4+
inputs:
5+
text:
6+
type: string
7+
default: 'Hello World'
8+
outputs:
9+
reversed_message:
10+
type: string
11+
outputSource: step_b/reversed_message
12+
13+
steps:
14+
step_a:
15+
run:
16+
class: CommandLineTool
17+
stdout: stdout.txt
18+
inputs:
19+
text: string
20+
outputs:
21+
step_a_stdout:
22+
type: File
23+
outputBinding:
24+
glob: 'stdout.txt'
25+
arguments: ['echo', '-n', '$(inputs.text)']
26+
in:
27+
text: text
28+
out: [step_a_stdout]
29+
step_b:
30+
run:
31+
class: CommandLineTool
32+
stdout: stdout.txt
33+
inputs:
34+
step_a_stdout: File
35+
outputs:
36+
reversed_message:
37+
type: string
38+
outputBinding:
39+
glob: stdout.txt
40+
loadContents: true
41+
outputEval: $(self[0].contents)
42+
baseCommand: revv
43+
arguments: [ $(inputs.step_a_stdout) ]
44+
in:
45+
step_a_stdout:
46+
source: step_a/step_a_stdout
47+
out: [reversed_message]

src/topics/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ best-practices.md
2121
file-formats.md
2222
metadata-and-authorship.md
2323
specifying-software-requirements.md
24+
troubleshooting.md
2425
```

src/topics/inputs.md

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ Create a file called `inp-job.yml`:
2929
:name: inp-job.yml
3030
```
3131

32+
````{note}
33+
You can use `cwltool` to create a template input object. That saves you from having
34+
to type all the input parameters in a input object file:
35+
36+
```{runcmd} cwltool --make-template inp.cwl
37+
:working-directory: src/_includes/cwl/inputs
38+
```
39+
40+
You can redirect the output to a file, i.e. `cwltool --make-template inp.cwl > inp-job.yml`,
41+
and then modify the default values with your desired input values.
42+
````
43+
3244
Notice that "example_file", as a `File` type, must be provided as an
3345
object with the fields `class: File` and `path`.
3446

src/topics/troubleshooting.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Troubleshooting
2+
3+
In this section you will find ways to troubleshoot when you have problems executing CWL.
4+
We focus on `cwltool` here but some of these techniques may apply to other CWL Runners.
5+
6+
## Run `cwltool` with `cachedir`
7+
8+
You can use the `--cachedir` option when running a workflow to tell `cwltool` to
9+
cache intermediate files (files that are not input nor output files, but created
10+
while your workflow is running). By default, these files are created in a
11+
temporary directory but writing them to a separate directory makes accessing
12+
them easier.
13+
14+
In the following example `troubleshooting-wf1.cwl` we have two steps, `step_a` and `step_b`.
15+
The workflow is equivalent to `echo "Hello World" | rev`, which would print the message
16+
"Hello World" reversed, i.e. "dlroW olleH". However, the second step, `step_b`, **has a typo**,
17+
where instead of executing the `rev` command it tries to execute `revv`, which
18+
fails.
19+
20+
```{literalinclude} /_includes/cwl/troubleshooting/troubleshooting-wf1.cwl
21+
:language: cwl
22+
:name: "`troubleshooting-wf1.cwl`"
23+
:caption: "`troubleshooting-wf1.cwl`"
24+
:emphasize-lines: 42
25+
```
26+
27+
Let's execute this workflow with `/tmp/cachedir/` as the `--cachedir` value (`cwltool` will
28+
create the directory for you if it does not exist already):
29+
30+
```{runcmd} cwltool --cachedir /tmp/cachedir/ troubleshooting-wf1.cwl
31+
:working-directory: src/_includes/cwl/troubleshooting
32+
:emphasize-lines: 12-14, 19-21
33+
```
34+
35+
The workflow is in the `permanentFail` status due to `step_b` failing to execute the
36+
non-existent `revv` command. The `step_a` was executed successfully and its output
37+
has been cached in your `cachedir` location. You can inspect the intermediate files
38+
created:
39+
40+
```{runcmd} tree /tmp/cachedir
41+
:emphasize-lines: 4
42+
```
43+
44+
Each workflow step has received a unique ID (the long value that looks like a hash).
45+
The `${HASH}.status` files display the status of each step executed by the workflow.
46+
And the `step_a` output file `stdout.txt` is visible in the output of the command above.
47+
48+
Now fix the typo so `step_b` executes `rev` (i.e. replace `revv` by `rev` in the
49+
`step_b`). After fixing the typo, when you execute `cwltool` with the same arguments
50+
as the previous time, note that now `cwltool` output contains information about
51+
pre-cached outputs for `step_a`, and about a new cache entry for the output of `step_b`.
52+
Also note that the status of `step_b` is now of success.
53+
54+
```{runcmd} cwltool --cachedir /tmp/cachedir/ troubleshooting-wf1-stepb-fixed.cwl
55+
:working-directory: src/_includes/cwl/troubleshooting
56+
:emphasize-lines: 12, 16-18
57+
```
58+
59+
In this example the workflow step `step_a` was not re-evaluated as it had been cached, and
60+
there was no change in its execution or output. Furthermore, `cwltool` was able to recognize
61+
when it had to re-evaluate `step_b` after we fixed the executable name. This technique is
62+
useful for troubleshooting your CWL documents and also as a way to prevent `cwltool` to
63+
re-evaluate steps unnecessarily.

0 commit comments

Comments
 (0)