Overview

This guide shows how to run Jupyter notebooks in VS Code using SLURM computational resources on a cluster environment.

Prerequisites

  • VS Code with Remote SSH extension
  • Connected to the cluster via VS Code Remote SSH
  • Python environment with Jupyter installed

Step 1: Request Interactive SLURM Session

In VS Code terminal, run:

srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bash

Resource Options:

  • --partition=gpu_devel - Development partition with GPU
  • --partition=cpu - CPU-only partition (for data analysis)
  • --partition=gpu_h200 - Production GPU partition
  • --mem=16G - Adjust memory as needed
  • --cpus-per-task=2 - Adjust CPU cores as needed
  • --time=02:00:00 - Adjust time limit as needed

Step 2: Start JupyterLab

Once in the interactive session:

jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --allow-root

Note the output: Copy the URL with token (e.g., http://localhost:8888/?token=abc123...)

Step 3: Connect VS Code to Jupyter Server

  1. Open your .ipynb file in VS Code
  2. Click “Select Kernel” in the top-right corner
  3. Choose “Existing Jupyter Server”
  4. Paste the Jupyter URL from Step 2
  5. VS Code will connect and you can run cells directly!

Method 2: Direct Python Kernel (No Jupyter Server)

Step 1: Get Interactive Session

srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bash

Step 2: Use VS Code’s Built-in Jupyter

  1. Open your .ipynb file in VS Code
  2. Click “Select Kernel”
  3. Choose “Python Environments”
  4. Select the Python interpreter from the compute node
  5. Run cells directly - no server needed!

Method 3: One-liner Launch

For quick setup:

srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bash -c "
cd /path/to/your/project && 
jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --allow-root
"

Common Resource Configurations

For Data Analysis (No GPU needed)

srun --partition=cpu --mem=16G --cpus-per-task=2 --time=02:00:00 --pty bash

For ML Training (GPU required)

srun --partition=gpu_h200 --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=08:00:00 --pty bash

For Large Dataset Processing

srun --partition=gpu_h200 --mem=64G --cpus-per-task=8 --time=04:00:00 --pty bash

Troubleshooting

Error: QOSMinGRES

  • Issue: GPU partition requires GPU resources
  • Solution: Add --gres=gpu:1 or use CPU partition

Error: Port already in use

  • Solution: Use different port: --port=8889 or --port=8890

Error: Unable to allocate resources

  • Solution: Reduce resource requirements or try different partition

Connection Issues

  • Check: VS Code port forwarding is working
  • Alternative: Use ssh -L 8888:compute_node:8888 user@login_node

Best Practices

  1. Resource Management:

    • Request only what you need
    • Use CPU partition for data analysis
    • Reserve GPU partition for ML workloads
  2. Time Limits:

    • Start with shorter time limits
    • Extend if needed using scontrol
  3. Port Management:

    • Use different ports for multiple sessions
    • Check netstat -tuln | grep 8888 for port availability
  4. Environment Setup:

    • Activate conda/virtual environments before starting Jupyter
    • Set proper environment variables if needed

Example Session

# 1. Request resources
srun --partition=gpu_devel --gres=gpu:1 --mem=32G --cpus-per-task=4 --time=05:00:00 --pty bash
 
# 2. Activate environment (if needed)
source ~/.bashrc
conda activate your_env
 
# 3. Navigate to project
cd /path/to/your/project
 
# 4. Start JupyterLab
jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --allow-root
 
# 5. In VS Code: Select Kernel → Existing Jupyter Server → Paste URL

Benefits of This Approach

  • ✅ No browser required - Everything runs in VS Code
  • ✅ Full computational resources - Access to requested CPUs/GPUs/memory
  • ✅ Integrated development - VS Code debugging, Git, extensions
  • ✅ Interactive computing - Real-time feedback and visualization
  • ✅ Resource isolation - Dedicated resources for your session

This method gives you the full power of SLURM resources while maintaining the familiar VS Code interface for notebook development.