feat: add ChapUserOptions with COVID mask support#352
Draft
knutdrand wants to merge 1 commit into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 existingchap_core.transformations.covid_mask.mask_covid_datahelper.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 withchap__covid_mask: bool = False.extract_from_config()pulls chap keys out of a configured-model'suser_option_values;to_json_schema_properties()emits the schema fragment.ModelTemplateDB.with_chap_options()— merges chap options intouser_optionsso 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.database.pycallsmodel_template.with_chap_options()before validation so schemas withadditionalProperties: Falseaccept thechap__keys.ExternalModel.train— calls_apply_chap_transformations()before writing the training CSV; whenchap__covid_mask=truethe helper masks 2020-03 to 2021-12-31.Test plan
make lintcleanuv run pytest tests/models/test_chap_user_options.py tests/models/test_external_model_chap_options.py -q-> 11 passedmake test-> 813 passed, integration tests Redis-gated (skip locally), two pre-existing untracked-doc failures unrelated to this branchtests/integration/rest_api/test_chap_options_endpoints.pyandtests/integration/rest_api/test_ewars_model_configuration.pyexecute end-to-endGET /v1/crud/model-templatesreturnschap__covid_maskin each template'suserOptionschap__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