Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ uv run mrp run example_model.mrp.toml --input seed=42 --input max_gen=10

You can run `uv tool install cfa-mrp` to omit the `uv run`.

## Running a calibration

The repository includes a complete calibration example for the bundled example model:

```bash
uv sync --all-packages --all-extras
uv run python -m example_model.calibrate
```

This runs the ABC-SMC calibration workflow defined in [packages/example_model/src/example_model/calibrate.py](/home/as81/work/cfa-calibration-tools-wtk-mp/packages/example_model/src/example_model/calibrate.py) and prints the posterior summary and diagnostics.

To compare serial and parallel execution for the same example, run:

```bash
uv run python -m example_model.benchmark
```

## General Disclaimer

This repository was created for use by CDC programs to collaborate on public health related projects in support of the [CDC mission](https://www.cdc.gov/about/organization/mission.htm). GitHub is not hosted by the CDC, but is a third party website used by CDC and its partners to share information and collaborate on software. CDC use of GitHub does not imply an endorsement of any one particular service, product, or enterprise.
Expand Down
8 changes: 8 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent
for rel_path in ("src", "packages/example_model/src"):
path = str(ROOT / rel_path)
if path not in sys.path:
sys.path.insert(0, path)
3 changes: 2 additions & 1 deletion example_model.mrp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ version = "0.0.1"

[runtime]
env = "uv"
command = "example_model"
command = "python"
args = ["-m", "example_model"]

[output]
spec = "filesystem"
Expand Down
6 changes: 5 additions & 1 deletion packages/example_model/src/example_model/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import timeit
from pathlib import Path

import numpy as np
from mrp import Environment
Expand Down Expand Up @@ -132,5 +133,8 @@ def outputs_to_distance(model_output, target_data):
for result in benchmark_results:
print(f"workers: {result['max_workers']}, time: {result['time']}")

with open("./benchmarks/parallelization_check.json", "w") as fp:
benchmark_dir = Path("./benchmarks")
benchmark_dir.mkdir(exist_ok=True)

with open(benchmark_dir / "parallelization_check.json", "w") as fp:
json.dump(benchmark_results, fp)
3 changes: 2 additions & 1 deletion src/calibrationtools/formatting.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from rich.console import Console
from rich.progress import Progress, BarColumn, TextColumn, TimeElapsedColumn, TimeRemainingColumn


def get_console() -> Console:
return Console(force_terminal=True)


def _format_time(seconds: float) -> str:
"""Format time duration in human-readable units.
- < 1s -> (e.g, 0.5s)
Expand Down
6 changes: 4 additions & 2 deletions src/calibrationtools/load_priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

def load_schema() -> dict:
"""Load the JSON schema for validating priors from the package resources."""
with importlib.resources.open_text(
"calibrationtools.assets", "schema.json"
with (
importlib.resources.files("calibrationtools.assets")
.joinpath("schema.json")
.open("r", encoding="utf-8")
) as f:
schema = json.load(f)
return schema
Expand Down
Loading
Loading