Jupyter on VSCode

Accessing Jupyter Notebooks is fairly straight forward on VSCode. Through the tunneling used by our base VSCode guide, you are able to start an interactive session requesting for the resources needed and use it in your notebook for heavily computational analysis.

 

Here’s an example:

  1. We can start by creating a custom conda environment that has the packages that you need:

(base) [anl14042@login4 ~]$ conda create --name vscode_notebook python=3.9
  1. Then start an interactive session and tunnel to connect to VSCode:

(base) [anl14042@login4 ~]$ srun --ntasks=12 --nodes=1 --partition=general --time=6:00:00 --exclusive --pty bash srun: job 5407517 queued and waiting for resources srun: job 5407517 has been allocated resources
  1. Load VSCode and start the tunnel:

(base) [anl14042@cn471 ~]$ module purge (base) [anl14042@cn471 ~]$ module load vscode/ Loading vscode/2024 Loading requirement: slurm/slurm/22.05.9 pre-module post-module (base) [anl14042@cn471 ~]$ tunnel * * Visual Studio Code Server * * By using the software, you agree to * the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and * the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement). * ✔ How would you like to log in to Visual Studio Code? · Microsoft Account To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ******** to authenticate.
  1. Once you’re signed in, either begin using the browser version or go back to your desktop VSCode.

We’ll create a directory and work within it:

  1. Connect to your tunnel in VSCode:

image-20240123-174409.png
  1. Sign in, navigate to your directory of choice. Then create a jupyter notebook (File, New File):

image-20240123-174656.png
  1. Now click “Select Kernel” and then “Python Enviroments” to find your custom conda environments!

  1. Select the environment we created earlier “vscode_notebook” with python 3.9.

Let’s test it! Click the “play” or run button to run the cell.

  1. You may be asked to install some things, click yes and install all.

  1. Remember to exit your VSCode using “ctrl+c” and to end your interactive session when you’re done!