Visual Studio Code: Difference between revisions

From Alliance Doc
Jump to navigation Jump to search
(Marked this version for translation)
No edit summary
Line 6: Line 6:
<!--T:2-->
<!--T:2-->
When using an IDE like Visual Studio Code, it's important to distinguish what sort of action you're performing, even if all of them take place within the context of the IDE. Editing a Python script or any other text file of reasonable size (up to a few thousand lines) is a very light-weight process which requires little processing power or memory but an IDE offers you numerous other possibilities, including the ability to debug your script for example. In this case, the IDE is now ''executing'' your Python code on the shared login node and until the script crashes because of a bug, it may well consume an entire CPU core or even several if the script or the libraries which it uses are multi-threaded.
When using an IDE like Visual Studio Code, it's important to distinguish what sort of action you're performing, even if all of them take place within the context of the IDE. Editing a Python script or any other text file of reasonable size (up to a few thousand lines) is a very light-weight process which requires little processing power or memory but an IDE offers you numerous other possibilities, including the ability to debug your script for example. In this case, the IDE is now ''executing'' your Python code on the shared login node and until the script crashes because of a bug, it may well consume an entire CPU core or even several if the script or the libraries which it uses are multi-threaded.
Note that if you are using Visual Studio Code with Python, you should avoid installing [[Anaconda/en|Conda and its variants]] as they are poorly adapted to our cluster environment. Alternatives to the use of Conda include [[Python#Creating_and_using_a_virtual_environment|Python virtual environments]] and [[Apptainer]].


=Configuring remote access= <!--T:3-->
=Configuring remote access= <!--T:3-->

Revision as of 19:16, 12 January 2024

Other languages:

Visual Studio Code is an integrated development environment (IDE) from Microsoft which can be used for remote development with Compute Canada clusters over SSH. In this context, users can run the graphical interface of Visual Studio Code locally, on their personal computer, while connecting to a cluster where the source code is located and where the debugging and testing operations are being executed. While Visual Studio Code may be used for development in a variety of programming languages, in this page we will focus on its use with Python.

When using an IDE like Visual Studio Code, it's important to distinguish what sort of action you're performing, even if all of them take place within the context of the IDE. Editing a Python script or any other text file of reasonable size (up to a few thousand lines) is a very light-weight process which requires little processing power or memory but an IDE offers you numerous other possibilities, including the ability to debug your script for example. In this case, the IDE is now executing your Python code on the shared login node and until the script crashes because of a bug, it may well consume an entire CPU core or even several if the script or the libraries which it uses are multi-threaded.

Note that if you are using Visual Studio Code with Python, you should avoid installing Conda and its variants as they are poorly adapted to our cluster environment. Alternatives to the use of Conda include Python virtual environments and Apptainer.

Configuring remote access[edit]

Configuration of your SSH keys[edit]

  1. If not done already, generate your SSH key. For example, we will name it ~/.ssh/ccdb.
  2. If not done already, install your public SSH key on CCDB.
  3. Because compute nodes may not get your public SSH key from CCDB through LDAP, you may have to copy your public key to ~/.ssh/authorized_keys on the remote cluster (create this file if it does not exist).

SSH configuration file[edit]

VS Code works well with your local SSH configuration file (~/.ssh/config). Here are the recommended options :

File : ~/.ssh/config

Host *
  ServerAliveInterval 300

Host beluga cedar graham narval
  HostName %h.alliancecan.ca
  IdentityFile ~/.ssh/ccdb
  User your_username

Host bc????? bg????? bl?????
  ProxyJump beluga
  IdentityFile ~/.ssh/ccdb
  User your_username

Host cdr*
  ProxyJump cedar
  IdentityFile ~/.ssh/ccdb
  User your_username

Host gra1* gra2* gra3* gra4* gra5* gra6* gra7* gra8* gra9*
  ProxyJump graham
  IdentityFile ~/.ssh/ccdb
  User your_username

Host nc????? ng????? nl?????
  ProxyJump narval
  IdentityFile ~/.ssh/ccdb
  User your_username


First connection with VS Code[edit]

Because some clusters do not provide access to Internet from compute nodes, the installation of VS Code Server must be done prior to using a remote connection to any compute node. Therefore, in VS Code, a first connection to any frontal node is required - select either :

  • beluga
  • cedar
  • graham
  • narval

Note 1 : you will be prompted many times for your SSH key passphrase. If not, make sure to copy your SSH public key as described in a previous section.

Note 2 : If you are using some multifactor authentication, you may need to check the "Details" of the connection, which will bring you to the VS Code Terminal in which you may be prompted for your 2nd factor of authentication.

That first connection will automatically install VS Code Server in ~/.vscode-server/. The installation can take up to 5 minutes. Once done, close the connection.

Connection to a compute node[edit]

Connection procedure:

  1. Make sure VS Code Server is installed as described in the previous section.
  2. Start a new interactive job (with salloc) and take note of the allocated compute node name.
    1. Important: make sure to request enough memory (at least 2000M).
  3. In VS Code, start a new remote session with the name of the allocated compute node:
    1. Press F1 or Ctrl+Shift+P to start the command prompt > in the Command Palette.
    2. Start typing and select Remote-SSH: Connect to Host...: > Remote-SSH: Connect to Host...
    3. Enter the noted compute node name.
      1. If you get prompted for the type of operating system, select Linux

See also[edit]