Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
technical:recipes:jupyter-notebook [2024-08-02 14:32] – [Setting up SSH tunnel to connect to Jupyter Notebook server] thuachen | technical:recipes:jupyter-notebook [2025-02-04 09:48] (current) – [VALET Package Definition] anita | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Jupyter Notebook Python Virtual Environment====== | ||
+ | |||
+ | The following steps will walk you through setting up an Anaconda virtual environment with Python 3 and Jupyter Notebook. It will also cover the steps of requesting a compute note to run a Jupyter Notebook session on Caviness. Lastly, it will explain how to set up SSH connections to be able to connect to the Jupyter Notebook session running on a compute node. This setup will be done in the '' | ||
+ | |||
+ | <note tip> | ||
+ | |||
+ | Before starting, make sure you set your workgroup and change to the directory where you would like to store your Jupyter Notebook virtual environment. In this example, a general directory '' | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | <code bash> | ||
+ | [traine@login00 ~]$ workgroup -g it_css | ||
+ | [(it_css: | ||
+ | [(it_css: | ||
+ | [(it_css: | ||
+ | </ | ||
+ | |||
+ | ===== Create Jupyter Notebook Virtual Environment | ||
+ | As stated above, in this example we will be using Anaconda version '' | ||
+ | |||
+ | <code bash> | ||
+ | (it_css: | ||
+ | Adding package `anaconda/ | ||
+ | </ | ||
+ | |||
+ | After loading the Anaconda software, we will want create the Jupyter Notebook virtual environment. In this example we will call it '' | ||
+ | |||
+ | <code bash> | ||
+ | [(it_css: | ||
+ | Channels: | ||
+ | - jupyter | ||
+ | - conda-forge | ||
+ | - nodefaults | ||
+ | Platform: linux-64 | ||
+ | Collecting package metadata (repodata.json): | ||
+ | Solving environment: | ||
+ | |||
+ | ## Package Plan ## | ||
+ | |||
+ | environment location: / | ||
+ | |||
+ | added / updated specs: | ||
+ | - jupyter | ||
+ | - python=3 | ||
+ | |||
+ | |||
+ | The following packages will be downloaded: | ||
+ | |||
+ | package | ||
+ | ---------------------------|----------------- | ||
+ | : | ||
+ | jupyter-1.1.1 | ||
+ | jupyter-lsp-2.2.5 | ||
+ | jupyter_client-8.6.3 | ||
+ | jupyter_console-6.6.3 | ||
+ | jupyter_core-5.7.2 | ||
+ | jupyter_events-0.11.0 | ||
+ | jupyter_server-2.15.0 | ||
+ | jupyter_server_terminals-0.5.3| | ||
+ | jupyterlab-4.3.5 | ||
+ | jupyterlab_pygments-0.3.0 | ||
+ | jupyterlab_server-2.27.3 | ||
+ | jupyterlab_widgets-3.0.13 | ||
+ | : | ||
+ | yaml-0.2.5 | ||
+ | zeromq-4.3.5 | ||
+ | zipp-3.21.0 | ||
+ | zstandard-0.23.0 | ||
+ | zstd-1.5.6 | ||
+ | ------------------------------------------------------------ | ||
+ | | ||
+ | |||
+ | The following NEW packages will be INSTALLED: | ||
+ | |||
+ | : | ||
+ | jupyter | ||
+ | jupyter-lsp | ||
+ | jupyter_client | ||
+ | jupyter_console | ||
+ | jupyter_core | ||
+ | jupyter_events | ||
+ | jupyter_server | ||
+ | jupyter_server_te~ conda-forge/ | ||
+ | jupyterlab | ||
+ | jupyterlab_pygmen~ conda-forge/ | ||
+ | jupyterlab_server | ||
+ | jupyterlab_widgets conda-forge/ | ||
+ | : | ||
+ | yaml | ||
+ | zeromq | ||
+ | zipp | ||
+ | zstandard | ||
+ | zstd | ||
+ | | ||
+ | | ||
+ | Proceed ([y]/n)? y | ||
+ | |||
+ | |||
+ | Downloading and Extracting Packages | ||
+ | ... | ||
+ | ... | ||
+ | Preparing transaction: | ||
+ | Verifying transaction: | ||
+ | Executing transaction: | ||
+ | # | ||
+ | # To activate this environment, | ||
+ | # > conda activate / | ||
+ | # | ||
+ | # To deactivate an active environment, | ||
+ | # > conda deactivate | ||
+ | # | ||
+ | $ | ||
+ | </ | ||
+ | |||
+ | ==== VALET Package Definition ==== | ||
+ | |||
+ | The new virtual environment can easily be added to your login shell and job runtime environments using VALET. Ensure you have a workgroup VALET package definition directory present: | ||
+ | |||
+ | <code bash> | ||
+ | [(it_css: | ||
+ | [(it_css: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Take note of the path echoed, then create a new file named '' | ||
+ | |||
+ | <code yaml> | ||
+ | jupyter-notebook: | ||
+ | prefix: / | ||
+ | description: | ||
+ | flags: | ||
+ | - no-standard-paths | ||
+ | actions: | ||
+ | - action: source | ||
+ | script: | ||
+ | sh: anaconda-activate-2024.sh | ||
+ | order: failure-first | ||
+ | success: 0 | ||
+ | versions: | ||
+ | " | ||
+ | description: | ||
+ | dependencies: | ||
+ | - anaconda/ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | ===== Using Jupyter Notebook Virtual Environment ===== | ||
+ | |||
+ | The versions of the virtual environment declared in the VALET package are listed using the '' | ||
+ | |||
+ | <code bash> | ||
+ | [(it_css: | ||
+ | |||
+ | Available versions in package (* = default version): | ||
+ | |||
+ | [/ | ||
+ | jupyter-notebook | ||
+ | * 20240801 | ||
+ | </ | ||
+ | |||
+ | Activating the virtual environment is accomplished using the '' | ||
+ | |||
+ | <code bash> | ||
+ | [(it_css: | ||
+ | Adding dependency `anaconda/ | ||
+ | Adding package `jupyter-notebook/ | ||
+ | (/ | ||
+ | </ | ||
+ | |||
+ | ===== Running Jupyter Notebook on the Caviness Cluster ===== | ||
+ | |||
+ | Running Jupyter Notebook on Caviness, or any HPC cluster for that matter, takes some extra steps. You can simply install Jupyter Notebook on your personal laptop and start it up. On Caviness, you need to run the Jupyter Notebook on a compute node. The steps below will show you how to request an interactive compute node and use VALET to load the Jupyter Notebook virtual environment. After starting the virtual environment, | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | ==== Requesting an interactive job ==== | ||
+ | In this example we will request an interactive job to connect us to a compute node with 2GB of memory for 1 hour on the '' | ||
+ | <code bash> | ||
+ | [(it_css: | ||
+ | </ | ||
+ | |||
+ | ==== Loading the Jupyter Notebook virtual environment ==== | ||
+ | After the interactive job has been established, | ||
+ | <code bash> | ||
+ | [[traine@r00n50 1201]$ vpkg_require jupyter-notebook/ | ||
+ | Adding dependency `anaconda/ | ||
+ | Adding package `jupyter-notebook/ | ||
+ | (/ | ||
+ | </ | ||
+ | |||
+ | <note tip>Once the Jupyter Notebook virtual environment has been loaded on the interactive compute node session, your prompt should look something like this: | ||
+ | |||
+ | '' | ||
+ | |||
+ | </ | ||
+ | ==== Starting Jupyter Notebook session ==== | ||
+ | When starting the Jupyter Notebook session, specific options are passed, which are used to set up the tunnel connection. | ||
+ | |||
+ | <code bash> | ||
+ | [traine@r04n68 1201]$ jupyter notebook --no-browser --ip=$(hostname -s) | ||
+ | ... | ||
+ | ... | ||
+ | ... | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [I 2024-08-01 15: | ||
+ | [C 2024-08-01 15: | ||
+ | |||
+ | To access the server, open this file in a browser: | ||
+ | file:/// | ||
+ | Or copy and paste one of these URLs: | ||
+ | http:// | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | <note warning> | ||
+ | The Jupyter Notebook server is running and there is no prompt. **Make sure you copy the line noted above and it will be used later by changing the compute node to '' | ||
+ | < | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Setting up SSH tunnel to connect to Jupyter Notebook server ==== | ||
+ | With the Jupyter Notebook server running on a compute node on Caviness, an SSH tunnel is needed to be able to make a connection and access the Jupyter Notebook server from a web browser on your local machine. This is done by opening a **second** SSH connection to Caviness. Follow the appropriate section below for Windows (PuTTY) or Terminal on a Linux/Mac laptop. | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | ==Windows (PuTTY)== | ||
+ | Once you open the PuTTY, it will show the //Session// window. For the //Host Name(or IP Address)//, you will need to enter the ''< | ||
+ | In addition to your standard connection PuTTY settings, you will need to set up the tunnel setting. This is easily done by loading an existing session you have saved for Caviness and then adding the tunnel settings based on the image below. The tunnel setting is found under the Category // | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Add the **Source port** as '' | ||
+ | {{ : | ||
+ | ==Linux/ | ||
+ | Open a new terminal session on your local machine. Set up a SSH Tunnel using the below '' | ||
+ | < | ||
+ | |||
+ | $ ssh -L 8888: | ||
+ | ...................................................................... | ||
+ | |||
+ | |||
+ | Caviness cluster (caviness.hpc.udel.edu) | ||
+ | |||
+ | This computer system is maintained by University of Delaware | ||
+ | IT. Links to documentation and other online resources can be | ||
+ | found at: | ||
+ | |||
+ | http:// | ||
+ | |||
+ | For support, please contact consult@udel.edu | ||
+ | |||
+ | |||
+ | ...................................................................... | ||
+ | |||
+ | Last login: Thu Aug 1 12:28:19 2024 | ||
+ | [traine@login00 ~]$ | ||
+ | </ | ||
+ | ==== Using your local browser to access Jupyter Notebook server | ||
+ | If everything this far has been set up correctly the final step is as easy as opening a web browser of choice on your local machine and entering the correct URL. If you followed the directions exactly, you can now use the URL from above changing the compute node to '' | ||
+ | |||
+ | **Example URL:** | ||
+ | '' | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | |||
+ | |||
+ | |||