Skip to content

Commit ad90f51

Browse files
committed
fix all smaller issues discovered on first run-through
1 parent 9f6f668 commit ad90f51

File tree

8 files changed

+1033
-12
lines changed

8 files changed

+1033
-12
lines changed

_episodes/01-getting-started.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ questions:
66
- "How do I run Python on Supercomputing Wales?"
77
- "How do I install packages and other Python software on
88
Supercomputing Wales?"
9+
keypoints:
10+
- "Use `module load anaconda/2019.03` and `source activate` to get started with Anaconda on Sunbird"
11+
- "Create new conda environments with `conda create` when the `base` Anaconda set of packages doesn't meet your needs"
912
---
1013

1114
Python is one of the most popular programming languages currently
@@ -228,8 +231,22 @@ root permissions.
228231

229232
> ## More packages for today
230233
>
231-
> We'll also need the Matplotlib package for some of today's examples
232-
> Decide whether to install it via Conda or Pip, and install it.
234+
> We'll also need the IPython, Matplotlib, Numba, and Pillow packages
235+
> for some of today's examples.
236+
> For each of these, decide whether to install it via Conda or Pip,
237+
> and install it.
238+
>
239+
> > ## Solution
240+
> >
241+
> > IPython, Matplotlib, Numba, and Pillow are all common packages, and all
242+
> > are included in the base Anaconda distribution. They can be
243+
> > installed with
244+
> >
245+
> > ~~~
246+
> > $ conda install ipython matplotlib numba pillow
247+
> > ~~~
248+
> > {: .language-bash}
249+
> {: .solution}
233250
{: .challenge}
234251
235252
> ## An environment for your research

_episodes/02-design-constraints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ depending on the processor and data type, then 4, 8, or even 16
133133
iterations of this loop can happen at a single time.
134134

135135
Compare the execution of a loop element-by-element sequentially:
136-
![An illustration of a loop happening sequentially](/fig/non-vector.svg)
136+
![An illustration of a loop happening sequentially](../fig/non-vector.svg)
137137

138138
with the execution of a vectorised loop:
139-
![An illustration of a vectorised loop](/fig/vector.svg)
139+
![An illustration of a vectorised loop](../fig/vector.svg)
140140

141141
The vectorised loop can be up to N times faster, where N is the number
142142
of elements that fit into the processor's vector units.

_episodes/04-gnu-parallel.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Parallel to be able to control.
6464
> will need to convert it to running as an independent Python script
6565
> in order to use GNU Parallel and command-line arguments. For more
6666
> information on this, see the
67-
>
67+
> [Command-line arguments](http://swcarpentry.github.io/python-novice-inflammation/10-cmdline/)
6868
> episode of the Software Carpentry Python lesson.
6969
{: .callout}
7070

@@ -81,7 +81,7 @@ see what it does:
8181
~~~
8282
$ python fourier_orig.py
8383
~~~
84-
{: .language-python}
84+
{: .language-bash}
8585

8686
This should take a few seconds to run; use `ls -lrt` to see the most
8787
recently created files in the directory once it finishes to see what
@@ -268,7 +268,8 @@ carries out.
268268
With this done, we can test that the program still works, by running:
269269

270270
~~~
271-
$ python fourier_new.py --fourier_restricted_output=fourier_restricted.pdf \
271+
$ python fourier_new.py einstein1_7.jpg \
272+
--fourier_restricted_output=fourier_restricted.pdf \
272273
--noise_isolation_output=noise_isolation.pdf \
273274
--phase_contrast_output=phase_contrast.pdf
274275
~~~

_episodes/05-profiling.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,11 @@ $ python -m cProfile -o mc.prof mc.py 0 1.0 0.1 1000000 mc.dat
247247
This will create a file called `mc.prof`, containing the profiling
248248
data. Now, since displaying graphics from the cluster on your own
249249
machine isn't always easy, instead we'll copy the profile to our local
250-
machine to view. This can be done with FileZilla, or at a Bash prompt
251-
with the command:
250+
machine to view. This can be done with FileZilla, or at a Bash prompt.
251+
252+
253+
To do this at the shell, open a new terminal (running on your own
254+
machine), and run the command:
252255

253256
~~~
254257
$ # This runs on your computer, not on the supercomputer
@@ -259,6 +262,7 @@ $ scp s.your.username@sunbird.swansea.ac.uk:hpp-examples/mc.prof ~/Desktop/
259262
Now we can install SnakeViz and visualise the profile:
260263

261264
~~~
265+
$ # This should also happen on your own computer
262266
$ pip install snakeviz
263267
$ snakeviz ~/Desktop/mc.prof
264268
~~~
@@ -432,7 +436,9 @@ $ python -m timeit --setup 'import mc' 'mc.metropolis(1.0, 0.1, 1.0)'
432436
>
433437
> You can use `timeit` within a Jupyter notebook to test the
434438
> performance of code you are writing there, too. In a new cell, use
435-
> `%timeit` followed by the function or expresion you want to time.
439+
> `%timeit` followed by the function or expresion you want to time,
440+
> and use `%%timeit` at the top of a cell to time the execution of the
441+
> entire cell.
436442
>
437443
> If you have Jupyter installed on your machine, open a new notebook
438444
> and try this now for the list comprehension and loop

_episodes/06-numpy-scipy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ express any other way without using explicit `for` loops.
361361
> square, and counting the number that lie within the unit circle, we
362362
> can find an estimate for $\frac{\pi}{4}$, and by extension, $\pi$.
363363
>
364+
> ![A diagram illustrating the description above.](../fig/pi_dartboard.svg)
365+
>
364366
> A plain Python function that would achieve this might look as
365367
> follows:
366368
>

_episodes/08-pathos.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ tasks across more than one CPU. Pathos is a tool that extends this
2727
to work across multiple nodes, and provides other convenience
2828
improvements over Python's built-in tools.
2929

30+
To start with, we need to install Pathos.
31+
Pathos isn't installed as part of the standard Anaconda distribution;
32+
it can be installed from the `conda-forge` channel though.
33+
34+
~~~
35+
$ conda install pathos
36+
~~~
37+
{: .language-bash}
3038

3139
## A toy example
3240

@@ -67,7 +75,7 @@ that we have written ourselves.
6775

6876
Before we can ask Pathos to run our code in parallel, we need to
6977
structure it in a way that Pathos can do this easily. This is
70-
a similar process process to the one we used for accepting command-line
78+
a similar process to the one we used for accepting command-line
7179
arguments; the difference is that now instead of using the `argparse`
7280
module and declaring the arguments that way, we declare a function
7381
that accepts the arguments in question. (It's good practice to do this
@@ -239,14 +247,37 @@ if __name__ == '__main__':
239247
hs = [0.25, 0.5, 1.0, 2.5]
240248
run_in_parallel(
241249
*zip(*product(betas, ms, hs)),
242-
1000
250+
10000
243251
)
244252
~~~
245253
{: .language-python}
246254

247255
Saving this as `mc_pathos_scan.py` and running it will now generate
248256
324 output files in the `mc_data` directory.
249257

258+
> ## Verifying that it is parallel
259+
>
260+
> When Slurm is running a job on a particular node, it will let us SSH
261+
> directly to that note to check its behaviour. We can use this to
262+
> verify that we are running in parallel as we expect.
263+
>
264+
> Open a new terminal, and SSH to Sunbird again. Use `squeue -u $USER`
265+
> to find out what node your job is running on—this is the
266+
> right-most column. Then SSH into that node, using `ssh scsXXXX`,
267+
> where `XXXX` is replaced with the node number you got from `squeue`.
268+
>
269+
> Once running on the node, you can use the `top` command to get a
270+
> list of the processes using the most CPU resource, updating every
271+
> second. If your program is parallelising properly, you should see
272+
> multiple `python` processes, all consuming somewhere near 100%
273+
> CPU. (The percentages refer to a single CPU core rather than to the
274+
> available CPU in the machine as a whole.)
275+
>
276+
> If your job (or interactive allocation) ends while you're SSHed into
277+
> the node, then the SSH session will be killed by the system
278+
> automatically.
279+
{: .callout}
280+
250281
> ## Processing file lists
251282
>
252283
> Not all the workloads of this kind will be parameter scans; some
@@ -321,6 +352,19 @@ While it is possible to start processes on more than one node using
321352
the Pathos library directly, this is easier to do using Pyina, which
322353
is another part of the Pathos framework.
323354

355+
Since Pyina depends on MPI, it's not available via Conda (as the MPI
356+
installation will change from machine to machine). To install Pyina,
357+
we first need to choose an MPI library, and then install via Pip. On
358+
Sunbird, the first step can be done by loading the appropriate module.
359+
360+
~~~
361+
$ # Get the latest version of the Intel MPI library
362+
$ module load mpi/intel/2019/4
363+
$ # Now install Pyina using this MPI library
364+
$ pip install pyina
365+
~~~
366+
{: .language-bash}
367+
324368
It can be used very similarly to the Pathos library, by creating a
325369
process pool and then using a map function across that pool. The
326370
difference is that Pyina will interact with Slurm to correctly

_episodes/10-numba.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def numpy_trig(a, b):
235235

236236
~~~
237237
$ python -m timeit --setup='import numpy as np; \
238+
import trig; \
238239
a = np.random.random((1000, 1000)); \
239240
b = np.random.random((1000, 1000))' \
240241
'trig.vec_trig(a, b)'

0 commit comments

Comments
 (0)