Reorganization, added parallel jobs and new pipeline tutorial.
[arvados.git] / doc / user / tutorial-job-debug.textile
1 ---
2 layout: default
3 navsection: userguide
4 title: "Tutorial: Debug a Crunch script"
5 navorder: 14
6 ---
7
8 h1. Tutorial: Debug a Crunch script
9
10 To test changes to a script by running a job, the change must be pushed into @git@, the job queued asynchronously, and the actual execution may be run on any compute server.  As a result, debugging a script can be difficult and time consuming.  This tutorial demonstrates using @arv-crunch-job@ to run your job in your local VM.  This avoids the job queue and allows you to execute the script from your uncomitted git tree.
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 This tutorial uses _you_ to denote your username.  Replace _you_ with your user name in all the following examples.
15
16 h2. Create a new script
17
18 Change to your git directory and create a new script in "crunch_scripts/".
19
20 <notextile>
21 <pre><code>$ <span class="userinput">cd you/crunch_scripts</span>
22 $ <span class="userinput">cat &gt;hello-world.py &lt;&lt;EOF
23 #!/usr/bin/env python
24
25 print "hello world"
26 EOF</span>
27 $ <span class="userinput">chmod +x hello-world.py</span>
28 </code></pre>
29 </notextile>
30
31 h2. Using arv-crunch-job to run the job in your VM
32
33 Instead of a git commit hash, we provide the path to the directory in the "script_version" parameter.  The script specified in "script" will actually be searched for in the "crunch_scripts/" subdirectory of the directory specified "script_version".  Although we are running the script locally, the script still requires access to the Arvados API server and Keep storage service, and the job will be recorded on then Arvados Workbench job history.
34
35 <notextile>
36 <pre><code>$ <span class="userinput">cat &gt;the_job &lt;&lt;EOF
37 {
38  "script":"hello-world.py",
39  "script_version":"/home/you/you",
40  "script_parameters":{}
41 }
42 EOF</span>
43 $ <span class="userinput">arv-crunch-job --job "$(cat the_job)"</span>
44 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  check slurm allocation
45 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  node localhost - 1 slots
46 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  start
47 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  script hello-world.py
48 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  script_version /home/you/you
49 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  script_parameters {}
50 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  runtime_constraints {"max_tasks_per_node":0}
51 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  start level 0
52 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  status: 0 done, 0 running, 1 todo
53 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 job_task qr1hi-ot0gb-4zdajby8cjmlguh
54 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 child 29834 started on localhost.1
55 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827  status: 0 done, 1 running, 0 todo
56 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 stderr hello world
57 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 child 29834 on localhost.1 exit 0 signal 0 success=
58 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 failure (#1, permanent) after 0 seconds
59 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 output 
60 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827  Every node has failed -- giving up on this round
61 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827  wait for last 0 children to finish
62 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827  status: 0 done, 0 running, 0 todo
63 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827  Freeze not implemented
64 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827  collate
65 2013-12-12_21:36:43 qr1hi-8i9sb-okzukfzkpbrnhst 29827  output d41d8cd98f00b204e9800998ecf8427e+0
66 2013-12-12_21:36:44 qr1hi-8i9sb-okzukfzkpbrnhst 29827  meta key is c00bfbd58e6f58ce3bebdd47f745a70f+1857+K@qr1hi
67 </code></pre>
68 </notextile>
69
70 This is the line of interest:
71
72 bc. 2013-12-12_21:36:42 qr1hi-8i9sb-okzukfzkpbrnhst 29827 0 stderr hello world
73
74 The script's printout is captured in the log, which is useful for print statement debugging.  However, although it the script returned a status code of 0 (success), the job failed.  Why?  For a job to complete successfully scripts must explicitly add their output to Keep, and then tell Arvados about it.  Here is a second try:
75
76 <notextile>
77 <pre><code>$ <span class="userinput">cat &gt;hello-world.py &lt;&lt;EOF
78 #!/usr/bin/env python
79
80 import arvados
81
82 # Create a new collection
83 out = arvados.CollectionWriter()
84
85 # Set the name of the file in the collection to write to
86 out.set_current_file_name('hello.txt')
87
88 # Actually output our text
89 out.write('hello world')
90
91 # Commit the collection to Keep
92 out_collection = out.finish()
93
94 # Tell Arvados which Keep object is our output
95 arvados.current_task().set_output(out_collection)
96
97 # Done!
98 EOF</span>
99 $ <span class="userinput">chmod +x hello-world-fixed.py</span>
100 $ <span class="userinput">cat &gt;the_job &lt;&lt;EOF
101 {
102  "script":"hello-world-fixed.py",
103  "script_version":"/home/you/you",
104  "script_parameters":{}
105 }
106 EOF</span>
107 $ <span class="userinput">arv-crunch-job --job "$(cat the_job)"</span>
108 2013-12-12_21:56:59 qr1hi-8i9sb-79260ykfew5trzl 31578  check slurm allocation
109 2013-12-12_21:56:59 qr1hi-8i9sb-79260ykfew5trzl 31578  node localhost - 1 slots
110 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  start
111 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  script hello-world.py
112 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  script_version /home/you/you
113 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  script_parameters {}
114 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  runtime_constraints {"max_tasks_per_node":0}
115 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  start level 0
116 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  status: 0 done, 0 running, 1 todo
117 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578 0 job_task qr1hi-ot0gb-u8g594ct0wt7f3f
118 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578 0 child 31585 started on localhost.1
119 2013-12-12_21:57:00 qr1hi-8i9sb-79260ykfew5trzl 31578  status: 0 done, 1 running, 0 todo
120 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578 0 child 31585 on localhost.1 exit 0 signal 0 success=true
121 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578 0 success in 1 seconds
122 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578 0 output 576c44d762ba241b0a674aa43152b52a+53
123 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578  wait for last 0 children to finish
124 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578  status: 1 done, 0 running, 0 todo
125 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578  Freeze not implemented
126 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578  collate
127 2013-12-12_21:57:02 qr1hi-8i9sb-79260ykfew5trzl 31578  output 576c44d762ba241b0a674aa43152b52a+53
128 2013-12-12_21:57:03 qr1hi-8i9sb-79260ykfew5trzl 31578  finish
129 2013-12-12_21:57:04 qr1hi-8i9sb-79260ykfew5trzl 31578  meta key is 9f937693334d0c9234ccc1f808ee7117+1761+K@qr1hi
130 </code></pre>
131 </notextile>
132
133 The job succeeded, with output in Keep object @576c44d762ba241b0a674aa43152b52a+53@.  Let's look at our output:
134
135 <notextile>
136 <pre><code>$ <span class="userinput">arv keep get 576c44d762ba241b0a674aa43152b52a+53/hello.txt</span>
137 hello world
138 </code></pre>
139 </notextile>
140
141 Next, "parallel tasks.":tutorial-parallel.html