Skip to content

Add pluggable region scoping strategies (RowFilter + WeightReplacement) #249

@anth-volk

Description

@anth-volk

Problem

The refactored policyengine.py replaced the old region: str parameter with filter_field/filter_value on the Simulation model but only implemented row filtering. The weight replacement logic used for UK parliamentary constituencies and local authorities was lost. UK constituencies are defined with filter_field="household_weight" which doesn't work with the row-filter implementation.

Proposed solution

Introduce a RegionScopingStrategy abstraction with two concrete implementations:

  • RowFilterStrategy: Filters dataset rows by matching a household-level variable (used for UK countries, US places)
  • WeightReplacementStrategy: Downloads pre-computed weight matrices from GCS and replaces household_weight in the dataset (used for UK constituencies and local authorities)

Changes

  • New scoping_strategy.py module with RegionScopingStrategy base class, RowFilterStrategy, WeightReplacementStrategy, and ScopingStrategy discriminated union type
  • Updated Region and Simulation models with scoping_strategy field
  • Updated UK and US model run() methods to use strategy pattern
  • Updated UK region registry (constituencies + local authorities use WeightReplacementStrategy, countries use RowFilterStrategy)
  • Updated US region registry (places use RowFilterStrategy)
  • Comprehensive tests for strategy serialization, application, and model integration

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions