Run Jupyter on a Compute Node in VS Code

  1. Follow the Remote SSH to Delta in VS Code instructions.

    You should now be on a Delta login node, which is not recommended for running big programs; the remaining steps will get you onto a compute node.

  2. Install the Jupyter and Python VS Code extensions, if they aren’t already installed.

    The python and jupyter extensions in the VS Code extensions marketplace.
  3. From the VS Code Terminal menu, open a New Terminal.

  4. Run the following to see the available anaconda modules:

  5. Load the anaconda module that you want to use, the following example installs anaconda3_cpu.

  6. Run the following command to verify Jupyter is in your path:

  7. Select one of the following tabs to connect to a compute node using srun or sbatch.

    1. Generate a MYPORT number and copy it to a notepad (you will use it in a subsequent step).

      MYPORT=$(($(($RANDOM % 10000))+49152)); echo $MYPORT
      
    2. Find the account name that you are going to use and copy it to a notepad. Your available accounts are listed under Project when you run the accounts command. Note, to use a GPU compute node, you must pick a GPU account (the account name will end in “-gpu”).

    3. Run the following srun command, with these replacements:

      • Replace <account_name> with the account you are going to use, which you found and copied in the previous step.

      • Replace <MYPORT> with the MYPORT number that you generated in a previous step.

      • Modify the --partition, --time, and --mem options and/or add other options to meet your needs.

      srun --account=<account_name> --partition=cpu-interactive --time=00:30:00 --mem=32g jupyter-notebook --no-browser --port=<MYPORT> --ip=0.0.0.0
      
    4. Copy the last five lines returned, beginning with “To access the notebook, …”

    5. Complete the Connect to a remote Jupyter server instructions.

      Use the first URL that you copied in the previous step as the URL of the running Jupyter Server.

    6. Select the Python 3 kernel (recommended).

    7. You can run !hostnamectl, in a notebook, to verify it is running on a compute node (Static hostname value).

      VS Code Jupyter notebook with a cell that ran !hostnamectl and returned static hostname value of a compute node.

Run a Python Script File (.py) in a Jupyter Interactive Window

After you’ve completed the above steps to connect to Jupyter on a compute node, use the following instructions to run a Python script file (.py) in a Jupyter interactive window.

  1. Open your Python script file in VS Code.

    Adding # %% or # In[] in your python codes splits your code into many Jupyter-like code cells. Because the Jupyter extension is installed, Run cell, Run Below, and Debug Cell will show up before # %% or # In[] for each cell.

  2. Right-click and select Run in an Interactive Window.

    The interactive Jupyter window should now be linked to your .py file. Each time you click Run Cell, your code will run in the window. You may need to select or change your desired python kernel by clicking the kernel select button at the top right.

    Python file opened with the right-click menu opened showing the run in interactive window option.