arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

Running with docker on AWS - OLD probably outdated

circle-exclamation

This page, along with the other AWS run guides, are not deprecated in case we need to run flepiMoP on AWS again in the future, but also are not maintained as other platforms (such as longleaf and rockfish) are preferred for running production jobs.

For large simulations, running the model on a cluster or cloud computing is required. AWS provides a good solution for this, if funding or credits are available (AWS can get very expensive).

hashtag
Introduction

This document contains instructions for setting up and running the two different kinds of SEIR modeling jobs supported by the COVIDScenarioPipeline repository on AWS:

  1. Inference jobs, using AWS Batch to coordinate hundreds/thousands of jobs across a fleet of servers, and

  2. Planning jobs, using a single relatively large EC2 instance (usually an r5.24xlarge) to run one or more planning scenarios on a single high-powered machine.

Most of the steps required to setup and run the two different types of jobs on AWS are identical, and I will explicitly call out the places where different steps are required. Throughout the document, we assume that your client machine is a UNIX-like environment (e.g., OS X, Linux, or WSL).

hashtag
Local Client Setup

I need a few things to be true about the local machine that you will be using to connect to AWS that I'll outline here:

  1. You have created and downloaded a .pem file for connecting to an EC2 instance to your ~/.ssh directory. When we provision machines, you'll need to use the .pem file as a secret key for connecting. You may need to change the permission of the .pem file:

  2. You have created a ~/.ssh/config file that contains an entry that looks like this so we can use staging as an alias for your provisioned EC2 instance in the rest of the runbook:

hashtag
Provisioning The Staging Server

If you are running an Inference job, you should use a small instance type for your staging server (e.g., an m5.xlarge will be more than enough.) If you are running a Planning job, you should provision a beefy instance type (I am especially partial to the memory-and-CPU heavy r5.24xlarge, but given how fast the planning code has become, an r5.8xlarge should be perfectly adequate.)

If you have access to the jh-covid account, you should use the IDD Staging AMI (ami-03641dd0c8554e5d0) to provision and launch new staging servers; it is already setup with all of the dependencies described in this section, however you will need to alter it's default network settings, iam role and security group(Please refer in details). You can find the AMI , select it, and press the Launch button to walk you through the Launch Wizard to choose your instance type and .pem file to provision your staging server. When going through the Launch Wizard, be sure to select Next: Configure Instance details instead of Review and Launch. You will need to continue selecting the option that is not Review and Launch until you have selected a security group. In these screens, most of the default options are fine, but you will want to set the HPC VPC network, choose a public subnet (it will say public or private in the name), and set the iam role to EC2S3FullAccess on the first screen. You can also name the machine by providing a Name tag in the tags screen. Finally, you will need to set your security group to dcv_usa

If you are having connection timeout issues when trying to ssh into the AWS machine, you should check that you have SSH TCP Port 22 permissions in the dcv_usa/ security group.

If you do not have access to the jh-covid account, you should walk through the regular EC2 Launch Wizard flow and be sure to choose the Amazon Linux 2 AMI (HVM), SSD Volume Type (ami-0e34e7b9ca0ace12d, the 64-bit x86 version) AMI. Once the machine is up and running and you can SSH to it, you will need to run the following code to install the software you will need for the rest of the run:

hashtag
Connect to Github

Once your staging server is provisioned and you can connect to it, you should scp the private key file that you use for connecting to Github to the /home/ec2-user/.ssh directory on the staging server (e.g., if the local file is named ~/.ssh/id_rsa, then you should run scp ~/.ssh/id_rsa staging:/home/ec2-user/.ssh to do the copy). For convenience, you should create a /home/ec2-user/.ssh/config file on the staging server that has the following entry:

This way, the git clone, git pull, etc. operations that you run on the staging server will use your SSH key without constantly prompting you to login. Be sure to chmod 600 ~/.ssh/config to give the new file the correct permissions. You should now be able to clone a COVID19 data repository into your home directory on the staging server to do work against. For this example, to use the COVID19_Minimal repo, run:

to get it onto the staging server. By convention, we do runs with the COVIDScenarioPipeline repository nested inside of the data repository, so we then do:

to clone the modeling code itself into a child directory of the data repository.

hashtag
Getting and Launching the Docker Container

The previous section is only for getting a minimal set of dependencies setup on your staging server. To do an actual run, you will need to download the Docker container that contains the more extensive set of dependencies we need for running the code in the COVIDScenarioPipeline repository. To get the development container on your staging server, please run:

There are multiple versions of the container published on DockerHub, but latest-dev contains the latest-and-greatest dependencies and can support both Inference and Planning jobs. In order to launch the container and run a job, we need to make our local COVID19_Minimal directory visible to the container's runtime. For Inference jobs, we do this by running:

The -v option to docker run maps a file in the host filesystem (i.e., the path on the left side of the colon) to a file in the container's filesystem. Here, we are mapping the /home/ec2-user/COVID19_Minimal directory on the staging server where we checked out our data repo to the /home/app/src directory in the container (by convention, we run commands inside of the container as a user named app.) We also map our .ssh directory from the host filesystem into the container so that we can interact with Github if need be using our SSH keys. Once the container is launched, we can cd src; ls -ltr to look around and ensure that our directory mapping was successful and we see the data and code files that we are expecting to run with.

Once you are in the src directory, there are a few final steps required to install the R packages and Python modules contained within the COVIDScenarioPipeline repository. First, checkout the correct branch of COVIDScenarioPipeline. Then, assuming that you created a COVIDScenarioPipeline directory within the data repo in the previous step, you should be able to run:

to install the local R packages and then install the Python modules.

Once this step is complete, your machine is properly provisioned to run Planning jobs using the tools you normally use (e.g., make_makefile.R or running simulate.py and hospdeath.R directly, depending on the situation.) Running Inference jobs requires some extra steps that are covered in the next two sections.

hashtag
Running Inference Jobs

Once the container is setup from the previous step, we are ready to test out and then launch an inference job against a configuration file (I will use the example of config.yml for the rest of this document.) First, I setup and run the build_US_setup.R script against my configuration file to ensure that the mobility data is up to date:

Next, I kick off a small local run of the full_filter.R script. This serves two purposes: first, we can verify that the configuration file is in good shape and can support a few small iterations of the inference calculations before we kick off hundreds/thousands of jobs via AWS Batch. Second, it downloads the case data that we need for inference calculations to the staging server so that it can be cached locally and used by the batch jobs on AWS- if we do not have a local cache of this data at the start of the run, then every job will try to download the data itself, which will force the upstream server to deny service to the worker jobs, which will cause all of the jobs to fail. My small runs usually look like:

This will run two sequential simulations (-k 2) for a single slot (-n 1) using a single CPU core (-j 1), looking for the modeling source code in the COVIDScenarioPipeline directory (-p COVIDScenarioPipeline). (We need to use the command line arguments here to explicitly override the settings of these parameters inside of config.yml since this run is only for local testing.) Assuming that this run succeeds, we are ready to kick off a batch job on the cluster.

The COVIDScenarioPipeline/batch/inference_job.py script will use the contents of the current directory and the values of the config file and any commandline arguments we pass it to launch a run on AWS Batch via the AWS API. To run this script, you need to have access to your so that you can enable access to the API by running aws configure at the command line, which will prompt you to enter your access key, secret, and preferred region, which should always be us-west-2 for jh-covid runs. (You can leave the Default format entry blank by simply hitting Enter.) IMPORTANT REMINDER: (Do not give anyone your access key and secret. If you lose it, deactivate it on the AWS console and create a new one. Keeep it safe.)

The simplest way to launch an inference job is to simply run

This will use the contents of the config file to determine how many slots to run, how many simulations to run for each slot, and how to break those simulations up into blocks of batch jobs that run sequentially. If you need to override any of those settings at the command line, you can run

to see the full list of command line arguments the script takes and how to set them.

One particular type of command line argument cannot be specified in the config: arguments to resume a run from a previously submitted run. This takes two arguments based on the previous run:

Both the s3 bucket and run id are printed as part of the output for the previous submission. We store that information on a slack channel #csp-production, and suggest other groups find similar storage.

Inference jobs are parallelized by NPI scenarios and hospitalization rates, so if your config file defines more than one top-level scenario or more than one set of hospitalization parameters, the inference_job.py script will kick off a separate batch job for the cross product of scenarios * hospitalizations. The script will announce that it is launching each job and will print out the path on S3 where the final output for the job will be written. You can monitor the progress of the running jobs using either the or by running:

which will show you the running status of the jobs in each of the queues.

hashtag
Operating Inference Jobs

By default, the AWS Batch system will usually run around 50% of your desired simultaneously executable jobs concurrently for a given inference run. For example, if you are running 300 slots, Batch will generally run about 150 of those 300 tasks at a given time. If you need to force Batch to run more tasks concurrently, this section provides instructions for how to cajole Batch into running harder.

You can see how many tasks are running within each of the different corresponding to the via the . There is a one-to-one correspondence between Job Queues, Compute Environments, and ECS Clusters (the matching ones all end with the same numeric identifier.) You can force Batch to scale up the number of CPUs available for running tasks by selecting the radio button corresponding to the compute environment that you want to scale on the , clicking Edit, increasing the Desired CPU (and possibly the Minimum CPU, see below), and clicking the Save button. You will be able to see new containers and tasks coming online via the ECS Dashboard after a few minutes.

If you want to force new tasks to come online ASAP, you should consider increasing the Minimum CPU for the Compute Environment as well as the Desired CPU (the Desired CPU is not allowed to be lower than the Minimum CPU, so if you increase the Minimum you must increase the Desired as well to match it.) This will cause Batch to spin new containers up quickly and get them populated with running tasks. There are two downsides to doing this: first, it overrides the allocation algorithm that makes cost/performance tradeoff decisions in favor of spending more money in order to get more tasks running. Second, you must remember to update the Compute Environment towards the end of the job run to set the Minimum CPU to zero again so that the ECS cluster can spin down when the job is finished; if you do not do this, ECS will simply leave the machines up and running, wasting money without doing any actual work. (Note that you should never manually try to lower the value of the Desired CPU setting for the Compute Environment- the Batch system will throw an error if you attempt to do this.)

You can connect to Github via SSH.arrow-up-right This is important because we will need to use your Github SSH key to interact with private repositories from the staging server on EC2.

and/or
dcv_usa2
. You can then finalize the machine initialization with
Review and Launch
. Once your instance is provisioned, be sure to put its IP address into the
HostName
section of the
~/.ssh/config
file on your local client so that you can connect to it from your client by simply typing
ssh staging
in your terminal window.
this page
herearrow-up-right
AWS access keysarrow-up-right
AWS Batch Dashboardarrow-up-right
Batch Compute Environmentsarrow-up-right
Batch Job Queuesarrow-up-right
Elastic Container Service (ECS) Dashboardarrow-up-right
Batch Compute Environment dashboardarrow-up-right
chmod 400 ~/.ssh/<your .pem file goes here>
host staging
HostName <IP address of provisioned server goes here>
IdentityFile ~/.ssh/<your .pem file goes here>
User ec2-user
IdentitiesOnly yes
StrictHostKeyChecking no 
sudo yum -y update
sudo yum -y install awscli 
sudo yum -y install git 
sudo yum -y install docker.io 
sudo yum -y install pbzip2 

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
sudo yum -y install git-lfs
git lfs install
host github.com
 HostName github.com
 IdentityFile ~/.ssh/id_rsa
 User git
git clone git@github.com:HopkinsIDD/COVID19_Minimal.git
cd COVID19_Minimal
git clone git@github.com:HopkinsIDD/COVIDScenarioPipeline.git
sudo docker pull hopkinsidd/covidscenariopipeline:latest-dev
sudo docker run \
  -v /home/ec2-user/COVID19_Minimal:/home/app/src \
  -v /home/ec2-user/.ssh:/home/app/.ssh \
  -it hopkinsidd/covidscenariopipeline:latest-dev
Rscript COVIDScenarioPipeline/local_install.R
(cd COVIDScenarioPipeline/; python setup.py install)
export CENSUS_API_KEY=<your census api key>
cd COVIDScenarioPipeline
git lfs pull
cd ..
Rscript COVIDScenarioPipeline/R/scripts/build_US_setup.R -c config.yml
Rscript COVIDScenarioPipeline/R/scripts/full_filter.R -c config.yml -k 2 -n 1 -j 1 -p COVIDScenarioPipeline
./COVIDScenarioPipeline/batch/inference_job.py -c config.yml
./COVIDScenarioPipeline/batch/inference_job.py --help
./COVIDScenarioPipeline/batch/inference_job.py --restart-from-s3-bucket=s3://idd-inference-runs/USA-20210131T170334/ --restart-from-run-id=2021.01.31.17:03:34.
./COVIDScenarioPipeline/batch/inference_job_status.py

Provisioning AWS EC2 instance

circle-exclamation

This page, along with the other AWS run guides, are not deprecated in case we need to run flepiMoP on AWS again in the future, but also are not maintained as other platforms (such as longleaf and rockfish) are preferred for running production jobs.

hashtag
Signing in to AWS Management Consol ;

Click on below:

Sign in as IAM user with your given Accound ID, username and Password

Then the next view appears, check "regeon" as "Oregon" by default and "user@Accond ID" as you expeced.

If you have already accessed AWS console, these kinds of view can be seen. In the case select "EC2" to go to "EC2 Dashboard"(if not, skip it).

hashtag
EC2 Dashboard

In this EC2 Dashboard, we can maintain the EC2 boxes from creation to deletion. In this section, how to create an EC2 instance from the AMI image which has already been registered is shown.

Select "Images>AMIs" in the right pane(Navigation pain) ;

Select an AMI name which name is "IDD Staging AMI" in the "Amazon Machine Images (AMIs)" by clicking the responding AMI checkbox on the left, then push the "Launch instance from AMI" button (colored in orange).

hashtag
Launch an instance

To create an EC2 instance, fill out the items as below (example):

  • Name and tags

    • input an appropriate name (e.g., "sample_box01")

  • Application and OS image

  • Advanced details

    • "EC2S3FullAccess" should be setected in IAM instance profile, but to do it an authentication (IAM role or policy) must be set on to the working IAM account

then push "Launch Instance" button which is located at the bottom right side of the scree ;

check whether "AMI from catalog" is _"IDD Staging AMI" (for example; select one as you want) ;

  • Instance type

    • as you selected by drop-down list(e.g., m5.xlarge)

  • Key pair(login ;

    • you can generate new key pair if you want to connect to the instance securely (by clicking "Create new key pair" on the right side), but usually select "ams__ks_ED25519__keypair" by drop-down list so that you can be helped when local client setup (recommended).

      • In case that you use your own key, you will be the only person to log in, of course. you should be careful of handling key management ;

  • Network settings (push the button "Edit" on the right to extend configuration; see below)

    • VPC - required

      • select "HPC VPC" item by drop-down menu

    • Subnet

      • select "HPC Public Subnet among _"us-west-2*" ;

    • Firewall (security groups)

      • select "Select existing security grous" toggle, then

      • Common security groups

  • Sign in as IAM user
    Console Home
    EC2 Dashboard
    Select an AMI Image among Amazon Machine Images(AMIs)
    Network settings
    Advanced details
    Launch Instance in Summary
    When in Success
    select "dvc_usa" and "dvc__usa2" by drop-down menu
    Manage AWS Resources - AWS Management Console - AWSAmazon Web Services, Inc.chevron-right
    Logo

    AWS Submission Instructions: COVID-19

    circle-exclamation

    This page, along with the other AWS run guides, are not deprecated in case we need to run flepiMoP on AWS again in the future, but also are not maintained as other platforms (such as longleaf and rockfish) are preferred for running production jobs.

    hashtag
    Step 1. Create the configuration file.

    see Building a configuration file

    hashtag
    Step 2. Start and access AWS submission box

    Spin up an Ubuntu submission box if not already running. To do this, log onto AWS Console and start the EC2 instance.

    Update IP address in .ssh/config file. To do this, open a terminal and type the command below. This will open your config file where you can change the IP to the IP4 assigned to the AWS EC2 instance (see AWS Console for this):

    SSH into the box. In the terminal, SSH into your box. Typically we name these instances "staging", so usually the command is:

    hashtag
    Step 3. Setup the environment

    Now you should be logged onto the AWS submission box.

    Update the github repositories. In the below example we assume you are running mainbranch in Flu_USA andmainbranch in COVIDScenarioPipeline. This assumes you have already loaded the appropriate repositories on your EC2 instance. Have your Github ssh key passphrase handy so you can paste it when prompted (possibly multiple times) with the git pull command. Alternatively, you can add your github key to your batch box so you do not have to log in repeated (see X).

    Initiate the docker. Start up and log into the docker container, pull the repos from Github, and run setup scripts to setup the environment. This setup code links the docker directories to the existing directories on your box. As this is the case, you should not run job submission simultaneously using this setup, as one job submission might modify the data for another job submission.

    hashtag
    Step 4. Model Setup

    To run the via AWS, we first run a setup run locally (in docker on the submission EC2 box) ;

    Setup environment variables. Modify the code chunk below and submit in the terminal. We also clear certain files and model output that get generated in the submission process. If these files exist in the repo, they may not get cleared and could cause issues. You need to modify the variable values in the first 4 lines below. These include the SCENARIO, VALIDATION_DATE, COVID_MAX_STACK_SIZE, and COMPUTE_QUEUE. If submitting multiple jobs, it is recommended to split jobs between 2 queues: Compartment-JQ-1588569569 and Compartment-JQ-1588569574.

    If not resuming off previous run:

    If resuming from a previous run, there are an additional couple variables to set. This is the same for a regular resume or continuation resume. Specifically:

    • RESUME_ID - the COVID_RUN_INDEX from the run resuming from.

    Preliminary model run. We do a setup run with 1 to 2 iterations to make sure the model runs and setup input data. This takes several minutes to complete, depending on how complex the simulation will be. To do this, run the following code chunk, with no modification of the code required:

    hashtag
    Step 5. Launch job on AWS batch

    Configure AWS. Assuming that the simulations finish successfully, you will now enter credentials and submit your job onto AWS batch. Enter the following command into the terminal ;

    You will be prompted to enter the following items. These can be found in a file called new_user_credentials.csv ;

    • Access key ID when prompted

    • Secret access key when prompted

    • Default region name: us-west-2

    • Default output: Leave blank when this is prompted and press enter (The Access Key ID and Secret Access Key will be given to you once in a file)

    Launch the job. To launch the job, use the appropriate setup based on the type of job you are doing. No modification of these code chunks should be required.

    NOTE: Resume and Continuation Resume runs are currently submitted the same way, resuming from an S3 that was generated manually. Typically we will also submit any Continuation Resume run specifying --resume-carry-seeding as starting seeding conditions will be manually constructed and put in the S3.

    Carrying seeding (do this to use seeding fits from resumed run):

    Discarding seeding (do this to refit seeding again):

    hashtag
    Step 6. Document the Submission

    Commit files to GitHub. After the job is successfully submitted, you will now be in a new branch of the population repo. Commit the ground truth data files to the branch on GitHub and then return to the main branch:

    Save submission info to slack. We use a slack channel to save the submission information that gets outputted. Copy this to slack so you can identify the job later. Example output:

    RESUME_S3 - the S3 bucket where this previous run is stored
    Single Iteration + Carry seeding (do this to produce additional scenarios where no fitting is required):
    notepad .ssh/config
    ssh staging
    cd COVID19_USA
    git config --global credential.helper cache
    git pull 
    git checkout main
    git pull
    
    cd flepiMoP
    git pull	
    git checkout main
    git pull
    cd .. 
    sudo docker pull hopkinsidd/flepimop:latest-dev
    sudo docker run -it \
      -v /home/ec2-user/COVID19_USA:/home/app/drp/COVID19_USA \
      -v /home/ec2-user/flepiMoP:/home/app/drp/flepiMoP \
      -v /home/ec2-user/.ssh:/home/app/.ssh \
    hopkinsidd/flepimop:latest-dev  
        
    cd ~/drp/COVID19_USA
    git config credential.helper store 
    git pull 
    git checkout main
    git pull
    git config --global credential.helper 'cache --timeout 300000'
    
    cd ~/drp/flepiMoP 
    git pull 
    git checkout main
    git pull 
    
    Rscript build/local_install.R && 
       python -m pip install --upgrade pip &&
       pip install -e flepimop/gempyor_pkg/ && 
       pip install boto3 && 
       cd ..
    export FLEPI_RUN_INDEX=FCH_R16_lowBoo_modVar_ContRes_blk4_FCH_Dec11_tsvacc && 
       export VALIDATION_DATE="2022-12-11" && 
       export COVID_MAX_STACK_SIZE=1000 && 
       export COMPUTE_QUEUE="Compartment-JQ-1588569574" &&
       export CENSUS_API_KEY=c235e1b5620232fab506af060c5f8580604d89c1 && 
       export FLEPI_RESET_CHIMERICS=TRUE &&
       rm -rf model_output data/us_data.csv data-truth &&
       rm -rf data/mobility_territories.csv data/geodata_territories.csv &&
       rm -rf data/seeding_territories.csv && 
       rm -rf data/seeding_territories_Level5.csv data/seeding_territories_Level67.csv
    export CONFIG_NAME=config_$SCENARIO.yml && 
       export CONFIG_PATH=/home/app/drp/COVID19_USA/$CONFIG_NAME && 
       export FLEPI_PATH=/home/app/drp/flepiMoP && 
       export PROJECT_PATH=/home/app/drp/COVID19_USA && 
       export INTERVENTION_NAME="med" && 
       export FLEPI_STOCHASTIC=FALSE && 
       rm -rf $PROJECT_PATH/model_output $PROJECT_PATH/us_data.csv && 
       cd $PROJECT_PATH && 
       Rscript $FLEPI_PATH/R/scripts/build_US_setup.R -c $CONFIG_NAME && 
       Rscript $FLEPI_PATH/R/scripts/build_covid_data.R -c $CONFIG_NAME && 
       Rscript $FLEPI_PATH/R/scripts/full_filter.R -c $CONFIG_NAME -j 1 -n 1 -k 1 && 
       printenv CONFIG_NAME
    aws configure
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $FLEPI_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE &&
    printenv CONFIG_NAME
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $FLEPI_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE -j 1 -k 1 &&
    printenv CONFIG_NAME
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $FLEPI_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE --resume-carry-seeding --restart-from-location=s3://idd-inference-runs/$RESUME_S3 --restart-from-run-id=$RESUME_ID &&
    printenv CONFIG_NAME
    export CONFIG_PATH=$CONFIG_NAME &&  
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE --resume-discard-seeding --restart-from-location=s3://idd-inference-runs/$RESUME_S3 --restart-from-run-id=$RESUME_ID &&
    printenv CONFIG_NAME
    git add data/ 
    git config --global user.email "[email]" 
    git config --global user.name "[github username]" 
    git commit -m"scenario run initial" 
    branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
    git push --set-upstream origin $branch
    
    git checkout main
    git pull
    Setting number of output slots to 300 [via config file]
    Launching USA-20220923T160106_inference_med...
    Resuming from run id is SMH_R1_lowVac_optImm_2018 located in s3://idd-inference-runs/USA-20220913T000opt
    Discarding seeding results
    Final output will be: s3://idd-inference-runs/USA-20220923T160106/model_output/
    Run id is SMH_R1_highVac_optImm_2022
    Switched to a new branch 'run_USA-20220923T160106'
    config_SMH_R1_highVac_optImm_2022.yml
    export FLEPI_RUN_INDEX=FCH_R16_lowBoo_modVar_ContRes_blk4_Dec18_tsvacc && 
       export VALIDATION_DATE="2022-12-18" && 
       export COVID_MAX_STACK_SIZE=1000 && 
       export COMPUTE_QUEUE="Compartment-JQ-1588569574" &&
       export CENSUS_API_KEY=c235e1b5620232fab506af060c5f8580604d89c1 && 
       export FLEPI_RESET_CHIMERICS=TRUE &&
       rm -rf model_output data/us_data.csv data-truth &&
       rm -rf data/mobility_territories.csv data/geodata_territories.csv &&
       rm -rf data/seeding_territories.csv && 
       rm -rf data/seeding_territories_Level5.csv data/seeding_territories_Level67.csv
       
    export RESUME_LOCATION=s3://idd-inference-runs/USA-20230423T235232
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE --resume-carry-seeding --restart-from-location=s3://idd-inference-runs/$RESUME_S3 --restart-from-run-id=$RESUME_ID -j 1 -k 1 &&
    printenv CONFIG_NAME

    AWS Submission Instructions: Influenza

    circle-exclamation

    This page, along with the other AWS run guides, are not deprecated in case we need to run flepiMoP on AWS again in the future, but also are not maintained as other platforms (such as longleaf and rockfish) are preferred for running production jobs.

    hashtag
    Step 1. Create the configuration file.

    see Building a configuration file

    hashtag
    Step 2. Start and access AWS submission box

    Spin up an Ubuntu submission box if not already running. To do this, log onto AWS Console and start the EC2 instance.

    Update IP address in .ssh/config file. To do this, open a terminal and type the command below. This will open your config file where you can change the IP to the IP4 assigned to the AWS EC2 instance (see AWS Console for this):

    SSH into the box. In the terminal, SSH into your box. Typically we name these instances "staging", so usually the command is:

    hashtag
    Step 3. Setup the environment

    Now you should be logged onto the AWS submission box.

    Update the github repositories. In the below example we assume you are running mainbranch in Flu_USA andmainbranch in COVIDScenarioPipeline. This assumes you have already loaded the appropriate repositories on your EC2 instance. Have your GitHub ssh key passphrase handy so you can paste it when prompted (possibly multiple times) with the git pull command. Alternatively, you can add your github key to your batch box so you do not have to log in repeated (see X).

    Initiate the docker. Start up and log into the docker container, pull the repos from GitHub, and run setup scripts to setup the environment. This setup code links the docker directories to the existing directories on your box. As this is the case, you should not run job submission simultaneously using this setup, as one job submission might modify the data for another job submission.

    hashtag
    Step 4. Model Setup

    To run the via AWS, we first run a setup run locally (in docker on the submission EC2 box) ;

    Setup environment variables. Modify the code chunk below and submit in the terminal. We also clear certain files and model output that get generated in the submission process. If these files exist in the repo, they may not get cleared and could cause issues. You need to modify the variable values in the first 4 lines below. These include the SCENARIO, VALIDATION_DATE, COVID_MAX_STACK_SIZE, and COMPUTE_QUEUE. If submitting multiple jobs, it is recommended to split jobs between 2 queues: Compartment-JQ-1588569569 and Compartment-JQ-1588569574.

    If not resuming off previous run:

    If resuming from a previous run, there are an additional couple variables to set. This is the same for a regular resume or continuation resume. Specifically:

    • RESUME_ID - the COVID_RUN_INDEX from the run resuming from.

    Preliminary model run. We do a setup run with 1 to 2 iterations to make sure the model runs and setup input data. This takes several minutes to complete, depending on how complex the simulation will be. To do this, run the following code chunk, with no modification of the code required:

    hashtag
    Step 5. Launch job on AWS batch

    Configure AWS. Assuming that the simulations finish successfully, you will now enter credentials and submit your job onto AWS batch. Enter the following command into the terminal ;

    You will be prompted to enter the following items. These can be found in a file called new_user_credentials.csv ;

    • Access key ID when prompted

    • Secret access key when prompted

    • Default region name: us-west-2

    • Default output: Leave blank when this is prompted and press enter (The Access Key ID and Secret Access Key will be given to you once in a file)

    Launch the job. To launch the job, use the appropriate setup based on the type of job you are doing. No modification of these code chunks should be required.

    NOTE: Resume and Continuation Resume runs are currently submitted the same way, resuming from an S3 that was generated manually. Typically we will also submit any Continuation Resume run specifying --resume-carry-seeding as starting seeding conditions will be manually constructed and put in the S3.

    Carrying seeding (do this to use seeding fits from resumed run):

    Discarding seeding (do this to refit seeding again):

    NOTE: A Resume and Continuation Resume are currently submitted the same way, but with --resume-carry-seeding specified and resuming from an S3 that was generated manually.

    hashtag
    Step 6. Document the Submission

    Commit files to Github. After the job is successfully submitted, you will now be in a new branch of the population repo. Commit the ground truth data files to the branch on github and then return to the main branch:

    Save submission info to slack. We use a slack channel to save the submission information that gets outputted. Copy this to slack so you can identify the job later. Example output:

    RESUME_S3 - the S3 bucket where this previous run is stored
    Single Iteration + Carry seeding (do this to produce additional scenarios where no fitting is required):
    notepad .ssh/config
    ssh staging
    cd Flu_USA
    git config --global credential.helper cache
    git pull 
    
    cd COVIDScenarioPipeline
    git pull	
    git checkout main
    git pull
    cd ..
    sudo docker pull hopkinsidd/covidscenariopipeline:latest-dev
    sudo docker run -it \
      -v /home/ec2-user/Flu_USA:/home/app/drp \
      -v /home/ec2-user/Flu_USA/COVIDScenarioPipeline:/home/app/drp/COVIDScenarioPipeline \
      -v /home/ec2-user/.ssh:/home/app/.ssh \
    hopkinsidd/covidscenariopipeline:latest-dev  
        
    cd ~/drp 
    git config credential.helper store 
    git pull 
    git checkout main
    git config --global credential.helper 'cache --timeout 300000'
    
    cd ~/drp/COVIDScenarioPipeline 
    git pull 
    git checkout main
    git pull 
    
    Rscript local_install.R && 
       python -m pip install --upgrade pip &&
       pip install -e gempyor_pkg/ && 
       pip install boto3 && 
       cd ~/drp
    export SCENARIO=FCH_R1_highVac_pesImm_2022_Oct30 && 
       export VALIDATION_DATE="2022-10-16" && 
       export COVID_MAX_STACK_SIZE=1000 && 
       export COMPUTE_QUEUE="Compartment-JQ-1588569574" &&
       export CENSUS_API_KEY=c235e1b5620232fab506af060c5f8580604d89c1 && 
       export COVID_RESET_CHIMERICS=TRUE &&
       rm -rf model_output data/us_data.csv data-truth &&
       rm -rf data/mobility_territories.csv data/geodata_territories.csv &&
       rm -rf data/seeding_territories.csv
    export COVID_RUN_INDEX=$SCENARIO && 
       export CONFIG_NAME=config_$SCENARIO.yml && 
       export CONFIG_PATH=/home/app/drp/$CONFIG_NAME && 
       export COVID_PATH=/home/app/drp/COVIDScenarioPipeline && 
       export PROJECT_PATH=/home/app/drp && 
       export INTERVENTION_NAME="med" && 
       export COVID_STOCHASTIC=FALSE && 
       rm -rf $PROJECT_PATH/model_output $PROJECT_PATH/us_data.csv &&
       rm -rf $PROJECT_PATH/seeding_territories.csv && 
       cd $PROJECT_PATH && Rscript $COVID_PATH/R/scripts/build_US_setup.R -c $CONFIG_NAME && 
       Rscript $COVID_PATH/R/scripts/build_flu_data.R -c $CONFIG_NAME && 
       Rscript $COVID_PATH/R/scripts/full_filter.R -c $CONFIG_NAME -j 1 -n 1 -k 1 && 
       printenv CONFIG_NAME
    aws configure
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE &&
    printenv CONFIG_NAME
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE -j 1 -k 1 &&
    printenv CONFIG_NAME
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE --resume-carry-seeding --restart-from-location=s3://idd-inference-runs/$RESUME_S3 --restart-from-run-id=$RESUME_ID &&
    printenv CONFIG_NAME
    export CONFIG_PATH=$CONFIG_NAME &&  
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE --resume-discard-seeding --restart-from-location=s3://idd-inference-runs/$RESUME_S3 --restart-from-run-id=$RESUME_ID &&
    printenv CONFIG_NAME
    git add data/ 
    git config --global user.email "[email]" 
    git config --global user.name "[github username]" 
    git commit -m"scenario run initial" 
    branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
    git push --set-upstream origin $branch
    
    git checkout main
    git pull
    Setting number of output slots to 300 [via config file]
    Launching USA-20220923T160106_inference_med...
    Resuming from run id is SMH_R1_lowVac_optImm_2018 located in s3://idd-inference-runs/USA-20220913T000opt
    Discarding seeding results
    Final output will be: s3://idd-inference-runs/USA-20220923T160106/model_output/
    Run id is SMH_R1_highVac_optImm_2022
    Switched to a new branch 'run_USA-20220923T160106'
    config_SMH_R1_highVac_optImm_2022.yml
    export SCENARIO=FCH_R1_highVac_pesImm_2022_Nov27 && 
       export VALIDATION_DATE="2022-11-27" && 
       export COVID_MAX_STACK_SIZE=1000 && 
       export COMPUTE_QUEUE="Compartment-JQ-1588569574" &&
       export CENSUS_API_KEY=c235e1b5620232fab506af060c5f8580604d89c1 && 
       export COVID_RESET_CHIMERICS=TRUE &&
       rm -rf model_output data/us_data.csv data-truth &&
       rm -rf data/mobility_territories.csv data/geodata_territories.csv &&
       rm -rf data/seeding_territories.csv
       
    export RESUME_ID=FCH_R1_highVac_pesImm_2022_Nov20 &&
      export RESUME_S3=USA-20221120T194228
    export CONFIG_PATH=$CONFIG_NAME &&
    cd $PROJECT_PATH &&
    $COVID_PATH/batch/inference_job.py -c $CONFIG_PATH -q $COMPUTE_QUEUE --resume-carry-seeding --restart-from-location=s3://idd-inference-runs/$RESUME_S3 --restart-from-run-id=$RESUME_ID -j 1 -k 1 &&
    printenv CONFIG_NAME