Skip to content

Launch Jupyter Lab on Hera

kevindougherty-noaa edited this page Dec 9, 2021 · 6 revisions

Launch Jupyter Lab on Hera

The following instructions are used to launch Jupyter Lab on Hera. Jupyter Lab is a web-based interface that enables you to work with notebooks, text editors, and terminals in a flexible, integrated and extensive manner. For more information about Jupyter Lab, you can reference this video here.

Using Jupyter Notebooks is an excellent tool for new Python users. The Jupyter notebook provides a space where you can learn to code, but can also be used as a presentation or educational tool. It allows programmers and data scientists to create documents that integrate live code, equations, computational output, and visualizations, along with explanatory text in a single document. As a new user, it allows you to run small bits of code for testing and debugging to learn how certain Python functions and applications work.

How to Launch Jupyter Lab:

  1. Login to Hera as you would normally and write down your Local (12345) and Remote (67890) port numbers that appear just above the “Welcome to Hera High Performance Computing system” box. Then sign out.

  2. Login to Hera using the following command:

    ssh -XL 67890:localhost:12345 First.Last@hera-rsa.princeton.rdhpcs.noaa.gov

    or

    ssh -XL 67890:localhost:12345 First.Last@hera-rsa.boulder.rdhpcs.noaa.gov

    Change the bolded numbers to your assigned user local and remote ports numbers and your own first and last name for your login.

  3. Load proper python environments

    module use /scratch1/NCEPDEV/da/Cory.R.Martin/Modulefiles/python/
    module load anaconda/kevin
    conda activate UFO
    
  4. cd into the directory you would like to work in

  5. Launch Jupyter Lab with the following command:

    jupyter lab --no-browser --port=8889

    Some output will then appear about the Jupyter Lab being launched. Towards the end of it, you will see one or more URLs that would take you to the same place.

  6. Copy and paste the URL that appears in your terminal to your favorite web browser. The promt in your terminal should look something like this:

    To access the notebook, open this file in a browser:
            ...
    Or copy and paste one of these URLs:
        http://localhost:8889/?token=5dfc63b24f0485df716951609b43c9bf85137fb86c478035
    

    NOTE: Pasting the URL in a browser and hitting Enter will not got you anywhere yet. Read on!

  7. Open a new terminal window and login to Hera using the following command. This sets up the appropriate tunneling. A reminder that the bolded number shown here is your Remote port number (see Step 1). Also, use your first and last name for typical login.

    ssh -N -f -p 67890 -L 8889:localhost:8889 First.Last@localhost

NOTE: If the command above returns an error message, try the following. In your terminal (i.e. not on Hera yet), open /Users/your_username/.ssh/known_hosts If a line looks like this:

[localhost]:67890 ssh-ed25519 blahblahblah

Replace blahblahblah with the string you see in the URL link immediately after the word "token" (see step 6). Save, exit, and retry to connect to Hera. Alternatively you can delete this line, save the file, and then when you try to connect to Hera, it will ask you 'are you sure?' and type 'yes' and press return.

  1. Go back to the web browser with the URL you copied in Step 6 and your Jupyter Lab should be activated It may take a moment to load.

Tips and shortcuts to make logging into Jupyter Lab faster:

1. Save ssh logins

Saving the ssh commands in Step 2 and Step 7 in where you typically login can help save some time and will only require you to submit your RSA token password.

For example, Step 1 can be saved as “Hera Princeton Jupyter”. Step 7 can be saved as “Hera Princeton launch Jupyter”

2. Create shell script that includes all Python environment commands

You can create a shell script for example: load_python_modules.sh that include all the commands needed to load the python environments. This way, all you need to do is run on command to ensure your python environment is set.

3. Create an alias in your ~/.bashrc file for launching Jupyter Lab (Step 5)

Within your ~/.bashrc file, you can set an alias that will run the command in Step 5. For example add the following lines to your ~/.bashrc file and source it:

jupyter_lab=’jupyter lab --no_browser --port=8889’

Doing this will now allow you to just run the command: jupyter_lab in your terminal window and it will launch jupyter lab without having to type all of the other information. Note that you may need to choose a different port if someone else is currently running something using port 8889 on Hera.

Now your following workflow to sign in would be:

  1. Launch your saved “Hera Princeton Jupyter” login and enter your RSA token
  2. Run the following commands
sh load_python_modules.sh
cd /your/working/directory
jupyter_lab
  1. Copy the output from the last command, similar to Step 6
  2. Launch your saved “Hera Princeton launch Jupyter” login and enter your RSA token
  3. Paste your url link into your favorite web browser