How to Use JupyterNotebook on Hoffman2 Cluster


Pre-requisites: a Hoffman2 account.

Why do we want to use JupyterNotebook on Hoffman2?

Answer: this UI allows us to directly modify R/Python/Julia scripts on Hoffman2 and submit them. You can also run code chunks (just like using Rmarkdown in Rstudio). If you are not uploading an entirely new script, it saves you the time for repeatedly editing locally and uploading

Note: to simply use the notebook to edit and test your code is fairly easy. In the next tutorial, we will cover how to use Jupyter's powerful Conda Environment to save your R packages and submit jobs using these environments (no need for the libPaths trick covered in the first tutorial).

Step 0, log in Hoffman2.

(I'm demonstrating BASH Shell code in Jupyter Notebook, which requires the $ in the front. In practice, ignore the $. Just type in the command, and press ENTER)

1. Load anaconda app

Optional Step: Per Hoffman2 policies, if you are going to *run code* in Jupyter-Notebook, take this step to request a computing core (or your login node could get shutdown due to excessive CPU usage.) If you are just editing code, you can skip this step to save some time.

In [ ]:
$ qrsh -l h_rt=10:00:00,h_data=8G

Go Home uisng cd

Then, load anaconda application installed on Hoffman2. (You can also load another anaconda version if you prefer. You can check all available modules installed on Hoffman2 by typing in module avail)

In [ ]:
$ module load anaconda/python3-4.2

# Then set a password to avoid a later complication. I recommend just setting it to 123. 
# This password does not protect your account or anything, just a required formality.
# Your account is already protected by your Hoffman2 password.

# You will only need to do this once:
$ jupyter notebook password
Enter password:  ***
Verify password: ***

Now we are going to check your node's unique IP address, and use it to forward the notebook to our browser.

In [ ]:
$ hostname -i

## Then copy the ip address you see (if you see two, they should be identical. Just copy the latter one.)
## Paste it down below
$ jupyter-notebook --no-browser --port=9999 --ip=_YOUR_IP_

Note that I specify the port to be 9999. You can use any port, but to be safe (avoiding conflicts with other applications using the ports), choose a four digit number above 9000.

Then open a new terminal window (do not close the current one running jupyter-notebook) locally. Type in

In [ ]:
# Should be the same IP you just copied. The port number before your IP should match the above port number
# I am forwarding to the same local port on my machine to avoid confusion, so the port after the ip is also
# 9999 for me. I recommend doing the same.
$ ssh -NL 9999:_YOUR_IP_:9999 caeserio@dtn.hoffman2.idre.ucla.edu

Final step (yes we done!),

go to your browser, type in localhost:9999 (should match the trailing port number you specified above, which is just 9999, unless you decided to go creative in the above step.)

You should see your home directory now!

2. Using Jupyter-notebook to edit and test code

Now it's just like a local jupyter-notebook. You can browse your files in this web UI (easier than command lines), open your R scripts, and/or edit your code in a notebook.

To test your code though, you need one more step to install an R kernel to your conda environment, which we will cover in the next tutorial.