Skip to content

Commit

Permalink
Split old part 2 into two separate slide decks.
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jul 9, 2016
1 parent 659dfbf commit 2a39a72
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 349 deletions.
Binary file modified docs/programmers/tutorials/workflows/part02.pdf
Binary file not shown.
355 changes: 6 additions & 349 deletions docs/programmers/tutorials/workflows/part02.tex
Expand Up @@ -135,15 +135,15 @@ \part{Workflow scaffolding}
\begin{enumerate}
\item Run the following command:
\begin{sh}
> python ex2a.py --help
\end{sh}
$ python ex2a.py --help
\end{sh}%$
Where does the program description in the help text come from?
Is there anything weird in other parts of the help text?
\item Run the following command:
\begin{sh}
> python ex2a.py
\end{sh}
$ python ex2a.py
\end{sh}%$
What happens?
\end{enumerate}
\end{exercise*}
Expand Down Expand Up @@ -521,7 +521,7 @@ \part{The \texttt{Application} object}
inputs = [
'/home/rmurri/values.dat',
'/home/rmurri/stats.csv',
]
]
\end{python}
will make files \emph{values.dat} and \emph{stats.csv} available in
the command execution directory.
Expand Down Expand Up @@ -646,7 +646,7 @@ \part{The \texttt{Application} object}
\begin{frame}[fragile]
\frametitle{The \texttt{stdout} parameter}
This specifies that the command's \texttt{standard output} should be
This specifies that the command's \emph{standard output} should be
saved into a file named \texttt{stdout.txt} and retrieved along with
the other output files.
Expand Down Expand Up @@ -757,349 +757,6 @@ \part{The \texttt{Application} object}
\end{frame}
\begin{frame}[fragile]
\frametitle{Application lifecycle}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily,keywordstyle=\normalfont]
$ ./grayscale.py lena.jpg
~\em [\ldots]~
NEW 1/1 (100.0%)
RUNNING 0/1 (0.0%)
STOPPED 0/1 (0.0%)
SUBMITTED 0/1 (0.0%)
TERMINATED 0/1 (0.0%)
TERMINATING 0/1 (0.0%)
UNKNOWN 0/1 (0.0%)
total 1/1 (100.0%)
\end{lstlisting}%$
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
\texttt{Application} objects can be in one of several states.

\+
(A session-based script prints a table of all managed applications and their states.)
\end{column}
\end{columns}

\+
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{lstlisting}[basicstyle=\footnotesize\ttfamily]
>>> print(app.execution.state)
'TERMINATED'
\end{lstlisting}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
The current state is stored in the \texttt{.execution.state} instance attribute.
\end{column}
\end{columns}

\+
\begin{references}
\tiny
\url{http://gc3pie.readthedocs.io/en/master/programmers/api/gc3libs.html#gc3libs.Run.state}
\end{references}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state NEW}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-NEW}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
\textbf{NEW} is the state of ``just created'' Application objects.

\+
The Application has not yet been sent off to a compute
resource: it only exists locally.
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state SUBMITTED}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-SUBMITTED}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
\emph{SUBMITTED} applications have been successfully sent to a
computational resource.

\+
(The transition to \emph{RUNNING} happens automatically, as we
do not control the remote execution.)
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state RUNNING}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-RUNNING}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
\emph{RUNNING} state happens when the computational job associated to an
application starts executing on the computational resource.
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state STOPPED}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-STOPPED}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
A task is in \emph{STOPPED} state when its execution has been
blocked at the remote site and GC3Pie cannot recover
automatically.

\+
User or sysadmin intervention is required for a task to get out
of \emph{STOPPED} state.
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state UNKNOWN}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-UNKNOWN}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
A task is in \emph{UNKNOWN} state when GC3Pie can no
longer monitor it at the remote site.

\+
(As this might be due to network failures, jobs \emph{can} get
out of \emph{UNKNOWN} automatically.)
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state TERMINATING}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-TERMINATING}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
\emph{TERMINATING} state when a computational job has finished
running, for whatever reason.

\+
(Transition to \emph{TERMINATED} only happens when \texttt{fetch\_output} is called.)
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Application lifecycle: state TERMINATED}

\begin{columns}[c]
\begin{column}{0.5\textwidth}
\includegraphics[height=0.7\textheight]{fig/states-TERMINATED}
\end{column}
\begin{column}{0.5\textwidth}
\raggedleft
A job is \emph{TERMINATED} when its final output has been
retrieved and is available locally.

\+
The exit code of \emph{TERMINATED} jobs can be inspected to
find out whether the termination was successful or unsuccessful,
or if the program was forcibly ended.
\end{column}
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{Post-processing features, I}

When the remote computation is done, the \texttt{terminated} method
of the application instance is called.

\+
The path to the output directory is available as
\lstinline|self.output_dir|; if \texttt{stdout} and \texttt{srderr}
have been captured, the paths to the capture files are available as
\lstinline|self.stdout| and \lstinline|self.stderr|.
\end{frame}


\begin{frame}[fragile]
\frametitle{Post-processing features, II}

For example, the following code logs a warning message if the
standard error output is non-empty:
\begin{python}
class MyApp(Application):
# ...
def terminated(self):
error_file = self.output_dir+"/"+self.stderr
error_size = os.stat(error_file).st_size
if error_size > 0:
gc3libs.log.warn(
"Application %s reported errors!", self)
\end{python}
\end{frame}


\begin{frame}
\begin{exercise*}[2.D]

Modify the \texttt{GrayscaleApp} application to print a message
``\texttt{Conversion of '\emph{filename}' done.}'' whenever
running the \texttt{convert} program terminates.
\end{exercise*}
\end{frame}


\begin{frame}
\frametitle{A successful run or not?}

There's a \emph{single TERMINATED state}, whatever the task outcome.
You have to inspect the ``return code'' to determine the
cause of ``task death''.

\+
Attribute `.execution.returncode` provides a numeric termination
status (with the same format and meaning as the POSIX termination
status).

\+
The termination status combines two fields: the ``termination
signal'' and the ``exit code''.

\end{frame}

\begin{frame}[fragile]
\frametitle{Termination signal, I}

The \texttt{.execution.signal} instance attribute is non-zero if
the program was killed by a signal (e.g., memory error / segmentation fault).

\+
The \texttt{.execution.signal} instance attribute is zero only if
the program run until termination. (\textbf{Beware!} This does not
mean that it run \emph{correctly}: just that it halted by itself.)
\end{frame}


\begin{frame}[fragile]
\frametitle{Termination signal, II}

Read \texttt{man 7 signal} for a list of OS signals and their
numeric values.

\+
{\bfseries Note that GC3Pie overloads some signal codes (unused
by the OS) to represent its own specific errors.}

\+
For instance, if program \texttt{app} was cancelled by the user,
\texttt{.execution.signal} will take the value 121:
\begin{python}
>>> print(app.execution.signal)
121
\end{python}
\end{frame}


\begin{frame}[fragile]
\frametitle{Exit code}

The \texttt{.execution.exitcode} instance attribute holds the
numeric exitcode of the executed command, or \texttt{None} if the
command has not finished running yet.

\+
{\bfseries Note that the \texttt{.execution.exitcode} is guaranteed
to have a valid value only if the \texttt{.execution.signal}
attribute has the value 0.}

\+
The \texttt{.execution.exitcode} is the same exitcode that you
would see when running a command directly in the terminal shell. (By
convention, code 0 is successful termination, every other value
indicates an error.)
\end{frame}


\begin{frame}
\begin{exercise*}[2.E]

Write a \texttt{TermStatusApp} application, which is like a
generic \texttt{Application} class with the addition that ---upon
termination--- it prints:
\begin{itemize}
\item whether the program has been killed by a signal, and the signal number;
\item whether the program has terminated by exiting, and the exit code.
\end{itemize}

Verify that it works by plugging the class into the ``grayscale''
session-based script.
\end{exercise*}
\end{frame}


\begin{frame}[fragile]
\begin{exercise*}[2.F] \emph{(Difficult)} \small

MATLAB has the annoying habit of exiting with code 0 even when some error occurred.

\+
Write a \texttt{MatlabApp} application, which:
\begin{itemize}
\item is constructed by giving the path to a MATLAB `\texttt{.m}'
script file, like this: \texttt{app = MatlabApp("ra.m")};
\item Runs the following command:
\begin{semiverbatim}
matlab -nosplash -nodesktop -nojvm \emph{file.m}
\end{semiverbatim}
where \emph{file.m} is the file given to the
\texttt{MatlabApp()} constructor.
\item captures the standard error output (\texttt{stderr}) of the
MATLAB script and, if the string ``\texttt{Out of memory.}''
occurs in it, sets the application exitcode to 11.
\end{itemize}

Verify that it works by running a MATLAB script that allocates an
array of random size. (For some random values, the size will
exceed the amount of available memory.)
\end{exercise*}
\end{frame}


\end{document}
%%% Local Variables:
Expand Down
Binary file added docs/programmers/tutorials/workflows/part03.pdf
Binary file not shown.

0 comments on commit 2a39a72

Please sign in to comment.