1. IDModeling server tips - HopkinsIDD/gavi_vimc_cholera GitHub Wiki

Note: This file is based on my personal experience with using the "idmodeling" server to run the VIMC core model. These tips also apply to running the surveillance model. Some tips included here may come in handy when you are doing something similar, but I would suggest referring to the Best-practice Wiki page to understand it more systematically if you have the access.

Log in and the most important Linux commands

If you are using the Ubuntu or the SSH service on VS Code, the first thing you could do is to use your account to log in to connect to the server (our JHU cluster, IDModeling). Then you could check if you are on the server and which directory you are in by looking at the terminal command line, which will give you something like: <your account>@idmodeling:~$. The part in front of the colon tells you that you are using your own account, and you are already successfully connected to the server. The other part indicates which directory you are in: the ~ simplifies the home directory available and accessible to you for your current log-in, while the pathway following ~ tells you more about the directory you are in more specifically; the dollar sign indicates the beginning of your command line, where you could start typing in Linux command.

While you could always learn about Linux commands online, you may find some very basic Linux commands very relevant to our project and convenient to use. The pwd returns you the most detailed version of the directory you are in right now, which also tells you your own home directory usually covered by ~. The cd command can help you change your current directory if you specify a new directory after it, which may look like: cd ~/NewProject/New_Folder_1. Likewise, cd ~ will bring you back to your home directory. It might be worth mentioning that it’s best not to leave any spaces/blanks in the names of your directories/folders and your files because it’s tricky to handle names likes that in the Linux system. A little tip to save your time is by using “.” to represent your current directory instead of typing in the whole pathway: e.g., if I want to change from ~/NewProject to ~/NewProject/New_Folder_1, I can just type in cd ./New_Folder_1. The ls pr ls -a command tells you what folders and files you have under your current directory. The rm or rm -r command helps you remove certain files or folders, but it’s not recommended to use too often since you can never get them back after you delete your files from the server permanently.

srun --pty --mem=3G --nodelist=idmodeling<1 or 2 or 3> bash must be used every single time before you run anything interactively on the server to prevent the server from a break-down. squeue tells you all the ongoing jobs. scancel <job id> allows you to cancel any of your jobs. sinfo -o "%14P %15N %5a %13C %8e/%8m %T" tells you the availability of the server. scp and rsync help you transfer files or the whole folder between servers or between a server and a local machine.

Recommended file manager software that you could use

We always need to upload and download files to and from the server, which can be done by using commands, but we could also use files manager software to make it easier, safer, and more convenient. With intuitive graphical user interface, the WinSCP application is very popular and easy to download, install, and use. You could get it using this link.

R packages installment

Now that we can get the files and folders ready in our server, there is only one step away from running some R code for us. If this is your first time to install R packages into the server, you may need to set up your own directory on the server to save all your packages by going through an interactive session where you can initialize installment. To start the session, you may need to run srun --pty bash or ssh [email protected] first, which is going to bring you from “idmodeling” to “idmodeling2”, where the R is installed and can be used. When you are on idmodeling2, you could freely open up your R environment and install the packages you need, but because we didn’t specify the memory we want to have in the srun --pty bash command, we can’t really run anything heavy currently but to set up our own R packages directory, since some R packages may need lots of resources to install. How to run R code in different kinds of ways is covered in the next step. Typically, we can get into R environment by typing in R in the command line when we are on idmodeling2. Then we can just type in install.packages(“<Your package>”) to initialize the interactive session.

Sometimes we may get error message when we are running this step because the current version of R language being used in the server is by default 3.4, which is a little bit old for some of the packages we want to install. To cope with this issue, we could alter the R version by typing in /opt/R/4.0.3/bin/R to change it from 3.4 to 4.0.3. After typing this into the command line, we will be in the R environment with 4.0.3 version of R and able to install most of the packages being used in the model.

Another error message you may get from running this step, is the one that might tell you that you are running out of memory in the middle of installing packages. This makes sense since we didn’t specify a decent amount of memory that we want to use when we run the code srun --pty bash. To solve this, we can easily assign more memory by typing in srun -n4 --mem=1G --time=100:00:00 --pty bash, for instance. Details of how to use srun and sbatch are covered in this tutorial.

If you just want to directly run R code in the R environment, this is basically all you need to know for package installment. But if you want to run R code in other ways, like using Rscript command in Linux or using sbatch, there is a little more to pay attention to. If we want to run one whole R script or a few R scripts without getting into the R environment, we could try Rscript command followed by the name of the R script, or use sbatch to run multiple R scripts in the non-interactive manner. However, because we are running R code outside of the R environment, we cannot respond to R’s request of specifying the mirror from which we want to download the new package, which will lead to the failure in installment. To get around this issue, we could use this R code: chooseCRANmirror(ind = 78), to pre-specify the mirror in the R script which tells the server what R packages we want to download for the model. Of course, the code of the mirror can be altered to others.

Ways to run our R code

There are different ways to run our R code. The most straightforward and intuitive way is to get into the R environment and copy-paste your local code to the server. It’s also possible to run the whole R script inside the R environment and the code you need is as follows:

setwd('/folder/where/the/file/is/')
source('Rscript_name.R')

Details of how to use srun and sbatch are covered in this tutorial. However, Rscript calls R version of 3.4 by default. To show this, we could try to type Rscript --version in the command line to confirm. To call another version of R, we can instead use /opt/R/4.0.3/bin/Rscript, which will help us start using 4.0.3 R language for the Rscript command when we want to run R code in the non-interactive way.

How to check the status of the server

If we want to check if the server is running the mission we submitted or if there is enough resource left in the server for us to utilize, we could try using the following two lines of code:

squeue
sinfo -o "%14P %15N %5a %13C %8e/%8m %T"

If we know the job id of our submitted job/mission, we could use the command scancel <job id> to cancel a certain job easily.

How to use the screen

Sometimes if we want to run one or more missions and exit the server without quitting the ongoing job, besides using sbatch, we could try to use the screen function already installed in the idmodeling server. Here are the commonly used commands (case sensitive):

-	Ctrl+a c -- Create a new window (with shell).
-	Ctrl+a " -- List all windows.
-	Ctrl+a A -- Rename the current window.
-	Ctrl+a d -- To detach
-	Ctrl+a k -- To kill a screen session
-	screen -ls -- To see all running screen sessions 
-	screen -r -- 12345 To resume one of them
⚠️ **GitHub.com Fallback** ⚠️