Skip to content

Commit

Permalink
Merge pull request #4 from CDCgov/create-experiment
Browse files Browse the repository at this point in the history
creating the create_experiment script
  • Loading branch information
arik-shurygin authored Nov 5, 2024
2 parents 997c907 + 25a92c1 commit 1650b77
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 249 deletions.
31 changes: 27 additions & 4 deletions src/scenarios_hpc_azure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
# keep imports relative to avoid circular importing
from . import azure_utilities, experiment_setup
from .azure_utilities import AzureExperimentLauncher
import os

from . import azure_utils
from . import utils as experiment_utils
from .azure_utils import AzureExperimentLauncher

# GLOBALS, DONT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING
# tells the script where to look for certain files in an experiment
RUNNER_SCRIPT_PATH = "run_task.py"
TEMPLATE_CONFIGS_DIR_NAME = "template_configs"
STATE_CONFIGS_DIR_NAME = "states"
PP_SCRIPTS_DIR_NAME = "postprocessing_scripts"
EXP_DIR_NAME_OPTIONAL = "exp"
PACKAGE_PATH, _ = os.path.split(os.path.realpath(__file__))
FIPS_TO_NAME_PATH = os.path.join(PACKAGE_PATH, "data", "fips_to_name.csv")
POPULATIONS_PATH = os.path.join(PACKAGE_PATH, "data", "CenPop2020_Mean_ST.csv")


# Defines all the different modules able to be imported
__all__ = [
experiment_setup,
azure_utilities,
azure_utils,
AzureExperimentLauncher,
experiment_utils,
RUNNER_SCRIPT_PATH,
TEMPLATE_CONFIGS_DIR_NAME,
STATE_CONFIGS_DIR_NAME,
PP_SCRIPTS_DIR_NAME,
EXP_DIR_NAME_OPTIONAL,
FIPS_TO_NAME_PATH,
POPULATIONS_PATH,
PACKAGE_PATH,
]
File renamed without changes.
86 changes: 80 additions & 6 deletions src/scenarios_hpc_azure/create_experiment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import argparse
import os

import pandas as pd

from . import (
FIPS_TO_NAME_PATH,
POPULATIONS_PATH,
PP_SCRIPTS_DIR_NAME,
STATE_CONFIGS_DIR_NAME,
TEMPLATE_CONFIGS_DIR_NAME,
utils,
)

parser = argparse.ArgumentParser()
# experiment directory
Expand All @@ -19,16 +31,78 @@
help="space separated list of str representing USPS postal code of each state",
)
parser.add_argument(
"-m",
"--config_molds",
"-tc",
"--template_configs",
type=str,
required=False,
nargs="+",
help="space separated paths to the config molds, defaults to the template_configs directory within the experiment",
help="space separated paths to the template configs, defaults to the %s directory within the experiment"
% TEMPLATE_CONFIGS_DIR_NAME,
)
args = parser.parse_args()
print(args)


def create():
print("testing creation of experiments")
"""Entry point to the create_experiment script, meant to be executed
from directory in which experiment exists.
"""
args = parser.parse_args()
experiment_name: str = args.experiment_name
states: list[str] = args.states
tcs: list[str] = args.template_configs
experiment_dir = utils.identify_experiment_dir(
experiment_name, working_dir=os.getcwd()
)
# create any folders that are not in the experiment
utils.create_experiment_framework(
experiment_dir,
necessary_dirs=[
PP_SCRIPTS_DIR_NAME,
TEMPLATE_CONFIGS_DIR_NAME,
STATE_CONFIGS_DIR_NAME,
],
)
# validate that all necessary folders are in the experiment
utils.validate_experiment_structure(
experiment_dir,
necessary_components=[
PP_SCRIPTS_DIR_NAME,
TEMPLATE_CONFIGS_DIR_NAME,
STATE_CONFIGS_DIR_NAME,
],
)
# validate the template_configs, moving them to the appropriate spot
# if they are not there already
tcs = utils.identify_template_config_paths(
experiment_dir, TEMPLATE_CONFIGS_DIR_NAME, tcs=tcs
)
# load our mapping CSVs
state_names_map = pd.read_csv(FIPS_TO_NAME_PATH)
state_pops_map = pd.read_csv(POPULATIONS_PATH)
# adding a USA row with the sum of all state pops
usa_pop_row = pd.DataFrame(
[
[
"US",
"United States",
sum(state_pops_map["POPULATION"]),
"+44.582076", # latitude
"+103.461760", # longitude
]
],
columns=state_pops_map.columns,
)
state_pops_map = pd.concat(
[state_pops_map, usa_pop_row], ignore_index=True
)
if "all" in states:
states = list(state_names_map["stusps"])
utils.create_state_subdirectories(
os.path.join(experiment_dir, STATE_CONFIGS_DIR_NAME),
state_names=states,
)
utils.populate_config_files(
experiment_dir, tcs, state_names_map, state_pops_map
)
print(
f"{utils.bcolors.OKGREEN}Successfully created and populated state directories{utils.bcolors.ENDC}"
)
2 changes: 1 addition & 1 deletion src/scenarios_hpc_azure/experiment_launcher_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
from itertools import groupby

from .azure_utilities import AzureExperimentLauncher
from .azure_utils import AzureExperimentLauncher

# specify job ID, cant already exist

Expand Down
236 changes: 0 additions & 236 deletions src/scenarios_hpc_azure/experiment_setup.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from shiny import App, Session, reactive, render, ui
from shinywidgets import output_widget, render_plotly, render_widget

from .. import azure_utilities as autils
from .. import azure_utils as autils
from . import shiny_utils as sutils

INPUT_BLOB_NAME = "scenarios-mechanistic-input"
Expand Down
Loading

0 comments on commit 1650b77

Please sign in to comment.