Jupyter: Difference between revisions

From HPCwiki
Jump to navigation Jump to search
New jupyter page in OOD
IA migration §7: merge JupyterHub with GPU + VSCode to Jupyter into Jupyter (GPU and VSCode as sections); polish code blocks, SLURM casing, links (via update-page on MediaWiki MCP Server)
 
Line 1: Line 1:
JupyterLab is the latest web-based interactive development environment for notebooks, code, and data. Its flexible interface allows users to configure and arrange workflows in data science, scientific computing, computational journalism, and machine learning. A modular design invites extensions to expand and enrich functionality.
JupyterLab is the latest web-based interactive development environment for notebooks, code, and data. Its flexible interface lets you arrange workflows in data science, scientific computing, and machine learning, and a modular design supports extensions that expand its functionality.


Traditionally, jupyter has been offered at Anunna via [https://notebook.anunna.wur.nl notebook.anunna.wur.nl], though OOD makes it possible to deploy Jupyter based off the environment modules from Anunna. Adding greater stability and flexibility. Jupyter is listed in the featured apps speed-dial and upon clicking on it, the user is presented with a form where they can select their preferences and allocate resources for their session
There are two ways to run Jupyter on Anunna:
 
* through the [[Portal Overview|Apps Portal]] (https://apps.anunna.wur.nl/), which deploys Jupyter from the Anunna environment modules — the more flexible and stable option;
* through JupyterHub at [https://notebook.anunna.wur.nl notebook.anunna.wur.nl], the traditional service, which is also where course kernels and the GPU setup below live.
 
== Launching Jupyter in the Apps Portal ==
 
Jupyter is listed in the Featured Apps speed-dial. Clicking it presents a form where you select your preferences and allocate resources for the session.
[[File:Jupyter-form-20260225.png|thumb|695x695px|Resource Allocation form for Jupyter Session]]
[[File:Jupyter-form-20260225.png|thumb|695x695px|Resource Allocation form for Jupyter Session]]


=== Resource Allocation Form ===
=== Resource allocation form ===
 
* '''Python version''': the version of Python the default kernel will run
* '''Session type''': the traditional notebook interface or the newer Lab interface (you can also switch interface from within an active session)
* '''Hours''': hours allocated to the session, maximum 4
* '''Number of CPUs''': CPU cores allocated for the session
* '''Amount of memory''': RAM allocated for the session
* '''Number of GPUs''': 0 means no GPU; a non-zero number switches the partition from <code>main</code> to the <code>gpu</code> partition
* '''Comment''': label or project number that will show up in billing
* '''SLURM options''': SLURM flags that may override the settings above
 
=== Connecting to an active session ===
 
Once resources and preferences are set, click '''Launch'''. This submits a job and takes you to the '''My Interactive Sessions''' page. When the session is ready, a '''Connect to Jupyter''' button appears, which lets you (re)connect to it. The card also has a red '''Cancel''' button to terminate the session.
 
== GPU notebooks on JupyterHub ==
 
You can run a GPU-enabled notebook through JupyterHub at [https://notebook.anunna.wur.nl notebook.anunna.wur.nl]. The steps below create a conda environment, register it as a Jupyter kernel, install GPU packages, and start a GPU notebook.
 
=== Set up a conda kernel ===
 
First, connect to a [[SSH Access|login node]] and install conda/Miniforge if you have not already — see [[Python]].
 
By default JupyterHub starts in your home folder, but it is better to keep data and code on Lustre. Link your Lustre folder into your home directory to reach it easily:
 
<syntaxhighlight lang="bash">
ln -s /lustre/[path to your lustre folder] lustre_folders
</syntaxhighlight>
 
To remove the link later:
 
<syntaxhighlight lang="bash">
rm lustre_folders
</syntaxhighlight>
 
Create a conda environment and register it as a Jupyter kernel:
 
<syntaxhighlight lang="bash">
conda create -y -n kernel_test python=3.10 ipykernel
conda activate kernel_test
python -m ipykernel install --user --name kernel_test
</syntaxhighlight>
 
You can set the Python version with <code>python=3.10</code>; choose a version compatible with the packages you need.
 
=== Install GPU packages ===
 
Install the framework you need. For PyTorch, see the [https://pytorch.org/get-started/locally/ PyTorch install guide]; for TensorFlow, see the [https://www.tensorflow.org/install/pip TensorFlow install guide]. For example, for PyTorch with CUDA 11.8:
 
<syntaxhighlight lang="bash">
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
</syntaxhighlight>
 
=== Start a GPU notebook ===
 
Go to [https://notebook.anunna.wur.nl notebook.anunna.wur.nl] and select:
 
* '''Select a location for your server''': on the cluster (the default)
* '''Partition to use''': <code>gpu</code>
* '''Memory (in MB)''': desired memory
* '''Number of CPUs''': desired CPU count
* '''Maximum execution time (hours:minutes:seconds)''': how long the notebook stays available
* '''Extra options''': <code>--gres=gpu:1</code> (use <code>--gres=gpu:x</code> for x GPUs)
 
For multiple GPUs, request them in '''Extra options''' with <code>--gres=gpu:x</code>, then confirm they are visible with the test code below.
 
=== Test GPU availability ===
 
'''PyTorch:'''
 
<syntaxhighlight lang="python">
import torch
 
print("CUDA available:", torch.cuda.is_available())
print("GPU count:", torch.cuda.device_count())
for i in range(torch.cuda.device_count()):
    print(i, torch.cuda.get_device_name(i))
 
# quick operation on the GPU
x = torch.zeros(2, 3).cuda()
print(x + 1)
</syntaxhighlight>
 
'''TensorFlow:'''
 
<syntaxhighlight lang="python">
import tensorflow as tf
 
print("Built with CUDA:", tf.test.is_built_with_cuda())
gpus = tf.config.list_physical_devices('GPU')
print("Accessible GPUs:", len(gpus), gpus)


* '''Python version:''' version of python the default kernel will be running
with tf.device('device:GPU:0'):
* '''Session Type:''' traditional notebooks interface or the newer lab interface. It is also possible to change the interface from within the active Jupyter session.
    a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
* '''Hours:''' Number of hours allocated to the session, max 4 hours
    b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
* '''Number of CPUs:''' Number of CPU cores allocated for the session
print(tf.matmul(a, b))
* '''Amount of Memory:''' RAM allocated for the session
</syntaxhighlight>
* '''Number of GPUs:''' 0 denotes no GPU is used, a non-zero number will switch the partition from main to the gpu partition
* '''Comment:'''  label or project number that will show up in billing.
* '''Slurm Options:''' slurm flags that may override settings above


== Connecting from VSCode ==


==== Connecting to an active session ====
You can connect your local VSCode (Visual Studio Code) to the Anunna Jupyter Server and run notebooks against a remote kernel — for example a Python, R, or Julia kernel.
After the resources and preferences have been defined, the user can simply click on the launch button. Which will submit a job at Anunna and take them to the My Interactive Sessions page where they can connect to their session.  


Once the session is ready a "Connect to Jupyter " button will appear which will allow the user to (re)connect to the corresponding active session.
# Update VSCode to the latest version.
# Install (or update) the '''Jupyter''' extension for Visual Studio Code.
# Install (or update) the '''Python''' extension (use the R or Julia extension instead for R or Julia kernels).
# Open [https://notebook.anunna.wur.nl the Jupyter Server] in your browser and log in with your user ID and credentials.
# From the top menu, click '''Token''' → '''Request new API token''' (the defaults are fine). Copy the token — you cannot see it again, but you can always request a new one. Then start your Jupyter Server.
# In VSCode, open the command palette (<code>Cmd+Shift+P</code> on macOS, <code>Ctrl+Shift+P</code> elsewhere) and run '''Create: New Jupyter Notebook''' (or '''File → New File… → Jupyter Notebook''').
# In the notebook, click '''Select Kernel''' (top-right) → '''Existing JupyterHub Server…''' and enter the URL <code>https://notebook.anunna.wur.nl</code>. Follow the prompts, entering your user ID and the API token, and give the server a name.
# VSCode connects to the remote server (you will see "Connecting to JupyterHub Server…" at the bottom-right). Once connected, choose a kernel and start coding against the remote kernel.


The card also has a red "Cancel" button where the user may terminate their session.
== See also ==
* [[Portal Overview]]
* [[Python]]
* [[R]]
* [[RStudio]]

Latest revision as of 12:38, 18 June 2026

JupyterLab is the latest web-based interactive development environment for notebooks, code, and data. Its flexible interface lets you arrange workflows in data science, scientific computing, and machine learning, and a modular design supports extensions that expand its functionality.

There are two ways to run Jupyter on Anunna:

Launching Jupyter in the Apps Portal

Jupyter is listed in the Featured Apps speed-dial. Clicking it presents a form where you select your preferences and allocate resources for the session.

Resource Allocation form for Jupyter Session

Resource allocation form

  • Python version: the version of Python the default kernel will run
  • Session type: the traditional notebook interface or the newer Lab interface (you can also switch interface from within an active session)
  • Hours: hours allocated to the session, maximum 4
  • Number of CPUs: CPU cores allocated for the session
  • Amount of memory: RAM allocated for the session
  • Number of GPUs: 0 means no GPU; a non-zero number switches the partition from main to the gpu partition
  • Comment: label or project number that will show up in billing
  • SLURM options: SLURM flags that may override the settings above

Connecting to an active session

Once resources and preferences are set, click Launch. This submits a job and takes you to the My Interactive Sessions page. When the session is ready, a Connect to Jupyter button appears, which lets you (re)connect to it. The card also has a red Cancel button to terminate the session.

GPU notebooks on JupyterHub

You can run a GPU-enabled notebook through JupyterHub at notebook.anunna.wur.nl. The steps below create a conda environment, register it as a Jupyter kernel, install GPU packages, and start a GPU notebook.

Set up a conda kernel

First, connect to a login node and install conda/Miniforge if you have not already — see Python.

By default JupyterHub starts in your home folder, but it is better to keep data and code on Lustre. Link your Lustre folder into your home directory to reach it easily:

ln -s /lustre/[path to your lustre folder] lustre_folders

To remove the link later:

rm lustre_folders

Create a conda environment and register it as a Jupyter kernel:

conda create -y -n kernel_test python=3.10 ipykernel
conda activate kernel_test
python -m ipykernel install --user --name kernel_test

You can set the Python version with python=3.10; choose a version compatible with the packages you need.

Install GPU packages

Install the framework you need. For PyTorch, see the PyTorch install guide; for TensorFlow, see the TensorFlow install guide. For example, for PyTorch with CUDA 11.8:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

Start a GPU notebook

Go to notebook.anunna.wur.nl and select:

  • Select a location for your server: on the cluster (the default)
  • Partition to use: gpu
  • Memory (in MB): desired memory
  • Number of CPUs: desired CPU count
  • Maximum execution time (hours:minutes:seconds): how long the notebook stays available
  • Extra options: --gres=gpu:1 (use --gres=gpu:x for x GPUs)

For multiple GPUs, request them in Extra options with --gres=gpu:x, then confirm they are visible with the test code below.

Test GPU availability

PyTorch:

import torch

print("CUDA available:", torch.cuda.is_available())
print("GPU count:", torch.cuda.device_count())
for i in range(torch.cuda.device_count()):
    print(i, torch.cuda.get_device_name(i))

# quick operation on the GPU
x = torch.zeros(2, 3).cuda()
print(x + 1)

TensorFlow:

import tensorflow as tf

print("Built with CUDA:", tf.test.is_built_with_cuda())
gpus = tf.config.list_physical_devices('GPU')
print("Accessible GPUs:", len(gpus), gpus)

with tf.device('device:GPU:0'):
    a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
    b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
print(tf.matmul(a, b))

Connecting from VSCode

You can connect your local VSCode (Visual Studio Code) to the Anunna Jupyter Server and run notebooks against a remote kernel — for example a Python, R, or Julia kernel.

  1. Update VSCode to the latest version.
  2. Install (or update) the Jupyter extension for Visual Studio Code.
  3. Install (or update) the Python extension (use the R or Julia extension instead for R or Julia kernels).
  4. Open the Jupyter Server in your browser and log in with your user ID and credentials.
  5. From the top menu, click TokenRequest new API token (the defaults are fine). Copy the token — you cannot see it again, but you can always request a new one. Then start your Jupyter Server.
  6. In VSCode, open the command palette (Cmd+Shift+P on macOS, Ctrl+Shift+P elsewhere) and run Create: New Jupyter Notebook (or File → New File… → Jupyter Notebook).
  7. In the notebook, click Select Kernel (top-right) → Existing JupyterHub Server… and enter the URL https://notebook.anunna.wur.nl. Follow the prompts, entering your user ID and the API token, and give the server a name.
  8. VSCode connects to the remote server (you will see "Connecting to JupyterHub Server…" at the bottom-right). Once connected, choose a kernel and start coding against the remote kernel.

See also