-
Notifications
You must be signed in to change notification settings - Fork 23
/
part08.tex
362 lines (287 loc) · 8.56 KB
/
part08.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
\documentclass[english,serif,mathserif,xcolor=pdftex,dvipsnames,table]{beamer}
\usetheme{gc3}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{gc3}
\title[Sequencing tasks]{%
Running tasks in sequence: \\
\texttt{SequentialTaskCollection} and \texttt{StagedTaskCollection}
}
\author[R. Murri, S3IT UZH]{%
Riccardo Murri \texttt{<riccardo.murri@uzh.ch>}
\\[1ex]
\emph{S3IT: Services and Support for Science IT}
\\[1ex]
University of Zurich
}
\date{January~23--27, 2017}
\begin{document}
% title frame
\maketitle
\begin{frame}[fragile]
\frametitle{Basic use of SequentialTaskCollection}
\begin{python}
from gc3libs.workflow \
import SequentialTaskCollection
class MySequence~\HL{(SequentialTaskCollection)}~:
# ...
def __init__(self, ...):
app1 = FirstApp(...)
app2 = SecondApp(...)
SequentialTaskCollection.__init__(
self, [app1, app2])
\end{python}
\+
A \texttt{SequentialTaskCollection} runs a list of tasks one at a time, in the order given.
\end{frame}
\begin{frame}[fragile]
\frametitle{Basic use of SequentialTaskCollection}
\begin{python}
from gc3libs.workflow \
import SequentialTaskCollection
class MySequence(SequentialTaskCollection):
# ...
def __init__(self, ...):
app1 = FirstApp(...)
app2 = SecondApp(...)
SequentialTaskCollection.__init__(
self, ~\HL{[app1, app2]}~)
\end{python}
\+
Initialize a \texttt{SequentialTaskCollection} \\
with a list of tasks to run.
\end{frame}
\begin{frame}[fragile]
\frametitle{Running tasks in sequence}
\begin{python}
class MyScript(SessionBasedScript):
# ...
def new_tasks(self, extra):
tasks_to_run = [
MySequence(...)
]
return tasks_to_run
\end{python}
\+ You can then run the entire sequence by returning it from
\lstinline|new_tasks()|.
\end{frame}
\begin{frame}
\begin{exercise*}[8.A]
Write a \texttt{priceplot.py} script that performs the following two steps:
\begin{enumerate}
\item Run the
\href{https://github.com/uzh/gc3pie/blob/master/docs/programmers/tutorials/workflows/downloads/simAsset.R}{\texttt{simAsset.R}}
script (from Exercise~6.D) with the parameters given on the command line,
and
\item Feed the \texttt{results.csv} file it outputs into the
\href{https://github.com/uzh/gc3pie/blob/master/docs/programmers/tutorials/workflows/downloads/saplot.py}{\texttt{saplot.py}}
script and retrieve the produced \texttt{saplot.pdf} file.
\end{enumerate}
\+
Run it like \texttt{simAsset.R}, for example:
\begin{semiverbatim}
\$ python priceplot.py 50 0.04 0.1 0.27 10 40
\end{semiverbatim}
\end{exercise*}
\end{frame}
\begin{frame}[fragile]
\frametitle{Running jobs in sequence}
\texttt{StagedTaskCollection} provides a simple interface for
constructing sequences of tasks, but only when the number and
content of steps is \emph{known and fixed} at programming time.
\+
(By contrast, the most general \texttt{SequentialTaskCollection}
can alter the sequence on the fly, insert new stages while running
and loop back. But the code is also harder to write.)
\end{frame}
\begin{frame}[fragile]
\begin{columns}[t]
\begin{column}{0.6\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily]
class Pipeline~\HL{(StagedTaskCollection)}~:
def __init__(self, image):
super(Pipeline).__init__(self)
self.source = image
def stage0(self):
# ...
def stage1(self):
# ...
# ...
def stage~{\bfseries\itshape X}~(self):
# ...
\end{lstlisting}
\end{column}
\begin{column}{0.4\textwidth}
\raggedleft
\+\+\small
Example: \\
subclassing a
\texttt{StagedTaskCollection}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{columns}[c]
\begin{column}{0.6\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily]
class Pipeline(StagedTaskCollection):
def __init__(self, image):
super(Pipeline).__init__(self)
self.source = image
def ~\HL{stage0(self)}~:
# ...
def ~\HL{stage1(self)}~:
# ...
# ...
def ~\HL{stage{\bfseries\itshape X}(self)}~:
# ...
\end{lstlisting}
\end{column}
\begin{column}{0.4\textwidth}
\raggedleft
Stages are numbered starting from $0$.
\+
You can have as many stages as you want.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{columns}[c]
\begin{column}{0.6\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily]
class Pipeline(StagedTaskCollection):
# ...
def stage0(self):
# run 1st step
~\HL{return Application}~(
['convert', self.source,
'-colorspace', 'gray',
'grayscale_' + self.source],
inputs = [self.source],
...)
# ...
\end{lstlisting}
\end{column}
\begin{column}{0.4\textwidth}
\raggedleft
Each \texttt{stage{\itshape X}} method can return a \texttt{Task}
instance, that will run as the $X$-th step in the sequence.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{columns}[c]
\begin{column}{0.6\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily]
class Pipeline(StagedTaskCollection):
# ...
def stage1(self):
~\HL{\textbf{if} \textbf{\color{gray} self}.tasks[0].execution.exitcode != 0:}~
# bail out
return (0, 1)
else:
# run 2nd step
return Application(...)
# ...
def stage~{\bfseries\itshape X}~(self):
# ...
\end{lstlisting}
\end{column}
\begin{column}{0.4\textwidth}
\raggedleft
\+\+\+\+\+
In later stages you can check the exit code of
earlier ones, and decide whether to continue the sequence or
abort.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{columns}[c]
\begin{column}{0.6\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily]
class Pipeline(StagedTaskCollection):
# ...
def stage1(self):
if ...:
# bail out
~\HL{return (0, 1)}~
else:
# run 2nd step
return Application(...)
# ...
def stage~{\bfseries\itshape X}~(self):
# ...
\end{lstlisting}
\end{column}
\begin{column}{0.4\textwidth}
\raggedleft
\+\+\+\+\+
To abort the sequence, return an integer (termination
status) or a pair \emph{(signal, exit code)}, instead of a
\texttt{Task} instance.
\+
This sets the collections' own signal and exit code, and also sets the
state as \texttt{TERMINATED}.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\frametitle{Detour: BLAST, again}
Another use of the BLAST tool is to search for given ``query''
proteins in a data base. Large curated DBs are available, but one
may want to build a custom DB.
\+
Building a DB from a set of FASTA-format files \texttt{p1.faa}
\texttt{p2.faa} and \texttt{p3.faa}, and querying it is a 3-step
process:
\begin{sh}
cat p1.faa p2.faa p3.faa > db.faa
formatdb -i db.faa
blastpgp -i q.faa -d db.faa -e ...
\end{sh}
\+ The \texttt{formatdb} step produces output files
\texttt{db.faa.phr}, \texttt{db.faa.pin}, and \texttt{db.faa.psq}; all
these files are \emph{inputs} to the \texttt{blastpgp} program.
\end{frame}
\begin{frame}[fragile]
\begin{exercise*}[8.B] \emph{(Difficult)}
Write a \texttt{blastdb.py} script to build a BLAST DB and query it.
\+
The \texttt{blastdb.py} script shall be invoked like this:
\begin{sh}
$ python blastdb.py query.faa p1.faa [p2.faa ...]
\end{sh}%$
where arguments \texttt{new.faa}, \texttt{p1.faa}, etc. are FASTA-format files.
\+
The script should build a BLAST DB out of the files {p$N$.faa}.
Then, it should query this database for occurrences of the
proteins in \texttt{query.faa} using \texttt{blastpgp}.
\end{exercise*}
\end{frame}
\begin{frame}
\begin{exercise*}[8.C]
Find out by running the \texttt{blastdb.py} script of Ex.~8.B:
\+
\begin{enumerate}
\item What happens if an intermediate step fails and does not
produce complete output?
\+
\item After the whole sequence turns to TERMINATED state, what is
the value of its signal and exitcode?
\end{enumerate}
\end{exercise*}
\+
\begin{exercise*}[8.D]
Implement (in \texttt{blastdb.py}) a ``cleanup'' feature that removes
intermediate results (e.g., the ``\texttt{.phr}'' files) and only keeps the
output from \texttt{blastpgp} \emph{if the whole sequence was successfully
executed}.
\end{exercise*}
\end{frame}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: