Skip to content

Commit

Permalink
Add get_output_model_name_string() (#220)
Browse files Browse the repository at this point in the history
Description
- *Category*: feature
- *JIRA issue*:  [MIC-3229](https://jira.ihme.washington.edu/browse/MIC-3229) and [MIC-3091](https://jira.ihme.washington.edu/browse/MIC-3091)

Changes:
- Add `get_output_model_name_string()` to be a standard way for both `psimulate run` and `simulate run` to create the same results paths.
- If an artifact is provided at the CLI, use the location there, if not, check the model specification YAML for an artifact and use its location. If there is no artifact (valid use case!), use the stem of the model specification filename.

Testing
Ran this VCT and Vivarium against IV Iron with an artifact provided only in the YAML and only at the command and @aflaxman's WA DOH staffing repo, which does not have an artifact and motivated one of these JIRA tickets. In each case, the correct artifact (if any) and results path location were as expected (`"south_asia"` in the former case and `"staffing"` in the latter, from `staffing.yaml`
  • Loading branch information
mattkappel committed Aug 12, 2022
1 parent c3e5e76 commit 70c301a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/vivarium/interface/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def run(
configure_logging_to_terminal(verbose)

start = time()
results_root = get_output_root(results_directory, model_specification)
results_root = get_output_root(results_directory, model_specification, artifact_path)
results_root.mkdir(parents=True, exist_ok=False)

configure_logging_to_file(results_root)
Expand Down
40 changes: 38 additions & 2 deletions src/vivarium/interface/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import sys
from datetime import datetime
from pathlib import Path
from typing import Union

import yaml
from loguru import logger

from vivarium.exceptions import VivariumError
Expand Down Expand Up @@ -105,9 +107,43 @@ def wrapped_method(*args, **kwargs):
return method_wrapper


def get_output_root(results_directory, model_specification_file):
def get_output_model_name_string(
artifact_path: Union[str, Path],
model_spec_path: Union[str, Path],
) -> str:
"""Find a good string to use as model name in output path creation.
Parameters
----------
artifact_path
Path to the artifact file, if exists, else should be None
model_spec_path
Path to the model specification file. This must exist.
Returns
-------
str
A model name string for use in output labeling.
"""
if artifact_path:
model_name = Path(artifact_path).stem
else:
with open(model_spec_path) as model_spec_file:
model_spec = yaml.safe_load(model_spec_file)
try:
model_name = Path(model_spec["configuration"]["input_data"]["artifact_path"]).stem
except KeyError:
model_name = Path(model_spec_path).stem
return model_name


def get_output_root(
results_directory: Union[str, Path],
model_specification_file: Union[str, Path],
artifact_path: Union[str, Path],
):
launch_time = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
model_name = Path(model_specification_file).stem
model_name = get_output_model_name_string(artifact_path, model_specification_file)
output_root = Path(results_directory + f"/{model_name}/{launch_time}")
return output_root

Expand Down

0 comments on commit 70c301a

Please sign in to comment.