VS Code
Overview
VS Code is a free editor from Microsoft, which is open source and support many useful extensions.
It may be a good alternative to terminal based editors (like vim, nano and Emacs) for some of our users.
Benefits
Work with files on cluster, almost as if they would be on your own laptop
Great syntax highlighting, linting, etc. for many languages (using extensions). Tools for debuging
Extensions simplifying work with git (recommended: Git Graphs)
Graphs produced on server, can be viewed directly withing VS Code
When you are done editing - you can run sbatch job from terminal panel of VS Code
You can set up port forwarding
And more
Using VS Code
IMPORTANT: don't run computations in VS Code!
Use VS Code only to edit scripts, use linting, etc.
Only run calculations using srun/sbatch
Download and Install
Download and install it on your local machine: download
Setting Up Remote Connections to HPC cluster
Make sure you activated NYU VPN
VS Code Lock files shall NOT be saved in /home. Ways to achieve that
In extensions tab of VS Code find extension "Remote - SSH"
press settings icon -> Extension settings
Do one of the following:
Don’t use lock files (uncheck "Remote.SSH: Use Flock")
Store lock file in /tmp (check Remote.SSH: Lockfiles In Tmp)
Inside VS Code
F1
remote-ssh: Connect to Host
New host (or - Configure SSH host)
ssh <user>@greene.hpc.nyu.edu
specify the path to the file, where the configuration of this connection will be saved
More details here: https://code.visualstudio.com/docs/remote/ssh
Login using ssh key
Instead of typing your password every time you need to log in, you can also specify an ssh key.
Only do that on the computer you trust
Generate ssh key pair (terminal in Linux/Mac or cmd/WSL in Windows): https://www.ssh.com/ssh/keygen/
Note the path to ssh key files. Don't share key files with anybody - anybody with this key file can login to your account
Log into cluster using regular login/password and then add the content of generated public key file (the one with .pub) to $HOME/.ssh/authorized_keys on cluster
Next time you will log into cluster no password will be required.
How to Connect VS Code to a Greene Compute Node
Sometimes users want to connect their VS Code GUI to a compute node, such as to launch a Jupyter Notebook file on Greene. This requires several steps to properly route through Greene's login nodes to the compute nodes in use. Please follow these instructions to connect and run VSCode server on Greene compute node:
On Greene login node, submit a dummy Slurm job to sleep there, 1 CPU core and 1GB memory for 2 hours. This step will enable you to login to compute nodes you have jobs running there.
sbatch --time=02:00:00 --mem=1GB --wrap "sleep infinity"After the job is running, please check the compute node this job is running there with squeue
[sw77@log-1 tmp]$ squeue -u sw77
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
23587213 cpu_gpu wrap sw77 R 18:29 1 gr070
In this example, the job is running on gr070On your local computer, add this block to ~/.ssh/config file
Host greene-compute
HostName <Compute Node your Jupyter Notebook is using e.g. gr070>
User <NetID>
ProxyJump <NetID>@greene.hpc.nyu.edu
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
LogLevel ERROR
Here the ProxyJump is <NetID>@greene, if you are in campus, please change to YourNYUNetID@greene.hpc.nyu.edu. Please be sure to be connected to the NYU VPN (vpn.nyu.edu).Set up ssh login to Greene with ssh key without password (see section above)
Now from VSCode, you can directly connect to greene-compute nodes with:
ssh greene-compute
More settings
VS Code has many more settings and options. Explore!
Additional notes
High CPU load on login node from VS Code
You may notice (please check with 'top') that your VS Code connection causes 'node' process running from your user to use a lot of CPU resources. One of the reason leading to that - large number of files within your home directory. Try to remove conda and pip environments from the home directory and check if this will resolve the issue.
Python
Recommended extensions: Python, Anaconda Extension Pack
When those are installed you can switch python env or conda env by clicking on the left bottom line specifying python.
Support for python scripts and Jupyter Notebooks
Syntax highlighting: extension MagicPython