Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions EMOD/analyze_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SurveyAllAgeAnalyzer(IAnalyzer):
Args:
expt_name (str): Name of the experiment.
sweep_variables (list): List of sweep variables. Defaults to None.
inset_channels (list): List of inset channels. Defaults to None.
channels (list): List of inset channels. Defaults to None.
daily (bool): Flag indicating whether the data is daily. Defaults to False.
working_dir (str): Working directory for the analysis. Defaults to "./".
start_year (int): Start year of the simulation. Defaults to 2022.
Expand Down Expand Up @@ -482,19 +482,19 @@ class AnnualAgebinAnalyzer(IAnalyzer):
and save a results dataframe for defined age groups over time (years).

Parameters:
- expt_name (str): Name of the experiment.
- sweep_variables (list): List of sweep variables. Defaults to None.
- working_dir (str): Working directory for the analysis. Defaults to './'.
- start_year (int): Start year of the simulation experiment. Defaults to 1920.
- end_year (int): End year of the simulation experiment. Defaults to 2020.
- age_groups_aggregates (list): List of age group aggregates. Defaults to None.
- burnin (None or int): Number of burn-in iterations. Defaults to None.
expt_name (str): Name of the experiment.
sweep_variables (list): List of sweep variables. Defaults to None.
working_dir (str): Working directory for the analysis. Defaults to './'.
start_year (int): Start year of the simulation experiment. Defaults to 1920.
end_year (int): End year of the simulation experiment. Defaults to 2020.
age_groups_aggregates (list): List of age group aggregates. Defaults to None.
burnin (None or int): Number of burn-in iterations. Defaults to None.

Saves:
mmmpy_yr.csv

Returns:
None
None: This method does not return a value.
"""

def __init__(self, expt_name, sweep_variables=None, working_dir='./', start_year=1920,
Expand Down Expand Up @@ -806,10 +806,9 @@ class FiveDayAgebinAnalyzer(IAnalyzer):
end_year (int): End year of the simulation experiment. Defaults to 2020.
age_groups_aggregates (list): List of age group aggregates. Defaults to None.
burnin (None or int): Number of burn-in iterations. Defaults to None.
cc (bool): Flag for change in conditions. Defaults to False.

Saves:
mmmpy_5day.csv (or mmmpy_ccstep_daily.csv if cc is True)
mmmpy_5day.csv

Returns:
None
Expand Down
14 changes: 7 additions & 7 deletions EMOD/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ def config_sweep_builder(exp, scen_df):
and configures EMOD simulation parameters related to demographics and mortality.

Args:
task (EMODTask): The EMOD task object that represents the simulation run. The task will be updated with
demographic data and the relevant parameters.
exp (ExperimentConfig): An instance of the `ExperimentConfig` class containing the experiment settings,
including population size and input file paths. This object is used to update the
demographics and configuration for the simulation.
exp (ExperimentConfig): An instance of the `ExperimentConfig` class that contains all the parameters
necessary to configure and run the EMOD simulation. This includes simulation
duration, entomology mode, burn-in period, platform configuration, and more.
scen_df (pandas.DataFrame): A DataFrame containing the scenario data to be used for the experiment.
The dataframe should include the scenario IDs and relevant parameters
that define the experiment conditions.

Returns:
EMODTask: The updated `task` object with demographic and simulation parameters configured.

list[SimulationBuilder]: A list containing the configured simulation builder with all sweep definitions added.
"""
builder = SimulationBuilder()
nseeds = exp.num_seeds
Expand Down
13 changes: 5 additions & 8 deletions OpenMalaria/analyze_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ def parse_args():
specifically for specifying the job directory and an optional experiment ID.
The job directory is required to locate the `exp.obj` file.

Args:
None

Returns:
argparse.Namespace: A Namespace object containing the parsed arguments.
The object has the attribute `directory` which corresponds to the user-provided path
Expand Down Expand Up @@ -192,11 +189,11 @@ def InputEIRAnalyzer(exp, mm, start_year, survey_step_days=30, compr='infer'):
Run the InputEIRAnalyzer for OpenMalaria experiments.

Args:
exp: The experiment object.
mm: The measure map object.
start_year: The start year of the analysis.
survey_step_days: The survey step interval in days (default: 30).
compr: The compression method for saving the output CSV files (default: 'infer').
exp (ExperimentConfig): The experiment configuration object.
mm (dict): The measure map object.
start_year (int): The start year of the analysis.
survey_step_days (int): The survey step interval in days. Defaults to 30.
compr (str): Compression method for saving output CSV files. Defaults to 'infer'.

Saves:
One or more CSV files based on the `daily` flag:
Expand Down
7 changes: 6 additions & 1 deletion OpenMalaria/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def write_sh_OpenMalaria(exp):

# Construct the content of the shell script
sh_content = f"""#!/bin/bash
set -e -o pipefail

# Job settings
job_name="run_openmalaria"
Expand All @@ -365,11 +366,15 @@ def write_sh_OpenMalaria(exp):
# Navigate to the job directory
cd "$jobdir" || exit 1

progress_bar="####################"
printf 'OpenMalaria [%-20s] 0/{exp.nexps} (0%%)' ""
# Run the OpenMalaria simulation for each experiment
for ((i = 1; i <= {exp.nexps}; i++)); do
# Run the OpenMalaria command and log output and errors
"{exp.OPENMALARIA_venv}/openMalaria" -s "$jobdir/xml/$i.xml" --output "txt/$i.txt" >> "$log_dir/run_openmalaria.log" 2>> "$log_dir/run_openmalaria.err" || true
"{exp.OPENMALARIA_venv}/openMalaria" -s "$jobdir/xml/$i.xml" --output "txt/$i.txt" >> "$log_dir/run_openmalaria.log" 2>> "$log_dir/run_openmalaria.err"
printf '\\rOpenMalaria [%-20s] %d/{exp.nexps} (%d%%)' "${{progress_bar:0:$((20 * i / {exp.nexps}))}}" "$i" "$((100 * i / {exp.nexps}))"
done
printf '\\n'

echo "OpenMalaria simulation complete."
"""
Expand Down
19 changes: 13 additions & 6 deletions dependencies/run_mmmpy_docker.bat
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
@echo off
setlocal
REM Check if Docker is installed
where docker >nul 2>nul
IF %ERRORLEVEL% NEQ 0 (
echo Docker is not installed. Please install Docker first.
pause
exit /b
exit /b 1
)

REM Pull the Docker image
docker pull multimalmodpy/mmmpy_local:rocky8
if errorlevel 1 (
echo Docker image download failed. Check that Docker Desktop is running.
pause
exit /b 1
)

REM Ask the user for model names
set /p "MODELS=Enter models to run (e.g. malariasimulation OpenMalaria): "

REM Get two levels up from current directory
for %%i in ("%cd%\..\..") do set "REPO_PATH=%%~fi"
REM Resolve the repository relative to this script.
for %%i in ("%~dp0..") do set "REPO_PATH=%%~fi"

REM Display what will run
echo Running Docker with models: %MODELS%
echo Mounting %REPO_PATH% to /mnt/c/projects
echo Mounting %REPO_PATH% to /mnt/c/projects/MultiMalModPy

REM Escape the MODELS variable for safe injection into bash command
REM We surround %MODELS% with double quotes inside single quotes to preserve spacing

docker run -it --rm ^
-v "%REPO_PATH%:/mnt/c/projects" ^
-v "%REPO_PATH%:/mnt/c/projects/MultiMalModPy" ^
multimalmodpy/mmmpy_local:rocky8 ^
/bin/bash -c "source /opt/envs/mmmpy_local/bin/activate && cd /mnt/c/projects/MultiMalModPy && python launch_sim.py --models %MODELS% --test"

set "RUN_EXIT_CODE=%ERRORLEVEL%"
echo.
pause

exit /b %RUN_EXIT_CODE%
21 changes: 16 additions & 5 deletions docs/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ Activate the Virtual Environment via:

```
.\my_venv\Scripts\activate # Linux/macOS
source my_venv/bin/activate # Windows
source my_venv/bin/activate # Windows (CMD)
.\my_venv\Scripts\Activate.ps1 # Windows (PowerShell)
```

Install Dependencies:
Expand Down Expand Up @@ -384,6 +385,8 @@ Update your manifest.py:
r_local = "C:/Program Files/R/R-4.2.3/bin"
```

Replace the version in this example with your installed R version. This directory must contain `Rscript.exe`, and the packages above must be installed in a library accessible to that R installation. This host setting is not used by the local Docker image.

<br>

----------------
Expand All @@ -401,7 +404,15 @@ See full run instructions: [Example run](../getting_started/example_run.md#usin

### Using Docker (Local)

Navigate to dependencies and double click on `run_mmmpy_docker.bat`
Start Docker Desktop and wait for its Linux engine to be running. Then double-click `dependencies/run_mmmpy_docker.bat` and select `OpenMalaria` or `malariasimulation`. The image provides Python, R, and these model dependencies; a host Python or R installation is not required for this route.

In the existing `elif hpc == 'LOCAL':` section of `manifest.py`, ensure the Docker activation setting is:

```python
EMOD_venv_container = 'source /opt/envs/mmmpy_local/bin/activate'
```

Docker is detected automatically; no `container_run` setting is required.

Manual Docker setup:

Expand All @@ -414,12 +425,12 @@ docker images
```

```
# Run interactively (optional to test it)
# Inside a container with the repository mounted at /mnt/c/projects/MultiMalModPy:
source /opt/envs/mmmpy_local/bin/activate
cd /mnt/c/projects
cd /mnt/c/projects/MultiMalModPy
python launch_sim.py --models OpenMalaria --test
```
Note: Inside Docker, you usually don’t need to activate a virtual environment. The Python in the image is ready to use.
Use the `mmmpy_local` environment inside the container, as the launcher and command below do.

Mount local project to the container to run a test simulation (from host):

Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ _This page provides a concise overview of the main steps to configure, launch, a
</li>
<li> ❌ If not, revisit the
</li>
&nbsp;➡️ <a href="../installation.md">Installation guide</a>
&nbsp;➡️ <a href="../configuration.md">First-time configuration</a>
&nbsp;&nbsp;➡️ <a href="../installation/">Installation guide</a><br>
&nbsp;&nbsp;➡️ <a href="../configuration/">First-time configuration</a>
</ul>
</div>

Expand Down
19 changes: 9 additions & 10 deletions malariasimulation/analyze_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def parse_args():
specifically for specifying the job directory and an optional experiment ID.
The job directory is required to locate the `exp.obj` file.

Args:
None

Returns:
Namespace: A namespace object containing the parsed command-line arguments.
The attributes include:
Expand Down Expand Up @@ -49,15 +46,16 @@ def parse_args():
def convert_to_long(output, age_groups):
"""
Convert the dataframe to long form for the desired columns.

For each specified age group, age-specific population, prevalence,
incidence, and mosquito-related outputs are extracted and combined
into a single long-format DataFrame.

Args:
output (pandas.DataFrame): Input dataframe.
age_min (list): Minimum age values.

age_max (list): Maximum age values.
age_groups (list): List of age groups, where each element contains the lower and upper age bounds in days.

Returns:
pandas.DataFrame: Long-form output.
pandas.DataFrame: Long-format DataFrame with one set of rows per specified age group.
"""
result = []
for pair in age_groups:
Expand Down Expand Up @@ -94,8 +92,9 @@ def post_processing(exp, job_directory, pv_suffix=''):
This was previously done in R, but was brought to python to match the two other models.

Args:
exp: Experiment object.
job_directory: Directory containing raw simulation output files.
exp (ExperimentConfig): The experiment configuration object.
job_directory (str): Directory containing raw simulation output files.
pv_suffix (str): Suffix for parameter variation files.

Saves:
{i}_daily.csv: for each simulation {i} in an experiment, saves the processed daily output.
Expand Down
29 changes: 24 additions & 5 deletions malariasimulation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,42 @@ def write_sh_malariasimulation(exp):
log_dir="$jobdir/log"

# Navigate to the working directory
cd $work_dir
cd "$work_dir"

# Create log directory if it doesn't exist
if [ ! -d "$log_dir" ]; then
mkdir -p "$log_dir"
fi

# Run the OpenMalaria simulation for each experiment
# Run each simulation in the background and retain its process ID.
pids=()
for ((i = 1; i <= {nexps}; i++)); do

Rscript "$work_dir/malariasimulation.R" "$work_dir" "$jobdir" $i >> "$log_dir/run_malariasimulation.log" 2>> "$log_dir/run_malariasimulation.err" &

echo "Simulation $i completed successfully" >> "$log_dir/run_malariasimulation.log"
pids+=("$!")
done

# Wait for all background jobs to finish
wait
# Wait for every child and check its own exit status.
failed=0
completed=0
progress_bar="####################"
printf 'malariasimulation [%-20s] 0/{nexps} (0%%)' ""
for i in "${{!pids[@]}}"; do
if wait "${{pids[$i]}}"; then
echo "Simulation $((i + 1)) completed successfully" >> "$log_dir/run_malariasimulation.log"
completed=$((completed + 1))
printf '\\rmalariasimulation [%-20s] %d/{nexps} (%d%%)' "${{progress_bar:0:$((20 * completed / {nexps}))}}" "$completed" "$((100 * completed / {nexps}))"
else
printf '\\n'
echo "Simulation $((i + 1)) failed. See $log_dir/run_malariasimulation.err" >&2
failed=1
fi
done
printf '\\n'
if ((failed)); then
exit 1
fi

echo "All simulations completed successfully."
"""
Expand Down
2 changes: 1 addition & 1 deletion manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@

image_path = 'mmmpy_local:rocky8'
image_venv_name = ''
EMOD_venv_container ='source /opt/envs/mmmpy_container/bin/activate'
EMOD_venv_container ='source /opt/envs/mmmpy_local/bin/activate'
bind_path = ROOT_DIR

else:
Expand Down
2 changes: 1 addition & 1 deletion plotter/plot_agecurves.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def age_curves(fdir, df, channel, sweepvar='models', facet_var='target_output_va
ValueError: If `facet_var` is set to 'ageGroup'.

Returns:
None: The function saves the generated plot to disk in the specified format.
None: The generated plot is saved to disk in the specified format.
"""

if facet_name is None:
Expand Down
Loading
Loading