Reorganized user manual into sections
[arvados.git] / doc / user / tutorials / tutorial-new-pipeline.textile
1 ---
2 layout: default
3 navsection: userguide
4 title: "Construct a pipeline"
5 navorder: 115
6 ---
7
8 h1. Tutorial: Construct a pipeline
9
10 A pipeline in Arvados is a sequence of crunch scripts, in which the output from the previous script is fed in as the input to the next script.
11
12 *This tutorial assumes that you are "logged into an Arvados VM instance":ssh-access.html#login, and have a "working environment.":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 <pre><code class="userinput">{% include 0-filter.py %}</code></pre>
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":"tetron:master"
44     },
45     "filter":{
46       "script":"0-filter.py",
47       "script_parameters":{
48         "input":{
49           "output_of":"do_hash"
50         }
51       },
52       "script_version":"tetron: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
65
66 The @"output_of"@ specifies a _dependency_.  Arvados uses the dependencies between jobs to automatically determine the correct order to run the jobs.
67
68 Now, use @arv pipeline_template create@ tell Arvados about your pipeline template:
69
70 <notextile>
71 <pre><code>$ <span class="userinput">arv pipeline_template create --pipeline-template "$(cat the_pipeline)"</span>
72 qr1hi-p5p6p-xxxxxxxxxxxxxxx
73 </code></pre>
74 </notextile>
75
76 Your new pipeline template will appear on the Workbench %(rarr)&rarr;% Compute %(rarr)&rarr;% Pipeline&nbsp;templates page.
77
78 h3. Running a pipeline
79
80 Run the pipeline using @arv pipeline run@, using the UUID that you received from @arv pipeline create@:
81
82 <notextile>
83 <pre><code>$ <span class="userinput">arv pipeline run --template qr1hi-p5p6p-xxxxxxxxxxxxxxx</span>
84 2013-12-16 14:08:40 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
85 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 queued 2013-12-16T14:08:40Z
86 filter  -                           -
87 2013-12-16 14:08:51 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
88 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 e2ccd204bca37c77c0ba59fc470cd0f7+162+K@qr1hi
89 filter  qr1hi-8i9sb-w5k40fztqgg9i2x queued 2013-12-16T14:08:50Z
90 2013-12-16 14:09:01 +0000 -- pipeline_instance qr1hi-d1hrv-vxzkp38nlde9yyr
91 do_hash qr1hi-8i9sb-hoyc2u964ecv1s6 e2ccd204bca37c77c0ba59fc470cd0f7+162+K@qr1hi
92 filter  qr1hi-8i9sb-w5k40fztqgg9i2x 735ac35adf430126cf836547731f3af6+56
93 </code></pre>
94 </notextile>
95
96 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.
97
98 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.
99
100 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.
101
102 <notextile>
103 <pre><code>
104 $ <span class="userinput">arv keep get e2ccd204bca37c77c0ba59fc470cd0f7+162+K@qr1hi/md5sum.txt</span>
105 0f1d6bcf55c34bed7f92a805d2d89bbf alice.txt
106 504938460ef369cd275e4ef58994cffe bob.txt
107 8f3b36aff310e06f3c5b9e95678ff77a carol.txt
108 $ <span class="userinput">arv keep get 735ac35adf430126cf836547731f3af6+56</span>
109 0f1d6bcf55c34bed7f92a805d2d89bbf alice.txt
110 </code></pre>
111 </notextile>
112
113 Indeed, the filter has picked out just the "alice" file as having a hash that starts with 0.
114
115 h3. Running a pipeline with different parameters
116
117 Notice that the pipeline definition explicitly specifies the Keep locator for the input:
118
119 <notextile>
120 <pre><code>
121 ...
122     "do_hash":{
123       "script_parameters":{
124         "input": "887cd41e9c613463eab2f0d885c6dd96+83"
125       },
126     }
127 ...
128 </code></pre>
129 </notextile>
130
131 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:
132
133 <pre><code>
134 $ <span class="userinput">arv pipeline run --template qr1hi-p5p6p-uf9gi9nolgakm85 do_hash::input=33a9f3842b01ea3fdf27cc582f5ea2af
135 </code></pre>
136 </notextile>
137
138 <notextile>
139 <pre><code>
140 $ <span class="userinput">arv keep get 880b55fb4470b148a447ff38cacdd952+54+K@qr1hi/md5sum.txt</span>
141 44b8ae3fde7a8a88d2f7ebd237625b4f var-GS000016015-ASM.tsv.bz2
142 $ <span class="userinput">arv keep get fb728f0ffe152058fa64b9aeed344cb5+54</span>
143 </code></pre>
144 </notextile>
145
146 Since the hash of @var-GS000016015-ASM.tsv.bz2@ does not start with 0, the filter script has no output in this pipeline instance.