Skip to content

Commit 56fb238

Browse files
eqmooringEric Mooring
andauthored
chore: updates to package README with new commands (#15)
Co-authored-by: Eric Mooring <pgv5@AZ1CFA1VSWL-46.ext.cdc.gov>
1 parent 6a6936c commit 56fb238

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

packages/example_model/README.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
# Example model
22

3-
This python package provides a simple, standalone executable model.
3+
This python package provides a simple branching process model intended to be used with the `mrp` (model runner protocol) package.
44

5-
To run the model within the `uv` environment:
5+
This README will describe multiple ways to run the model.
6+
7+
First open the Python interactive shell within the `uv` environment:
68

79
```bash
810
uv sync --all-packages
9-
uv run python -m example_model.example_model packages/example_model/tests/model_input.json
11+
uv run python
12+
```
13+
The following two lines of code are sufficient to run the example model using the static method (i.e., calling `Binom_BP_Model.simulate()`).
14+
```python
15+
from example_model import Binom_BP_Model
16+
Binom_BP_Model.simulate({"seed": 123, "max_gen": 15, "n": 3, "p": 0.5, "max_infect": 500})
1017
```
18+
This should yield the following output: `[1, 2, 1, 1, 1, 2, 4, 8, 15, 24, 28, 38, 58, 86, 126]`
19+
20+
An equivalent approach is to read the model input from `defaults.json`. (The code here assumes working from the root of the repo.)
1121

12-
Which will write `model_output.json` with the results of the run. You
13-
can specify a different location with the `-o` command line argument.
22+
```python
23+
import json
24+
from example_model import Binom_BP_Model
25+
model_inputs = json.load(open("./packages/example_model/defaults.json"))
26+
Binom_BP_Model.simulate(model_inputs)
27+
```
28+
To use the MRP functionality, create an environment that specifies the inputs and use the `.run()` method:
29+
```python
30+
from mrp import Environment
31+
from example_model import Binom_BP_Model
32+
model_inputs = {"max_gen": 15, "n": 3, "p": 0.5, "max_infect": 500}
33+
env = Environment({"input": model_inputs})
34+
Binom_BP_Model(env).run()
35+
```
36+
The above examples are very similar to those included in `scripts/direct_runner.py`, which can be run (from the root of the repo) with the following:
37+
```bash
38+
uv sync --all-packages
39+
uv run python scripts/direct_runner.py
40+
```
41+
Additionally, as described in the repo-level README, the model can be run as specified in the `example_model.mrp.toml`, which can be run as follows:
42+
```bash
43+
uv sync --all-packages
44+
uv run mrp run example_model.mrp.toml
45+
```

0 commit comments

Comments
 (0)