Updating and reorganizing tutorials based on new features and feedback.
[arvados.git] / doc / user / tutorials / tutorial-new-pipeline.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 navmenu: Tutorials
5 title: "Writing a Crunch pipeline"
6 ...
7
8 h1. Writing a Crunch pipeline
9
10 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.
11
12 *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*
13
14 h2. Create a new script
15
16 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@:
17
18 <notextile> {% code '0_filter_py' as python %} </notextile>
19
20 Now add it to git:
21
22 <notextile>
23 <pre><code>$ <span class="userinput">git add 0-filter.py</span>
24 $ <span class="userinput">git commit -m"zero filter"</span>
25 $ <span class="userinput">git push origin master</span>
26 </code></pre>
27 </notextile>
28
29 h2. Create a pipeline template
30
31 Next, create a file that contains the pipeline definition:
32
33 <notextile>
34 <pre><code>$ <span class="userinput">cat &gt;the_pipeline &lt;&lt;EOF
35 {
36   "name":"my_first_pipeline",
37   "components":{
38     "do_hash":{
39       "script":"parallel-hash.py",
40       "script_parameters":{
41         "input": "887cd41e9c613463eab2f0d885c6dd96+83"
42       },
43       "script_version":"you:master"
44     },
45     "filter":{
46       "script":"0-filter.py",
47       "script_parameters":{
48         "input":{
49           "output_of":"do_hash"
50         }
51       },
52       "script_version":"you:master"
53     }
54   }
55 }
56 EOF
57 </code></pre>
58 </notextile>
59
60 * @"name"@ is a human-readable name for the pipeline
61 * @"components"@ is a set of scripts that make up the pipeline
62 * Each component is listed with a human-readable name (@"do_hash"@ and @"filter"@ in this example)
63 * Each item in @"components"@ is a single Arvados job, and uses the same format that we saw previously with @arv job create@
64 * @"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.
65
66 Now, use @arv pipeline_template create@ tell Arvados about your pipeline template:
67
68 <notextile>
69 <pre><code>$ <span class="userinput">arv pipeline_template create --pipeline-template "$(cat the_pipeline)"</span>
70 qr1hi-p5p6p-xxxxxxxxxxxxxxx
71 </code></pre>
72 </notextile>
73
74 Your new pipeline template will appear on the Workbench %(rarr)&rarr;% Compute %(rarr)&rarr;% Pipeline&nbsp;templates page.
75
76 h3. Running a pipeline
77
78 Run the pipeline using @arv pipeline run@, using the UUID that you received from @arv pipeline create@:
79
80 <notextile>
81 <pre><code>$ <span class="userinput">arv pipeline run --template qr1hi-p5p6p-xxxxxxxxxxxxxxx</span>
82 2013-12-16 14:08:40 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
83 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 queued 2013-12-16T14:08:40Z
84 filter  -                           -
85 2013-12-16 14:08:51 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
86 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 e2ccd204bca37c77c0ba59fc470cd0f7+162
87 filter  qr1hi-8i9sb-w5k40fztqgg9i2x queued 2013-12-16T14:08:50Z
88 2013-12-16 14:09:01 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
89 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 e2ccd204bca37c77c0ba59fc470cd0f7+162
90 filter  qr1hi-8i9sb-w5k40fztqgg9i2x 735ac35adf430126cf836547731f3af6+56
91 </code></pre>
92 </notextile>
93
94 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.
95
96 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.
97
98 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.
99
100 <notextile>
101 <pre><code>$ <span class="userinput">arv keep get e2ccd204bca37c77c0ba59fc470cd0f7+162/md5sum.txt</span>
102 0f1d6bcf55c34bed7f92a805d2d89bbf alice.txt
103 504938460ef369cd275e4ef58994cffe bob.txt
104 8f3b36aff310e06f3c5b9e95678ff77a carol.txt
105 $ <span class="userinput">arv keep get 735ac35adf430126cf836547731f3af6+56</span>
106 0f1d6bcf55c34bed7f92a805d2d89bbf alice.txt
107 </code></pre>
108 </notextile>
109
110 Indeed, the filter has picked out just the "alice" file as having a hash that starts with 0.
111
112 h3. Running a pipeline with different parameters
113
114 Notice that the pipeline definition explicitly specifies the Keep locator for the input:
115
116 <notextile>
117 <pre><code>...
118     "do_hash":{
119       "script_parameters":{
120         "input": "887cd41e9c613463eab2f0d885c6dd96+83"
121       },
122     }
123 ...
124 </code></pre>
125 </notextile>
126
127 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:
128
129 <notextile>
130 <pre><code>$ <span class="userinput">arv pipeline run --template qr1hi-d1hrv-vxzkp38nlde9yyr do_hash::input=33a9f3842b01ea3fdf27cc582f5ea2af+242</span>
131 2013-12-17 20:31:24 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
132 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 queued 2013-12-17T20:31:24Z
133 filter  -                           -
134 2013-12-17 20:31:34 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
135 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 {:done=>1, :running=>1, :failed=>0, :todo=>0}
136 filter  -                           -
137 2013-12-17 20:31:44 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
138 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 {:done=>1, :running=>1, :failed=>0, :todo=>0}
139 filter  -                           -
140 2013-12-17 20:31:55 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
141 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 880b55fb4470b148a447ff38cacdd952+54
142 filter  qr1hi-8i9sb-j347g1sqovdh0op queued 2013-12-17T20:31:55Z
143 2013-12-17 20:32:05 +0000 -- pipeline_instance qr1hi-d1hrv-tlkq20687akys8e
144 do_hash qr1hi-8i9sb-rffhuay4jryl2n2 880b55fb4470b148a447ff38cacdd952+54
145 filter  qr1hi-8i9sb-j347g1sqovdh0op fb728f0ffe152058fa64b9aeed344cb5+54
146 </code></pre>
147 </notextile>
148
149 Now check the output:
150
151 <notextile>
152 <pre><code>$ <span class="userinput">arv keep ls -s fb728f0ffe152058fa64b9aeed344cb5+54</span>
153 0 0-filter.txt
154 </code></pre>
155 </notextile>
156
157 Here the filter script output is empty, so none of the files in the collection have hash code that start with 0.