Skip to content

Commit c9e374a

Browse files
authored
Add jupyterlab docs (#107)
1 parent 68ced86 commit c9e374a

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* @bcumming @msimberg @RMeli
2+
docs/services/jupyterlab.md @rsarm
23
docs/services/firecrest @jpdorsch @ekouts
34
docs/software/communication @Madeeks @msimberg
45
docs/software/devtools/linaro @jgphpc

docs/services/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@
1212
FirecREST is a RESTful API for programmatically accessing High-Performance Computing resources.
1313

1414
[:octicons-arrow-right-24: FirecREST][ref-firecrest]
15+
16+
- :simple-jupyter: __JupyterLab__
17+
18+
JupyterLab is a feature-rich notebook authoring application and editing environment.
19+
20+
[:octicons-arrow-right-24: JupyterLab][ref-jlab]
1521
</div>
1622

docs/services/jupyterlab.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
[](){#ref-jlab}
2+
# JupyterLab
3+
4+
## Access and setup
5+
6+
The JupyterHub service enables the interactive execution of JupyterLab on [Daint][ref-cluster-daint] on a single compute node.
7+
8+
The service is accessed at [jupyter-daint.cscs.ch](https://jupyter-daint.cscs.ch/).
9+
10+
Once logged in, you will be redirected to the JupyterHub Spawner Options form, where typical job configuration options can be selected in order to allocate resources. These options might include the type and number of compute nodes, the wall time limit, and your project account.
11+
12+
Single-node notebooks are launched in a dedicated queue, minimizing queueing time. For these notebooks, servers should be up and running within a few minutes. The maximum waiting time for a server to be running is 5 minutes, after which the job will be cancelled and you will be redirected back to the spawner options page. If your single-node server is not spawned within 5 minutes we encourage you to [contact us](ref-get-in-touch).
13+
14+
When resources are granted the page redirects to the JupyterLab session, where you can browse, open and execute notebooks on the compute nodes. A new notebook with a Python 3 kernel can be created with the menu `new` and then `Python 3` . Under `new` it is also possible to create new text files and folders, as well as to open a terminal session on the allocated compute node.
15+
16+
## Debugging
17+
18+
The log file of a JupyterLab server session is saved on `$SCRATCH` in a file named `jupyterhub_<jobid>.log`. If you encounter problems with your JupyterLab session, the contents of this file can be a good first clue to debug the issue.
19+
20+
!!! warning "Unexpected error while saving file: disk I/O error."
21+
This error message indicates that you have run out of disk quota.
22+
You can check your quota using the command `quota`.
23+
24+
## Accessing file systems
25+
26+
The Jupyter sessions are started in your `$HOME` folder. All non-hidden files and folders in `$HOME` are visible and accessible through the JupyterLab file browser. However, you can not browse directly to folders above `$HOME`. To enable access your `$SCRATCH` folder, it is therefore necessary to create a symbolic link to your `$SCRATCH` folder. This can be done by issuing the following command in a terminal from your `$HOME` directory:
27+
28+
```bash
29+
ln -s $SCRATCH $HOME/scratch
30+
```
31+
32+
Alternatively, you can issue the following command directly in a notebook cell: `!ln -s $SCRATCH $HOME/scratch`.
33+
34+
## Creating Jupyter kernels for Python
35+
36+
A kernel, in the context of Jupyter, is a program that runs the user code within the Jupyter notebooks. Jupyter kernels make it possible to access virtual environments, custom python installations like anaconda/miniconda or any custom python setting, from Jupyter notebooks.
37+
38+
Jupyter kernels are powered by [`ipykernel`](https://github.com/ipython/ipykernel).
39+
As a result, `ipykernel` must be installed in every environment that will be used as a kernel.
40+
That can be done with `pip install ipykernel`.
41+
A kernel can be created from an active Python virtual environment with the following commands
42+
43+
```console title="Create a Jupyter kernel"
44+
. /myenv/bin/activate
45+
python -m ipykernel install --user --name="<kernel-name>" --display-name="<kernel-name>"
46+
```
47+
48+
## Using uenvs in JupyterLab
49+
50+
In the JupyterHub Spawner Options form mentioned above, it's possible to pass an uenv and a view.
51+
The uenv will be mounted at `/user-environment`, and the specified view will be activated.
52+
53+
If the uenv includes the installation of a Python package, you will need to create a Jupyter kernel to make the package available in the notebooks.
54+
If `ipykernel` is not available in the uenv, you can create a Python virtual environment in a terminal within JupyterLab and install it there
55+
56+
```console
57+
cd $SCRATCH
58+
python -m venv uenv-pyenv --system-site-packages
59+
pip install ipykernel
60+
```
61+
62+
Then with that virtual environment activated, you can run the command to create the Jupyter kernel.
63+
64+
!!! warning "Using remote uenv for the first time."
65+
If the uenv is not present in the local repository, it will be automatically fetched.
66+
As a result, JupyterLab may take slightly longer than usual to start.
67+
68+
## Ending your interactive session and logging out
69+
70+
The Jupyter servers can be shut down through the Hub. To end a JupyterLab session, please select `Control Panel` under the `File` menu and then `Stop My Server`. By contrast, clicking `Logout` will log you out of the server, but the server will continue to run until the Slurm job reaches its maximum wall time.
71+
72+
## MPI in the notebook via IPyParallel and MPI4Py
73+
74+
MPI for Python provides bindings of the Message Passing Interface (MPI) standard for Python, allowing any Python program to exploit multiple processors.
75+
76+
MPI can be made available on Jupyter notebooks through [IPyParallel](https://github.com/ipython/ipyparallel). This is a Python package and collection of CLI scripts for controlling clusters for Jupyter: A set of servers that act as a cluster, called engines, is created and the code in the notebook's cells will be executed within them.
77+
78+
We provide the python package [`ipcmagic`](https://github.com/eth-cscs/ipcluster_magic) to make easier the mangement of IPyParallel clusters. `ipcmagic` can be installed by the user with
79+
80+
```bash
81+
pip install ipcmagic-cscs
82+
```
83+
84+
The engines and another server that moderates the cluster, called the controller, can be started an stopped with the magic `%ipcluster start -n <num-engines>` and `%ipcluster stop`, respectively. Before running the command, the python package `ipcmagic` must be imported
85+
86+
```bash
87+
import ipcmagic
88+
```
89+
90+
Information about the command, can be obtained with `%ipcluster --help`.
91+
92+
In order to execute MPI code on JupyterLab, it is necessary to indicate that the cells have to be run on the IPyParallel engines. This is done by adding the [IPyParallel magic command](https://ipyparallel.readthedocs.io/en/latest/tutorial/magics.html) `%%px` to the first line of each cell.
93+
94+
There are two important points to keep in mind when using IPyParallel. The first one is that the code executed on IPyParallel engines has no effect on non-`%%px` cells. For instance, a variable created on a `%%px`-cell will not exist on a non-`%%px`-cell. The opposite is also true. A variable created on a regular cell, will be unknown to the IPyParallel engines. The second one is that the IPyParallel engines are common for all the user's notebooks. This means that variables created on a `%%px` cell of one notebook can be accessed or modified by a different notebook.
95+
96+
The magic command `%autopx` can be used to make all the cells of the notebook `%%px`-cells. `%autopx` acts like a switch: running it once, activates the `%%px` and running it again deactivates it. If `%autopx` is used, then there are no regular cells and all the code will be run on the IPyParallel engines.
97+
98+
Examples of notebooks with `ipcmagic` can be found [here](https://github.com/eth-cscs/ipcluster_magic/tree/master/examples).
99+
100+
## Further documentation
101+
102+
* [Jupyter](http://jupyter.org/)
103+
* [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/)
104+
* [JupyterHub](https://jupyterhub.readthedocs.io/en/stable)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ nav:
8686
- services/index.md
8787
- 'FirecREST': services/firecrest.md
8888
- 'CI/CD': services/cicd.md
89+
- 'JupyterLab': services/jupyterlab.md
8990
- 'Running Jobs':
9091
- running/index.md
9192
- 'slurm': running/slurm.md

0 commit comments

Comments
 (0)