Skip to content

feat: add ChapUserOptions with COVID mask support#352

Draft
knutdrand wants to merge 1 commit into
masterfrom
feat/CLIM-191-chap-user-options
Draft

feat: add ChapUserOptions with COVID mask support#352
knutdrand wants to merge 1 commit into
masterfrom
feat/CLIM-191-chap-user-options

Conversation

@knutdrand

Copy link
Copy Markdown
Collaborator

Summary

Introduces CHAP-wide user options prefixed with chap__ that apply automatically to every model template via the REST API. The first option, chap__covid_mask, masks the 2020-03 to 2021-12-31 COVID period from training data using the existing chap_core.transformations.covid_mask.mask_covid_data helper.

Extracted from the Laos workshop bundle (#261) so the feature can land independently of the other unrelated changes in that PR (aggregated-metrics plot, weekly stride, HMC hash bump, incidental refactors). Related: CLIM-191.

What's in the change

  • ChapUserOptions (chap_core/models/chap_user_options.py) — Pydantic model with chap__covid_mask: bool = False. extract_from_config() pulls chap keys out of a configured-model's user_option_values; to_json_schema_properties() emits the schema fragment.
  • ModelTemplateDB.with_chap_options() — merges chap options into user_options so the schema downstream sees them.
  • GET /v1/crud/model-templates — injects chap options into each template at API time (not stored in the DB), preserving the existing live-chapkit-sync flow.
  • Configured-model creationdatabase.py calls model_template.with_chap_options() before validation so schemas with additionalProperties: False accept the chap__ keys.
  • ExternalModel.train — calls _apply_chap_transformations() before writing the training CSV; when chap__covid_mask=true the helper masks 2020-03 to 2021-12-31.

Test plan

  • make lint clean
  • uv run pytest tests/models/test_chap_user_options.py tests/models/test_external_model_chap_options.py -q -> 11 passed
  • make test -> 813 passed, integration tests Redis-gated (skip locally), two pre-existing untracked-doc failures unrelated to this branch
  • CI: run integration tests with Redis available so tests/integration/rest_api/test_chap_options_endpoints.py and tests/integration/rest_api/test_ewars_model_configuration.py execute end-to-end
  • Manual: GET /v1/crud/model-templates returns chap__covid_mask in each template's userOptions
  • Manual: create a configured model with chap__covid_mask=true, run training on a 2019-2022 dataset, confirm rows from [2020-03, 2021-12-31] are absent from the written training CSV

Introduces CHAP-wide user options prefixed with `chap__` that apply
automatically to every model template via the REST API. The first
option, `chap__covid_mask`, masks the 2020-03 to 2021-12-31 COVID
period from training data using the existing
`chap_core.transformations.covid_mask.mask_covid_data` helper.

- `ChapUserOptions` Pydantic model with `chap__covid_mask`
- `ModelTemplateDB.with_chap_options()` merges chap options into
  `user_options` so they appear in the schema
- `GET /v1/crud/model-templates` injects chap options at API time
  (not stored in the DB)
- Configured-model creation runs `with_chap_options()` before
  validation so schemas with `additionalProperties: False` accept
  the chap__ keys
- `ExternalModel.train` applies covid masking before writing the
  training CSV when `chap__covid_mask=true`

Extracted from the Laos workshop bundle (PR #261) so the feature
can land on its own. Related: CLIM-191.
@knutdrand knutdrand marked this pull request as draft May 18, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant