Skip to content

alter demographic adjustment - #701

Open
tomjemmett wants to merge 2 commits into
remove_tretspef_groupedfrom
alter_demog_adjustment
Open

tomjemmett wants to merge 2 commits into
remove_tretspef_groupedfrom
alter_demog_adjustment

Conversation

@tomjemmett

@tomjemmett tomjemmett commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

closes #703, closes #704, closes #705

updates the model and the parameters schema to remove support for multiple variants to be used within a model run, and to pass the demographic/birth factors directly in the params file, rather than reading these values from disk


Stack created with GitHub Stacks CLI • Give Feedback 💬

rather than load the values in, values are passed in via params file
@tomjemmett
tomjemmett added this pull request to stack #702 October 19, 2026 10:16
@github-actions

Copy link
Copy Markdown

✅ A new build is available.

You can use the following to use pull the image into your local environment:

docker pull ghcr.io/the-strategy-unit/nhp_model:pr-701

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a52ce6b) to head (00851fe).

Additional details and impacted files
@@                    Coverage Diff                    @@
##           remove_tretspef_grouped      #701   +/-   ##
=========================================================
  Coverage                   100.00%   100.00%           
=========================================================
  Files                           20        20           
  Lines                         1214      1196   -18     
  Branches                        61        61           
=========================================================
- Hits                          1214      1196   -18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tomjemmett tomjemmett self-assigned this Oct 19, 2026
@tomjemmett tomjemmett added this to the v6.2.0 milestone Oct 19, 2026
@tomjemmett
tomjemmett marked this pull request as ready for review October 19, 2026 10:24
@tomjemmett
tomjemmett requested a review from a team as a code owner October 19, 2026 10:24
Copilot AI balanced review requested due to automatic review settings October 19, 2026 10:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Removing the "variant" key from generate_run_params leaves run_all (run.py:172) reading run_params["variant"], which will raise a runtime KeyError that the mocked unit tests do not catch.

2 open issues
What changed in this PR

This PR implements the demographic-adjustment rework described in issues #703–#705. It removes the model's support for selecting among multiple population variants per model run and stops reading demographic/birth factors from parquet files on disk. Instead, the demographic and birth growth factors are now supplied directly in the parameters file under a new demographic_adjustment object, and _load_demog_factors computes the growth factors (horizon ÷ baseline) into pd.Series keyed by (sex, age). This supports custom population projections without changing the data pipeline.

Changes:

  • generate_run_params no longer selects variants/probabilities, and _load_demog_factors builds demog_factors/birth_factors Series from params["demographic_adjustment"] rather than from the data loader.
  • The Data/Local interfaces drop get_demographic_factors/get_birth_factors, and activity_resampling consumes the new (sex, age)-indexed Series directly.
  • The params schema and sample are restructured to embed demographic_adjustment (variant + population/births baseline/horizon tables), with tests and golden-file snapshots updated accordingly.
File Description
src/​nhp/​model/​model.py Rewrites _load_demog_factors to build Series from params and removes variant selection from generate_run_params; docstring left stale.
src/​nhp/​model/​activity_resampling.py Simplifies demographic/birth adjustments to use the new (sex, age) Series directly.
src/​nhp/​model/​data/​local.py Removes get_demographic_factors/get_birth_factors loaders.
src/​nhp/​model/​data/​data.py Removes the abstract get_demographic_factors/get_birth_factors interface methods.
src/​nhp/​model/​params/​params-schema.json Replaces demographic_factors.variant_probabilities with the demographic_adjustment object and supporting $defs.
src/​nhp/​model/​params/​params-sample.json Embeds the full population/births baseline/horizon tables.
tests/​unit/​nhp/​model/​test_model.py Updates demog-factor and run-param tests to the new Series/params shape.
tests/​unit/​nhp/​model/​test_activity_resampling.py Updates fixtures/assertions to the (demog_type, sex, age) index.
tests/​unit/​nhp/​model/​data/​test_local.py Removes tests for deleted loader methods.
tests/​unit/​nhp/​model/​data/​test_data.py Removes tests for deleted abstract methods.
tests/​integration/​.../​*.csv, tests/​e2e/​.../​*.csv Regenerated golden snapshots reflecting the new computation.

Review effort: Balanced

Comment thread src/nhp/model/model.py
Comment on lines 269 to 270
return {
"variant": variants,
"seeds": rng.integers(0, 65535, model_runs).tolist(),
Comment thread src/nhp/model/model.py
demog = self.params["demographic_adjustment"]

pop = demog["population"]
self.demog_factors = pd.Series(

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants