Advertise filters param in discovery doc.
[arvados.git] / doc / user / tutorials / tutorial-new-pipeline.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 navmenu: Tutorials
5 title: "Constructing a Crunch pipeline"
6
7 ...
8
9 h1. Constructing a Crunch pipeline
10
11 A pipeline in Arvados is a collection of crunch scripts, in which the output from one script may be used as the input to another script.
12
13 *This tutorial assumes that you are "logged into an Arvados VM instance":{{site.baseurl}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.baseurl}}/user/getting_started/check-environment.html*
14
15 h2. Create a new script
16
17 Our second script will filter the output of @parallel_hash.py@ and only include hashes that start with 0.  Create a new script in @crunch_scripts/@ called @0-filter.py@:
18
19 <pre><code class="userinput">{% include '0_filter_py' %}</code></pre>
20
21 Now add it to git:
22
23 <notextile>
24 <pre><code>$ <span class="userinput">git add 0-filter.py</span>
25 $ <span class="userinput">git commit -m"zero filter"</span>
26 $ <span class="userinput">git push origin master</span>
27 </code></pre>
28 </notextile>
29
30 h2. Create a pipeline template
31
32 Next, create a file that contains the pipeline definition:
33
34 <notextile>
35 <pre><code>$ <span class="userinput">cat &gt;the_pipeline &lt;&lt;EOF
36 {
37   "name":"my_first_pipeline",
38   "components":{
39     "do_hash":{
40       "script":"parallel-hash.py",
41       "script_parameters":{
42         "input": "887cd41e9c613463eab2f0d885c6dd96+83"
43       },
44       "script_version":"you:master"
45     },
46     "filter":{
47       "script":"0-filter.py",
48       "script_parameters":{
49         "input":{
50           "output_of":"do_hash"
51         }
52       },
53       "script_version":"you:master"
54     }
55   }
56 }
57 EOF
58 </code></pre>
59 </notextile>
60
61 * @"name"@ is a human-readable name for the pipeline
62 * @"components"@ is a set of scripts that make up the pipeline
63 * Each component is listed with a human-readable name (@"do_hash"@ and @"filter"@ in this example)
64 * Each item in @"components"@ is a single Arvados job, and uses the same format that we saw previously with @arv job create@
65 * @"output_of"@ indicates that the @"input"@ of @"filter"@ is the @"output"@ of the @"do_hash"@ component.  This is a _dependency_.  Arvados uses the dependencies between jobs to automatically determine the correct order to run the jobs.
66
67 Now, use @arv pipeline_template create@ tell Arvados about your pipeline template:
68
69 <notextile>
70 <pre><code>$ <span class="userinput">arv pipeline_template create --pipeline-template "$(cat the_pipeline)"</span>
71 qr1hi-p5p6p-xxxxxxxxxxxxxxx
72 </code></pre>
73 </notextile>
74
75 Your new pipeline template will appear on the Workbench %(rarr)&rarr;% Compute %(rarr)&rarr;% Pipeline&nbsp;templates page.
76
77 h3. Running a pipeline
78
79 Run the pipeline using @arv pipeline run@, using the UUID that you received from @arv pipeline create@:
80
81 <notextile>
82 <pre><code>$ <span class="userinput">arv pipeline run --template qr1hi-p5p6p-xxxxxxxxxxxxxxx</span>
83 2013-12-16 14:08:40 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
84 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 queued 2013-12-16T14:08:40Z
85 filter  -                           -
86 2013-12-16 14:08:51 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
87 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 e2ccd204bca37c77c0ba59fc470cd0f7+162
88 filter  qr1hi-8i9sb-w5k40fztqgg9i2x queued 2013-12-16T14:08:50Z
89 2013-12-16 14:09:01 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
90 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 e2ccd204bca37c77c0ba59fc470cd0f7+162
91 filter  qr1hi-8i9sb-w5k40fztqgg9i2x 735ac35adf430126cf836547731f3af6+56
92 </code></pre>
93 </notextile>
94
95 This instantiates your pipeline and displays a live feed of its status.  The new pipeline instance will also show up on the Workbench %(rarr)&rarr;% Compute %(rarr)&rarr;% Pipeline&nbsp;instances page.
96
97 Arvados adds each pipeline component to the job queue as its dependencies are satisfied (or immediately if it has no dependencies) and finishes when all components are completed or failed and there is no more work left to do.
98
99 The Keep locators of the output of each of @"do_hash"@ and @"filter"@ component are available from the output log shown above.  The output is also available on the Workbench by navigating to %(rarr)&rarr;% Compute %(rarr)&rarr;% Pipeline&nbsp;instances %(rarr)&rarr;% pipeline uuid under the *id* column %(rarr)&rarr;% components.
100
101 <notextile>
102 <pre><code>$ <span class="userinput">arv keep get e2ccd204bca37c77c0ba59fc470cd0f7+162/md5sum.txt</span>
103 0f1d6bcf55c34bed7f92a805d2d89bbf alice.txt
104 504938460ef369cd275e4ef58994cffe bob.txt
105 8f3b36aff310e06f3c5b9e95678ff77a carol.txt
106 $ <span class="userinput">arv keep get 735ac35adf430126cf836547731f3af6+56</span>
107 0f1d6bcf55c34bed7f92a805d2d89bbf alice.txt
108 </code></pre>
109 </notextile>
110
111 Indeed, the filter has picked out just the "alice" file as having a hash that starts with 0.
112
113 h3. Running a pipeline with different parameters
114
115 Notice that the pipeline definition explicitly specifies the Keep locator for the input:
116
117 <notextile>
118 <pre><code>...
119     "do_hash":{
120       "script_parameters":{
121         "input": "887cd41e9c613463eab2f0d885c6dd96+83"
122       },
123     }
124 ...
125 </code></pre>
126 </notextile>
127
128 What if we want to run the pipeline on a different input block?  One option is to define a new pipeline template, but would potentially result in clutter with many pipeline templates defined for one-off jobs.  Instead, you can override values in the input of the component like this:
129
130 <notextile>
131 <pre><code>$ <span class="userinput">arv pipeline run --template qr1hi-d1hrv-vxzkp38nlde9yyr do_hash::input=33a9f3842b01ea3fdf27cc582f5ea2af+242</span>
132 2013-12-17 20:31:24 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
133 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 queued 2013-12-17T20:31:24Z
134 filter  -                           -
135 2013-12-17 20:31:34 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
136 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 {:done=>1, :running=>1, :failed=>0, :todo=>0}
137 filter  -                           -
138 2013-12-17 20:31:44 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
139 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 {:done=>1, :running=>1, :failed=>0, :todo=>0}
140 filter  -                           -
141 2013-12-17 20:31:55 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
142 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 880b55fb4470b148a447ff38cacdd952+54
143 filter  qr1hi-8i9sb-j347g1sqovdh0op queued 2013-12-17T20:31:55Z
144 2013-12-17 20:32:05 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
145 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 880b55fb4470b148a447ff38cacdd952+54
146 filter  qr1hi-8i9sb-j347g1sqovdh0op fb728f0ffe152058fa64b9aeed344cb5+54
147 </code></pre>
148 </notextile>
149
150 Now check the output:
151
152 <notextile>
153 <pre><code>$ <span class="userinput">arv keep ls -s fb728f0ffe152058fa64b9aeed344cb5+54</span>
154 0 0-filter.txt
155 </code></pre>
156 </notextile>
157
158 Here the filter script output is empty, so none of the files in the collection have hash code that start with 0.