Running locally in a conda environment 🐍
Short tutorial on running locally using an "Anaconda" environment.
Last updated
Short tutorial on running locally using an "Anaconda" environment.
Last updated
Follow all the steps in the section to ensure you have access to the correct files needed to run your model with flepiMoP.
Take note of the location of the directory on your local computer where you cloned the flepiMoP model code (which we'll call FLEPI_PATH
).
conda
environmentOne of simplest ways to get everything to work is to build an Anaconda environment. Install (or update) Anaconda on your computer. We find that it is easiest to create your conda environment by installing required python packages, then installing R packages separately once your conda environment has been built as not all R packages can be found on conda.
You can either use the command line (here) or the graphical user interface (you just tick the packages you want). With the command line it's this one-liner:
Anaconda will take some time, to come up with a proposal that works with all dependencies. This creates a conda
environment named flepimop-env
that has all the necessary python packages.
The next step in preparing your environment is to install the necessary R packages. First, activate your environment, launch R and then install the following packages.
If you'd like, you can install rstudio
as a package as well.
Activate your conda environment, which we built above.
In this conda
environment, commands with R and python will uses this environment's R and python.
Since you'll be navigating frequently between the folder that contains your project code and the folder that contains the core flepiMoP model code, it's helpful to define shortcuts for these file paths. You can do this by creating environmental variables that you can then quickly call instead of writing out the whole file path.
If you're on a Mac or Linux/Unix based operating system, define the FLEPI_PATH and PROJECT_PATH environmental variables to be your directory locations, for example
or, if you have already navigated to your flepiMoP directory
You can check that the variables have been set by either typing env
to see all defined environmental variables, or typing echo $FLEPI_PATH
to see the value of FLEPI_PATH
.
If you're on a Windows machine
or, if you have already navigated to your flepiMoP directory
You can check that the variables have been set by either typing set
to see all defined environmental variables, or typing echo $FLEPI_PATH$
to see the value of FLEPI_PATH
.
Other environmental variables can be set at any point in process of setting up your model run. These options are listed in ... ADD ENVAR PAGE
For example, some frequently used environmental variables we recommend setting are:
Everything is now ready. 🎉
The next step depends on what sort of simulation you want to run: One that includes inference (fitting model to data) or only a forward simulation (non-inference). Inference is run from R, while forward-only simulations are run directly from the Python package gempyor
.
In either case, navigate to the project folder and make sure to delete any old model output files that are there.
An inference run requires a configuration file that has an inference
section. Stay in the $PROJECT_PATH
folder, and run the inference script, providing the name of the configuration file you want to run (ex. config.yml
).
The last few lines visible on the command prompt should be:
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
NULL
If you want to quickly do runs with options different from those encoded in the configuration file, you can do that from the command line, for example
where:
n
is the number of parallel inference slots,
j
is the number of CPU cores to use on your machine (if j
> n
, only n
cores will actually be used. If j
< n
, some cores will run multiple slots in sequence)
k
is the number of iterations per slots.
Stay in the $PROJECT_PATH
folder, and run a simulation directly from forward-simulation Python package gempyor
. To do this, call flepimop simulate
providing the name of the configuration file you want to run (ex. config.yml
). An example config is provided in $PROJECT_PATH/config_sample_2pop_interventions.yml.
It is currently required that all configuration files have an interventions
section. There is currently no way to simulate a model with no interventions, though this functionality is expected soon. For now, simply create an intervention that has value zero.
You can also try to knit the Rmd file in flepiMoP/flepimop/gempyor_pkg/docs
which will show you how to analyze these files.
This will run the model and create in $PROJECT_PATH/model_output/
.