Skip to content

Commit 53c7b99

Browse files
authored
Merge pull request #505 from The-Strategy-Unit/add_params_module
adds schema/sample params to src
2 parents 193150c + 19e801f commit 53c7b99

File tree

23 files changed

+265
-92
lines changed

23 files changed

+265
-92
lines changed

.github/workflows/build_schema.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Deploy schema.json to GitHub Pages
1+
name: Deploy schema.json to GitHub Pages
22

33
on:
44
workflow_call:
55
inputs:
66
schema-tag:
77
required: true
88
default: dev
9-
type: string
9+
type: string
1010

1111
permissions:
1212
pages: write
@@ -28,7 +28,7 @@ jobs:
2828
- name: Copy schema to app version path
2929
run: |
3030
mkdir -p schemas/${{ inputs.schema-tag }}
31-
sed '/$id/ s/dev/${{ inputs.schema-tag }}/' params-schema.json > schemas/${{ inputs.schema-tag }}/params-schema.json
31+
sed '/$id/ s/dev/${{ inputs.schema-tag }}/' src/nhp/model/params/params-schema.json > schemas/${{ inputs.schema-tag }}/params-schema.json
3232
3333
- name: Commit the schema
3434
run: |
@@ -39,7 +39,7 @@ jobs:
3939
git commit -m "adding schema for ${{ inputs.schema-tag }}" || echo "No changes to commit"
4040
git push origin schemas
4141
popd
42-
42+
4343
- name: Upload to GitHub Pages
4444
uses: actions/upload-pages-artifact@v4
4545
with:

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
{
2222
"id": "params_file",
2323
"type": "promptString",
24-
"description": "Path to parameters file",
25-
"default": "queue/params-sample.json"
24+
"description": "Path to parameters file (leave empty to use sample parameters)",
25+
"default": ""
2626
},
2727
{
2828
"id": "type",

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
],
66
"python.testing.pytestArgs": [
77
"tests",
8-
"--data-dir=data/synth",
9-
"--params-file=queue/params-sample.json"
8+
"--data-dir=data/synth"
109
],
1110
"python.testing.unittestEnabled": false,
1211
"python.testing.pytestEnabled": true,

docs/index.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@ Welcome to the NHP Model documentation. This project provides modeling capabilit
1313
Download and install [`uv`](https://docs.astral.sh/uv/getting-started/installation/), then run `uv sync`. Download data locally, e.g., download a synthetic dataset to `data/synth`. Then, run the model with:
1414

1515
``` bash
16-
uv run python -m nhp.model queue/params-sample.json -d data/synth --type all
16+
uv run python -m nhp.model -d data/synth --type all
1717
```
1818

19+
to run the model with the sample parameters.
20+
21+
### Generating Sample Parameters
22+
23+
you can generate sample parameters using the CLI command:
24+
25+
``` bash
26+
python -m nhp.model.params --dataset [dataset] --scenario [scenario] --app-version dev > params.json
27+
```
28+
29+
replacing the values as needed. This will generate a file `params.json` with the sample parameters.
30+
1931
## API Reference
2032

2133
See the [Model Reference](reference/nhp/model/index.md) for detailed documentation of all classes and functions.

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dependencies = [
99
"azure-identity>=1.12",
1010
"azure-storage-blob>=12.15",
1111
"azure-storage-file-datalake>=12.10",
12+
"importlib-resources>=6.5.2",
13+
"jsonschema>=4.23.0",
1214
"numpy>=1.23",
1315
"pandas>=1.5",
1416
"pyarrow>=20.0",
@@ -28,14 +30,14 @@ where = ["src"]
2830

2931
[tool.setuptools.package-data]
3032
"nhp.model.data.reference" = ["*.csv", "*.json"]
33+
"nhp.model.params" = ["*.json"]
3134

3235
[project.optional-dependencies]
3336
dev = [
3437
"coverage>=7.2",
3538
"ipykernel>=6.21",
3639
"ipython>=8.11",
3740
"ipywidgets>=8.0",
38-
"jsonschema>=4.23.0",
3941
"jupyter_client>=8.0",
4042
"jupyter_core>=5.2",
4143
"jupyterlab_pygments>=0.2",
@@ -121,4 +123,4 @@ version_file = "src/nhp/model/_version.py"
121123
fallback_version = "0.0.0"
122124

123125
[tool.ty.src]
124-
exclude = ["notebooks", "docs"]
126+
exclude = ["notebooks", "docs"]

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ The model is deployed to Azure Container Registry and GitHub Container Registry
4343

4444
## JSON Schema
4545

46-
Parameters for the model are set in JSON format; an example can be seen in `queue/params-sample.json`. As the model develops, requirements for this JSON file change over time. We use [JSON schema](https://json-schema.org/understanding-json-schema/about) to manage changes to the parameters file. From model v3.5 onwards, these are deployed to GitHub pages, following this pattern:
46+
Parameters for the model are set in JSON format; an example can be seen in `src/nhp/model/params/params-sample.json`. As the model develops, requirements for this JSON file change over time. We use [JSON schema](https://json-schema.org/understanding-json-schema/about) to manage changes to the parameters file. From model v3.5 onwards, these are deployed to GitHub pages, following this pattern:
4747
- on merge to `main`, the schema is deployed to `https://the-strategy-unit.github.io/nhp_model/dev/params-schema.json`
4848
- on release of new model version vX.X, the schema is deployed to `https://the-strategy-unit.github.io/nhp_model/vX.X/params-schema.json`

src/nhp/docker/__main__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ def parse_args():
1414
parser = argparse.ArgumentParser()
1515
parser.add_argument(
1616
"params_file",
17-
nargs="?",
18-
default="params-sample.json",
1917
help="Name of the parameters file stored in Azure",
2018
)
2119

src/nhp/docker/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from azure.storage.filedatalake import DataLakeServiceClient
1414

1515
from nhp.docker.config import Config
16-
from nhp.model.helpers import load_params
16+
from nhp.model.params import load_params
1717
from nhp.model.run import noop_progress_callback
1818

1919

src/nhp/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from nhp.model.aae import AaEModel
55
from nhp.model.activity_resampling import ActivityResampling
66
from nhp.model.health_status_adjustment import HealthStatusAdjustmentInterpolated
7-
from nhp.model.helpers import load_params
87
from nhp.model.inpatients import InpatientEfficiencies, InpatientsModel
98
from nhp.model.model import Model
109
from nhp.model.model_iteration import ModelIteration
1110
from nhp.model.outpatients import OutpatientsModel
11+
from nhp.model.params import load_params, load_sample_params

src/nhp/model/__main__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
from nhp.model.aae import AaEModel
1919
from nhp.model.data import Local
20-
from nhp.model.helpers import load_params
2120
from nhp.model.inpatients import InpatientsModel
2221
from nhp.model.outpatients import OutpatientsModel
22+
from nhp.model.params import load_params, load_sample_params
2323
from nhp.model.run import run_all, run_single_model_run
2424

2525

@@ -28,8 +28,8 @@ def _parse_args() -> argparse.Namespace: # pragma: no cover
2828
parser.add_argument(
2929
"params_file",
3030
nargs="?",
31-
default="queue/params-sample.json",
32-
help="Path to the params.json file",
31+
default="",
32+
help="Path to the params.json file (leave empty to use sample parameters).",
3333
)
3434
parser.add_argument("-d", "--data-path", help="Path to the data", default="data")
3535
parser.add_argument(
@@ -54,7 +54,10 @@ def main() -> None:
5454
"""
5555
# Grab the Arguments
5656
args = _parse_args()
57-
params = load_params(args.params_file)
57+
if args.params_file == "":
58+
params = load_sample_params()
59+
else:
60+
params = load_params(args.params_file)
5861
# define the model to run
5962
match args.type:
6063
case "all":

0 commit comments

Comments
 (0)