Skip to content

Using Jupyter via OnDemand

Jupyter is an interactive web-based environment for creating and using Jupyter notebooks, documents containing live code and visualisations. While many languages are supported by Jupyter, Python notebooks are very commonly used. Please refer to the overview section for instructions on how to login to OnDemand.

Starting a Jupyter session

If your code does not specifically use GPU acceleration and/or you do not have access to GPU-enabled nodes, then choose "Jupyter Notebook CPU" from the Interactive Apps list.

Jupyter request

Here you can choose the number of cores and quantity of RAM required.

Request 1 core for most Jupyter jobs

Many Jupyter notebooks will only use 1 core, therefore any additional cores requested will be allocated but not utilised.

Choosing a 1 hour maximum running time is the best option for getting a session quickly, unless you have access to owned nodes which may also provide sessions immediately for up to 240hrs if resources are available.

Once clicking Launch, the request will be queued, and when resources have been allocated, you will be presented with the option to open the session.

Jupyter launch

Here you can see the compute host that the session has been scheduled on, and time remaining for the session.

Clicking Connect to Jupyter will open the familiar Jupyter session window, from which you can open notebooks.

Jupyter default session

And in action:

Jupyter pandas

Using environments

The Anaconda suite, which we are using, provides a lot of popular Python packages as standard. However, if you need you use modules outside of the default list provided by Anaconda, you will need to switch environments from within the Jupyter notebook.

We will demonstrate this by attempting to use the emoji module to display emojis. A default Anaconda environment does not contain this package.

Listing installed packages

You can inspect the list of packages provided by the default Anaconda installation from within a terminal session on Apocrita by loading the Anaconda module: module load anaconda3 followed by the conda list command

In a Jupyter notebook, attempting to load the emoji module will fail.

Jupyter import

We will need to create a new conda environment containing our desired packages. Installing the emoji package into an activated environment will allow us to use it on the command line interface, but to also make it visible to Jupyter we need the ipykernel package, and a command to activate it.

We can perform this on Apocrita as follows:

module load anaconda3

# use -y to accept the y/n question, -q to reduce verbosity
conda create -n emoji_env -y -q
conda activate emoji_env

# add the desired packages to the env
# we need to specify the conda-forge channel to install the emoji package
conda install -c conda-forge emoji ipykernel -y -q

# make the env visible to Jupyter
python -m ipykernel install --user --name emoji_env

# deactivate your env
conda deactivate

Note that the ipykernel package and subsequent command are only required to make the environment visible to Jupyter.

If you already have an existing conda environment myenv but you wish to make it visible to Jupyter, simply activate your environment:

conda activate myenv

and run:

conda install ipykernel -y -q
python -m ipykernel install --user --name myenv

Now if you open a new Jupyter session from OnDemand, you will notice that the new environment is available under the Kernel -> Change Kernel menu, with the name we provided with the --name option. Similarly, it will be available as an option under the File -> New notebook menu in addition to the default Anaconda Python 3 environment.

Jupyter switching environment

Now if you open a new notebook, you can now use the emoji_env we created. Note that the currently active environment is displayed in the top right corner.

Jupyter correct environment

Using this method, if you have notebooks requiring packages in addition to the defaults, you can now maintain different environments to support use of those notebooks.