Setting up and running jupyter notebooks in slurm is tedious and finnicky. It involves the following steps:
- allocating a slurm node (salloc command)
- running jupyter-notebook on the node
- ssh forwarding to the login node (so you can actually use it if the node is airgapped)
- using the authentication token to log in to the notebook
- On some clusters (e.g. Princeton's
della
cluster), running jupyter-notebooks on login nodes is forbidden. In practice, this means that any jobs which have the name "jupyter-notebook" in them are automatically killed. To bypass this, we use the runb.sh script so that the script can't catch it.
This program automates all of that, while letting you easily configure your slurm job.
- Clone this repo
- Install rust (https://www.rust-lang.org/tools/install)
- Run
cargo install --path .
in the repo directory - (if not already done) add
~/.cargo/bin
to your PATH variable (recommended to do this in ~/.bashrc)
- Change to the directory you want to run the notebook in
- Create a config file (see argfile.toml for an example)
- Activate your conda/venv environment
- Run salloc-nb
The output should display a URL. You can use this one of two ways:
- With VScode, simply open the .ipynb file you want to run, and select the kernel in the top right. Choose "Existing Jupyter Server" and "Enter the URL of the running Jupyter Server", and copy-paste the URL from the output of salloc-nb. You will only need to do this once, and VScode will remember the server. Now you will be able to run the notebook as normal on the allocated node.
- If you are using your browser, you will need to ssh forward the port to access from your local machine (VScode should do this automatically). Then navigate to the URL in your browser.