13  Using VS Code as an MPlus Editor

This is for users willing to wade into the details of software configuration. This is worthwhile if you use MPlus on Linstat a lot, but is probably a bit much if you are an MPlus beginner.

It might also be for you if you are already a VS Code user.

For users familiar with VS Code, there is an extension called language-mplus that will provide highlighting of MPlus key words (however, it is incomplete). VS Code can also be configured with an “MPlus via Slurm” task (explained below). So, with some set up, you can write your code on Linstat and submit it via Slurm, all from the same interface.

13.1 An MPlus Slurm Task for VS Code

To configure VS Code to submit MPlus jobs via Slurm, you need to create a “task”.

The task described here uses SSCC ssubmit script, and prompts you to specify the number of cores, amount of memory, and partition for your Slurm job.

13.1.1 Set Up

Copy the following code into a file named tasks.json, and save this file in a folder named .vscode in your linux home directory, or in the folder (VS Code “workspace”) where you keep all your MPlus files. For example, I have a file

/home/h/hemken/MPlus/.vscode/tasks.json

with the contents

{
    // SSCC Slurm task for MPlus
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run Mplus via Slurm",
            "type": "process",
            "command": "ssubmit",
            "args": ["-L mplus", 
                "--cores=${input:slurmcores}",
                "--mem=${input:slurmmem}G", 
                "--partition=${input:slurmpart}",
                " mplus ${fileBasename}"],
            "options": {
                "cwd": "${fileDirname}"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "inputs": [
      {
        "id": "slurmcores",
        "type": "promptString",
        "description": "SLURM CORES",
        "default": "1"
        // type specific configuration attributes
      },
      {
        "id": "slurmmem",
        "type": "promptString",
        "description": "SLURM MEMORY (GB)",
        "default": "2"
        // type specific configuration attributes
      },
      {
        "id": "slurmpart",
        "type": "promptString",
        "description": "SLURM PARTITION",
        "default": "short"
        // type specific configuration attributes
      }
    ]
}

13.1.2 Use

To submit an MPlus job via Slurm:

  • Connect VS Code to Linstat
  • Use the VS Code Explorer to find the MPlus input file you want to submit. Select the file in the Explorer.
  • In the Command box at the top of VS Code, click once and pick Run Task.
  • Select Run MPlus via Slurm
  • You will be prompted to fill in the number of processors, amount of memory, and Slurm partition that Slurm should use. The number of processors should be the same as specified within your MPlus code (see above).

Once the job has been submitted, you can close out VS Code and head for the Terrace.

14 Using Rstudio Server as an MPlus Editor

For users familiar with RStudio Server on Linstat, it is possible to use RStudio as a simple text editor and the built in terminal to submit Slurm jobs. It should be possible to use the MplusAutomation and SlurmR packages to further automate running multiple MPlus models, but we haven’t worked out the details.

The advantage of using MplusAutomation is it’s ability to set up arrays of MPlus jobs, and also it’s ability to parse MPlus output for creating tables or calculating post-estimation statistics.

14.1 MPlus Job Arrays

Slurm is an ideal tool for running multiple scripts that use similar parameters. However, MPlus does not include any macro processing facility for setting model parameters dynamically - each input file must be written and saved to disk, separately. If you have a lot of this sort of work to do, it could be worthwhile learning two more tools.

Using the MPlusAutomation package for R is a good tool for writing similar MPlus input files. Use MPlusAutomation::createModels to create MPlus input files with sequentially numbered names.

Then use sbatch at the Linux command prompt to specify a Slurm job array to run multiple MPlus jobs simultaneously.

While both of these tools are beyond the scope of this note, hopefully this will point you in the right direction!