Skip to content

Visual Studio Code

Warning

Please, take into account that while you are allowed to connect any IDE to the cluster, you are not allowed to execute code on the login nodes as it might do unusable the cluster for other users.

Visual Studio Code

Visual Studio Code, also commonly referred to as VS Code, is an integrated development environment developed by Microsoft for Windows, Linux, macOS and web browsers. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded version control with Git. Users can change the theme, keyboard shortcuts, preferences, and install extensions that add functionality.

Connecting VSCode to the cluster

In order to connect VS Code to the cluster, you must do it to one of the compute nodes. If you connect it directly to one of the login nodes, you risk to be banned by the abuse of resources.

1. Prepare VSCode for the connection

Install the "Remote SSH" extension from Microsoft. Open the extensions tab, search for it and install it.

Once installed, we are going to configure it to connect to a comupting node on the cluster with an SSH tunnel.

2. Asking a node to Slurm

In order to execute VS Code, you must do it in one of the compute nodes. To do that, you need to ask for resources to the SLURM scheduler and connect to the node with an SSH tunnel. To avoid problems in case several users are executing VS Code on the computing node, we have created a module that you can use to execute your own SSH server on the compute node. You can use it with the following slurm batch script:

#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=test
#SBATCH --cpus-per-task=2
#SBATCH --ntasks=2
#SBATCH --mem=16gb
#SBATCH --time=08:00:00

# The following module gives access to the ssh-server-start.sh command
module load DIPC-Utils/0.0.1

# Execute ssh server on the compute node
ssh-server-start.sh

To execute it, you can use the following command:

sbatch test.slurm

Once your job has been granted with resources, you will see the following output on its output file with instructions to connect to the node:

11:06:57-user@hyperion-login-02:~$ cat slurm-826208.out
Selecting a random available port...
Selected port 11332.
Using existing SSH configuration file.
Starting custom SSH server on port 11332...
SSHD started successfully with PID 5671.
==============================================================
Custom SSH Server Started
==============================================================
Hostname: hyperion-260
Port: 11332
==============================================================
To securely connect to the custom SSH server, set up SSH tunneling:
1. Run the following command on your local machine:

   ssh -L <local-port>:hyperion-260:11332 user@hyperion.sw.ehu.es -N

2. Connect your SSH client to 'localhost:<local-port>'.

   ssh -p <local-port> cperezmig@localhost
==============================================================
Running under SLURM job ID: 826208

Now is time to open an SSH tunnel.

3. Using an SSH tunnel to connect to the cluster

Open a terminal on your local PC and execute the following command:

ssh -L 2222:hyperion-260:11332 USER@hyperion-01.sw.ehu.es -N

Warning

  • Change hyperion-260 by the node granted by Slurm on the previous step.
  • Change USER by your cluster user.
  • Change PORT by the port shown by ssh-server-start.sh.
  • You'll need to recreate this SSH tunnel every time you connect to the system.

This will open an SSH tunnel to the computing node's port 22 using your local 2222 port. If your local 2222 port is in use by another service, select another one (12222 for example).

Now, configure your system to connect to the tunnel. Open the file ~/.ssh/config and add the following lines to it:

Host hyperion-tunnel
  HostName localhost
  Port 2222
  User USER

Warning

Change "USER" by the user you are using on your local PC.

This file will instruct VS Code to connect to the port 2222 of your local PC.

4. Open a connection on VS Code

  • Open the "Remote Explorer" on VS Code. You should see your new tunnel on the available connections.
  • Select the connection and open it.
  • Browse the server to the path in which you intend to keep your code.
  • Work as you would do locally

Possible problems

Take into account that most of the software you may need is not accessible by default by using this method. To access it, you'll need to load it in the "module" tool. As there isn't any way to tell VS Code to execute module load you'll need to place your module load command onto you .bashrc file onto your cluster account.

In case of problems with the ssh-server-start.sh command, you can also ask for a node with salloc and create the tunnel to the 22 node port:

salloc --nodes=1 --ntasks=4 --qos=regular --time=8:00:00 --mem=20GB \
 srun --pty /bin/bash
ssh -L 2222:hyperion-260:22 USER@hyperion-01.sw.ehu.es -N

Example - Executing a Jupyter notebook on the cluster

While there is already a way of using Jupyter notebooks on the DIPC clusters, here we are going to explain how we can do it with VS Code. These are the steps:

  • Load the required modules before opening VS Code. To do that, place the following line on your .bashrc:
    module load Python
    
  • Open VS Code and connect to the cluster following this guide.
  • Open your Jupyter notebook and try to execute it.
  • It may complain about not having selected a kernel. Press at "Select Another Kernel":
  • On the new window, select "Python Environments"
  • Then select the "base" conda env. That is the one that is loaded with "module load Python".
    !!! Warning Don't select the recommended kernel.

If you follow these steps, now you'll be able to execute your jupyter notebook if all the required python modules are installed correctly.