diff --git a/changelog.d/microcosm-name-sweep-20261106.changed.md b/changelog.d/microcosm-name-sweep-20261106.changed.md new file mode 100644 index 000000000..11cbab8f6 --- /dev/null +++ b/changelog.d/microcosm-name-sweep-20261106.changed.md @@ -0,0 +1 @@ +Give the Belgian dataset class, the data-producer certification strategy and the certification and legacy-SPM constants Microcosm names, keeping the previous names as aliases. diff --git a/docs/bundles.md b/docs/bundles.md index 55fff09be..acaf3ab39 100644 --- a/docs/bundles.md +++ b/docs/bundles.md @@ -206,7 +206,7 @@ python scripts/bundle.py certify-data \ --manifest-uri hf://dataset/policyengine/populace-uk-private@/releases//release_manifest.json ``` -For US Populace releases, certify the Populace release manifest directly: +For US Microcosm releases, certify the Microcosm release manifest directly: ```bash python scripts/bundle.py certify-data \ @@ -218,7 +218,7 @@ python scripts/bundle.py certify-data \ ``` US state and congressional-district regions scope one certified ACS-local -Populace dataset with row filters. Pass its non-default local-area release +Microcosm dataset with row filters. Pass its non-default local-area release manifest through `--regional-manifest-uri`; certification adds the pinned H5 artifact to `data_releases.us.datasets` and writes both regional path templates under `data_releases.us.region_datasets`. If a legacy release publishes derived diff --git a/docs/countries.md b/docs/countries.md index 256ac9077..1a1443bc9 100644 --- a/docs/countries.md +++ b/docs/countries.md @@ -32,12 +32,12 @@ Override in any output with `income_variable=`. | | Dataset | |---|---| -| US | Populace US 2024 (`populace_us_2024.h5`) | +| US | Microcosm US 2024 (`populace_us_2024.h5`) | | UK | Microcosm UK 2024-25 (`microcosm_uk_2024_25.h5`); constituency and local-authority regions use its local-area release (`microcosm_uk_2024_25_dense.h5`) | ## State / regional breakdown -US: Populace row scoping uses `state_fips` and `congressional_district_geoid`. +US: Microcosm row scoping uses `state_fips` and `congressional_district_geoid`. `state_code` remains the human-readable state input for custom households. US resource and poverty calculations also require observed `county_fips` or an explicit national or SPM-area choice; see [Households](households.md#spm-geography-and-measurement-selection). diff --git a/docs/engineering/runbooks/build-m-us-populace-certification.md b/docs/engineering/runbooks/build-m-us-populace-certification.md index c99190436..c69f77986 100644 --- a/docs/engineering/runbooks/build-m-us-populace-certification.md +++ b/docs/engineering/runbooks/build-m-us-populace-certification.md @@ -1,6 +1,6 @@ -# US Populace certification runbook +# US Microcosm certification runbook -Use this runbook to certify a new national US Populace release together with +Use this runbook to certify a new national US Microcosm release together with the shared ACS-local release used for state and congressional-district simulations. For now, state and district simulations use the national release instead; see the interim exception in Step 2. Read the @@ -25,7 +25,7 @@ interim exception in Step 2 holds). metadata and runs reachability `HEAD` checks against Hugging Face. - `HUGGING_FACE_TOKEN` (or `HF_TOKEN`) exported — required to regenerate the UK TRO in the `--include-tros` step and to run the UK data-release fetch in - the test suite. The US populace repo is public. + the test suite. The US release repo, `policyengine/populace-us`, is public. ## Step 1 — identify the releases @@ -93,7 +93,7 @@ PE_UPDATE_SNAPSHOTS=1 pytest tests/test_household_calculator_snapshot.py The certification command passes the immutable ACS-local release manifest with `--regional-manifest-uri`. Confirm all of the following: -- `default_dataset` remains the national Populace dataset; +- `default_dataset` remains the national Microcosm dataset; - the local-area artifact appears in `data_releases.us.datasets` with its repository type, immutable revision, and SHA-256; - `region_datasets.national` selects the national artifact; diff --git a/docs/engineering/skills/data-certification.md b/docs/engineering/skills/data-certification.md index 10236467d..545b1aad4 100644 --- a/docs/engineering/skills/data-certification.md +++ b/docs/engineering/skills/data-certification.md @@ -314,7 +314,7 @@ their `_tiny` files. ### US -For US Populace certification, certify the Populace release manifests +For US Microcosm certification, certify the Microcosm release manifests directly. `policyengine/populace-us` publishes each build in its own release folder (it has `releases.json`), so give each manifest's folder at the commit that published it: @@ -327,7 +327,7 @@ python scripts/bundle.py certify-data --country us --data-producer populace \ ``` US state and congressional-district regions are row filters over one shared, -certified ACS-local Populace dataset. Its release manifest must declare +certified ACS-local Microcosm dataset. Its release manifest must declare `dataset_role: non_default_local_area`, `is_default: false`, no default datasets, and exactly one pinned H5 microdata artifact. Certification writes each dataset's path in its build folder: @@ -343,7 +343,7 @@ each dataset's path in its build folder: The ACS-local artifact is a second entry in `data_releases.us.datasets`; it is not a dataset overlay and it never replaces the national `default_dataset`. -If the Populace release publishes derived `states/*.h5` or `districts/*.h5` +If the Microcosm release publishes derived `states/*.h5` or `districts/*.h5` files for compatibility checks, certification omits them from the runtime bundle. The country-wide default and ACS-local dataset are each single shared files; region registries select one and then filter its rows. @@ -433,7 +433,7 @@ A certification PR should normally change only: Hard failures (certification refuses): missing national default dataset, default dataset absent from artifacts, any artifact without a revision pin, unreachable certified dataset, missing required supplemental release files -(for example Populace-US `us_source_coverage.json`), a malformed shared +(for example Microcosm-US `us_source_coverage.json`), a malformed shared local-area release, area-coded national release or legacy per-state artifacts when `--regional-manifest-uri` is used, a regional release that does not serve the pinned model version, an unreachable regional artifact, a re-certification diff --git a/docs/microsim.md b/docs/microsim.md index 4aef63d71..15b12ba25 100644 --- a/docs/microsim.md +++ b/docs/microsim.md @@ -134,12 +134,12 @@ datasets = pe.us.ensure_datasets( dataset = datasets["populace_us_2024_2026"] ``` -The default US dataset is **Populace US 2024** — a Populace-built dataset +The default US dataset is **Microcosm US 2024** — a Microcosm-built dataset calibrated to IRS, CMS, SNAP, Census, and other administrative totals. The current UK certified default is **Microcosm UK 2024–25**, a Microcosm build calibrated to HMRC, DWP, OBR and other administrative totals; constituency and local-authority regions use its local-area release. **Enhanced FRS 2024–25** -(`enhanced_frs_2024_25`, policyengine-uk-data 1.58.1) and **Populace UK 2023** +(`enhanced_frs_2024_25`, policyengine-uk-data 1.58.1) and **Microcosm UK 2023** remain available as named, non-default bundle datasets. PolicyEngine.py obtains the repository type, immutable revision, and SHA-256 @@ -156,7 +156,7 @@ pe.us.load_datasets() # or pe.uk.load_datasets() Alongside the certified national default, the bundle registers a US dataset for finer geographic work: `populace_us_2024_acs_local`. It is a -Populace US 2024 build of roughly **1.6 million households** on an **ACS 2024 +Microcosm US 2024 build of roughly **1.6 million households** on an **ACS 2024 multispine**, with each household **PUMA-assigned** to a 119th-Congress congressional district, county, and state, and calibrated to **state administrative totals and state and congressional-district population**. Its @@ -387,7 +387,7 @@ See [Outputs](outputs.md) for the full catalog. ## Memory and performance -A full Populace US microsimulation uses roughly 4 GB of memory and takes 15-30 seconds on a laptop. For parameter sweeps, reuse the baseline: +A full Microcosm US microsimulation uses roughly 4 GB of memory and takes 15-30 seconds on a laptop. For parameter sweeps, reuse the baseline: ```python baseline = Simulation(dataset=dataset, tax_benefit_model_version=pe.us.model) @@ -404,7 +404,7 @@ Smaller custom H5 datasets can be passed explicitly for testing: ```python datasets = pe.us.ensure_datasets( - datasets=["/path/to/smoke_test_populace_us_2024.h5"], + datasets=["/path/to/smoke_test_microcosm_us_2024.h5"], years=[2026], allow_unmanaged=True, ) diff --git a/docs/regions.md b/docs/regions.md index c86eb5f07..b1c8eea9d 100644 --- a/docs/regions.md +++ b/docs/regions.md @@ -24,7 +24,7 @@ ca_snap.run() ``` Each state is a region in the US registry. State regions load the ACS-local -Populace dataset declared by `region.dataset_path`, then scope its rows by +Microcosm dataset declared by `region.dataset_path`, then scope its rows by `state_fips`. They do not require separate state H5 files: ```python @@ -218,7 +218,7 @@ df.groupby("geo").apply(lambda g: (g["change"] * g["weight"]).sum() / g["weight" ## Scoping datasets to a region -For reforms defined only over a sub-national slice, pass a scoping strategy to `Simulation`. `RowFilterStrategy` keeps only matching households. `WeightReplacementStrategy` is legacy matrix infrastructure and is not used by the UK Populace constituency or local-authority registry. +For reforms defined only over a sub-national slice, pass a scoping strategy to `Simulation`. `RowFilterStrategy` keeps only matching households. `WeightReplacementStrategy` is legacy matrix infrastructure; neither the UK Microcosm constituency registry nor its local-authority registry uses it. ```python from policyengine.core.scoping_strategy import RowFilterStrategy @@ -233,7 +233,7 @@ baseline = Simulation( ) ``` -Regions that filter (US states and congressional districts, UK countries, and any region with `region.requires_filter == True`) carry their own `scoping_strategy`. Pull it off the region object rather than reconstructing it. US place regions are present as hierarchy metadata, but current Populace datasets do not carry `place_fips`, so they do not expose runtime scoping yet: +Regions that filter (US states and congressional districts, UK countries, and any region with `region.requires_filter == True`) carry their own `scoping_strategy`. Pull it off the region object rather than reconstructing it. US place regions are present as hierarchy metadata, but current Microcosm datasets do not carry `place_fips`, so they do not expose runtime scoping yet: ```python ca = pe.us.model.region_registry.get("state/ca") diff --git a/docs/release-bundles.md b/docs/release-bundles.md index def3658d2..b4f8199ec 100644 --- a/docs/release-bundles.md +++ b/docs/release-bundles.md @@ -164,7 +164,7 @@ It does not own final runtime bundle certification. ### Country data package -Examples: `populace-data`, `policyengine-uk-data` +Examples: `microcosm-data`, `policyengine-uk-data` The country data package owns: @@ -196,7 +196,7 @@ python scripts/bundle.py certify-data --country us \ --manifest-uri "hf://dataset/policyengine/populace-us@/releases//release_manifest.json" ``` -US Populace certification uses the Populace release manifest directly: +US Microcosm certification uses the Microcosm release manifest directly: ```bash python scripts/bundle.py certify-data --country us --data-producer populace \ @@ -205,7 +205,7 @@ python scripts/bundle.py certify-data --country us --data-producer populace \ --model-version "" ``` -That produces one US bundle manifest entry containing the Populace national +That produces one US bundle manifest entry containing the Microcosm national default dataset and the certified ACS-local regional dataset. State and congressional-district simulations use the latter with runtime row filters, so derived `states/*.h5` or `districts/*.h5` files are not vendored into diff --git a/examples/belgium_axiom_pilot.py b/examples/belgium_axiom_pilot.py index f13941dc7..5c77fa576 100644 --- a/examples/belgium_axiom_pilot.py +++ b/examples/belgium_axiom_pilot.py @@ -1,6 +1,6 @@ """Belgium population microsimulation through the Axiom rules engine. -Runs the calibrated populace-be pilot dataset (populace-us support records +Runs the calibrated Microcosm-BE pilot dataset (Microcosm-US support records reweighted to Statbel/SPF/ONSS/ONEM targets from PolicyEngine/ledger) through the rulespec-be composed worker pipeline, and scores the aggregates against Belgian administrative facts. @@ -19,7 +19,7 @@ Usage:: - POPULACE_BE_DATASET=.../populace_be_pilot_2026.h5 \\ + MICROCOSM_BE_DATASET=.../populace_be_pilot_2026.h5 \\ RULESPEC_BE_ROOT=.../rulespec-be \\ uv run python examples/belgium_axiom_pilot.py """ @@ -31,19 +31,27 @@ EMPLOYEE_SSC, PIT_BEFORE_WITHHOLDING, AxiomBelgiumPilot, - PopulaceBelgiumDataset, + MicrocosmBelgiumDataset, ) -DATASET = os.environ["POPULACE_BE_DATASET"] +DATASET = os.environ.get("MICROCOSM_BE_DATASET") +if DATASET is None: + DATASET = os.environ.get( + "POPULACE_BE_DATASET" # compat: populace alias, remove after 6.20.2 + ) +if DATASET is None: + raise SystemExit( + "Set MICROCOSM_BE_DATASET to the Microcosm-BE pilot dataset's .h5 path." + ) RULESPEC = os.environ.get("RULESPEC_BE_ROOT", "~/TheAxiomFoundation/rulespec-be") # Ledger facts (PolicyEngine/ledger, Belgian publisher packages) ONSS_WORKER_CONTRIBUTIONS_2024 = 20_836_582_673 SPF_PIT_BEFORE_WITHHOLDING_2023 = 62_840_116_134 -dataset = PopulaceBelgiumDataset( - name="populace-be-pilot", - description="populace-us support reweighted to Belgian ledger targets", +dataset = MicrocosmBelgiumDataset( + name="microcosm-be-pilot", + description="Microcosm-US support reweighted to Belgian ledger targets", filepath=DATASET, year=2026, ) @@ -57,7 +65,7 @@ ssc_net = person[EMPLOYEE_SSC].sum() pit = person[PIT_BEFORE_WITHHOLDING].sum() -print("Belgium pilot (Axiom engine over populace-be, worker slice)") +print("Belgium pilot (Axiom engine over Microcosm-BE, worker slice)") print( f" data vintage {output.year}; policy period {output.policy_period}; " f"model {model_version.version}" diff --git a/src/policyengine/countries/us/data/places.py b/src/policyengine/countries/us/data/places.py index 5669e26be..27a44f4f8 100644 --- a/src/policyengine/countries/us/data/places.py +++ b/src/policyengine/countries/us/data/places.py @@ -5,7 +5,7 @@ """ # US cities/places with population over 100K (from Census data). -# These are registry metadata until Populace emits place-level row keys. +# These are registry metadata until Microcosm emits place-level row keys. # Total: 333 places US_PLACES: list[dict[str, str]] = [ { diff --git a/src/policyengine/countries/us/regions.py b/src/policyengine/countries/us/regions.py index 7f6ceb87c..71f02e9f2 100644 --- a/src/policyengine/countries/us/regions.py +++ b/src/policyengine/countries/us/regions.py @@ -100,7 +100,7 @@ def build_us_region_registry() -> RegionRegistry: ) ) - # 4. Place/city regions (hierarchy metadata only until Populace emits place_fips) + # 4. Place/city regions (hierarchy metadata only until Microcosm emits place_fips) for place in US_PLACES: state_abbrev = place["state"] fips = place["fips"] diff --git a/src/policyengine/provenance/certification.py b/src/policyengine/provenance/certification.py index c590d19ce..72a278903 100644 --- a/src/policyengine/provenance/certification.py +++ b/src/policyengine/provenance/certification.py @@ -109,16 +109,25 @@ QUALIFICATION_LEDGER_URL = ( "https://github.com/PolicyEngine/policyengine.py/tree/uk-qualification-ledger" ) -POPULACE_US_SOURCE_COVERAGE_FILE = "us_source_coverage.json" -# The Populace US producer publishes under `microcosm-data` since the -# source-enrichment releases; `populace-data` is its earlier name. Both denote -# the same producer, so every Populace-specific rule below must accept either. -POPULACE_DATA_PACKAGES = frozenset({"populace-data", "microcosm-data"}) -# The Hugging Face repos each country's Populace/Microcosm releases publish to. -POPULACE_RELEASE_REPOS = { +MICROCOSM_US_SOURCE_COVERAGE_FILE = "us_source_coverage.json" +# The Microcosm US producer publishes under `microcosm-data` since the +# source-enrichment releases; both published package names below denote +# the same producer, so every Microcosm-specific rule below must accept either. +MICROCOSM_DATA_PACKAGES = frozenset({"populace-data", "microcosm-data"}) +# The Hugging Face repos each country's Microcosm releases publish to. +MICROCOSM_RELEASE_REPOS = { "us": "policyengine/populace-us", "uk": "policyengine/populace-uk-private", } +POPULACE_US_SOURCE_COVERAGE_FILE = ( # compat: populace alias, remove after 6.20.2 + MICROCOSM_US_SOURCE_COVERAGE_FILE +) +POPULACE_DATA_PACKAGES = ( # compat: populace alias, remove after 6.20.2 + MICROCOSM_DATA_PACKAGES +) +POPULACE_RELEASE_REPOS = ( # compat: populace alias, remove after 6.20.2 + MICROCOSM_RELEASE_REPOS +) # Region types a regional release serves. Their regions load the routed dataset # and keep row-filtering it on their own geography column. LOCAL_AREA_REGION_TYPES: dict[CertifiedCountry, tuple[str, ...]] = { @@ -950,10 +959,10 @@ def required_supplemental_release_files( ) -> tuple[str, ...]: if ( country == "us" - and manifest.data_package.name in POPULACE_DATA_PACKAGES + and manifest.data_package.name in MICROCOSM_DATA_PACKAGES and uri_parts["repo_id"] == "policyengine/populace-us" ): - return (POPULACE_US_SOURCE_COVERAGE_FILE,) + return (MICROCOSM_US_SOURCE_COVERAGE_FILE,) return () @@ -962,9 +971,9 @@ def should_validate_vendored_artifacts( manifest: DataReleaseManifest, uri_parts: dict, ) -> bool: - return manifest.data_package.name in POPULACE_DATA_PACKAGES and uri_parts[ + return manifest.data_package.name in MICROCOSM_DATA_PACKAGES and uri_parts[ "repo_id" - ] == POPULACE_RELEASE_REPOS.get(country) + ] == MICROCOSM_RELEASE_REPOS.get(country) def _state_code_from_path(path: str, artifact_prefix: str) -> Optional[str]: @@ -987,7 +996,7 @@ def merge_us_state_release_manifest( artifact_prefix: str = "states/", path_template: str = "states/{state_code}.h5", ) -> DataReleaseManifest: - """Add legacy US state artifacts to a primary Populace release manifest.""" + """Add legacy US state artifacts to a primary Microcosm release manifest.""" primary_payload = primary_manifest.model_dump(mode="json", exclude_none=True) merged_artifacts = primary_payload.setdefault("artifacts", {}) @@ -1361,7 +1370,7 @@ def build_country_manifest_payload( for name, artifact in manifest.artifacts.items(): if ( country == "us" - and manifest.data_package.name in POPULACE_DATA_PACKAGES + and manifest.data_package.name in MICROCOSM_DATA_PACKAGES and artifact.path.endswith(".h5") and ( artifact.path.startswith("states/") @@ -1390,7 +1399,7 @@ def build_country_manifest_payload( path_template = template.get("path_template") if ( country == "us" - and manifest.data_package.name in POPULACE_DATA_PACKAGES + and manifest.data_package.name in MICROCOSM_DATA_PACKAGES and region in {"state", "congressional_district"} and isinstance(path_template, str) and "{" in path_template @@ -1561,7 +1570,7 @@ def certify( ) -class PopulaceDataProducerCertificationStrategy(DataProducerCertificationStrategy): +class MicrocosmDataProducerCertificationStrategy(DataProducerCertificationStrategy): data_producer = "populace" def certify( @@ -1752,12 +1761,17 @@ def certify( ) +PopulaceDataProducerCertificationStrategy = ( # compat: populace alias, remove after 6.20.2 + MicrocosmDataProducerCertificationStrategy +) + + def certification_strategy( country: str, data_producer: Optional[str] = None ) -> DataProducerCertificationStrategy: producer = data_producer or ("populace" if country == "uk" else "legacy") if producer == "populace": - return PopulaceDataProducerCertificationStrategy() + return MicrocosmDataProducerCertificationStrategy() if producer == "legacy": return LegacyDataProducerCertificationStrategy() raise CertificationError(f"Unknown data-producer {producer!r}.") diff --git a/src/policyengine/tax_benefit_models/be/__init__.py b/src/policyengine/tax_benefit_models/be/__init__.py index 74044832d..4ab6be709 100644 --- a/src/policyengine/tax_benefit_models/be/__init__.py +++ b/src/policyengine/tax_benefit_models/be/__init__.py @@ -7,7 +7,7 @@ and ``model.py`` for scope and source-install requirements. """ -from .datasets import BEYearData, PopulaceBelgiumDataset +from .datasets import BEYearData, MicrocosmBelgiumDataset from .model import ( EMPLOYEE_SSC, PIT_BEFORE_WITHHOLDING, @@ -17,13 +17,18 @@ be_model, ) +PopulaceBelgiumDataset = ( # compat: populace alias, remove after 6.20.2 + MicrocosmBelgiumDataset +) + __all__ = [ "AxiomBelgium", "AxiomBelgiumPilot", "BEYearData", "EMPLOYEE_SSC", "PIT_BEFORE_WITHHOLDING", - "PopulaceBelgiumDataset", + "MicrocosmBelgiumDataset", + "PopulaceBelgiumDataset", # compat: populace alias, remove after 6.20.2 "REMUNERATION", "be_model", ] diff --git a/src/policyengine/tax_benefit_models/be/datasets.py b/src/policyengine/tax_benefit_models/be/datasets.py index 04bb40d06..c1b4f1832 100644 --- a/src/policyengine/tax_benefit_models/be/datasets.py +++ b/src/policyengine/tax_benefit_models/be/datasets.py @@ -88,7 +88,7 @@ def entity_data(self) -> dict[str, MicroDataFrame]: return {"person": self.person, "household": self.household} -class PopulaceBelgiumDataset(Dataset): +class MicrocosmBelgiumDataset(Dataset): """Belgium pilot dataset loaded from a Microcosm-BE HDF5 artifact. ``year`` identifies the input dataset vintage. ``policy_period`` is set on @@ -188,3 +188,8 @@ def save(self) -> None: self._POLICY_PERIOD_ATTRIBUTE, int(self.policy_period), ) + + +PopulaceBelgiumDataset = ( # compat: populace alias, remove after 6.20.2 + MicrocosmBelgiumDataset +) diff --git a/src/policyengine/tax_benefit_models/be/model.py b/src/policyengine/tax_benefit_models/be/model.py index c4fe9e850..ea41009a2 100644 --- a/src/policyengine/tax_benefit_models/be/model.py +++ b/src/policyengine/tax_benefit_models/be/model.py @@ -2,7 +2,7 @@ Unlike the US and UK model versions, Belgium runs on the Axiom rules engine: statutes encoded as RuleSpec YAML in TheAxiomFoundation/rulespec-be, -compiled and executed by ``axiom-rules-engine``, and driven over populace +compiled and executed by ``axiom-rules-engine``, and driven over Microcosm entity tables through the ``microcosm.frame`` Axiom adapter. There is no policyengine-core country package and no certified release manifest, so this version subclasses ``TaxBenefitModelVersion`` directly and stays outside the @@ -46,10 +46,14 @@ from .datasets import ( BEYearData, - PopulaceBelgiumDataset, + MicrocosmBelgiumDataset, _person_with_household_weights, ) +PopulaceBelgiumDataset = ( # compat: populace alias, remove after 6.20.2 + MicrocosmBelgiumDataset +) + if TYPE_CHECKING: from policyengine.core.simulation import Simulation @@ -76,7 +80,7 @@ class AxiomBelgium(TaxBenefitModel): id: str = "axiom-rulespec-be" description: str = ( "Belgium tax rules encoded as RuleSpec (TheAxiomFoundation/rulespec-be), " - "executed by the Axiom rules engine over populace entity tables." + "executed by the Axiom rules engine over Microcosm entity tables." ) @@ -126,7 +130,7 @@ def run(self, simulation: "Simulation") -> "Simulation": ) dataset = simulation.dataset - assert isinstance(dataset, PopulaceBelgiumDataset) + assert isinstance(dataset, MicrocosmBelgiumDataset) if dataset.data is None: dataset.load() assert dataset.data is not None @@ -186,7 +190,7 @@ def run(self, simulation: "Simulation") -> "Simulation": }, ] - simulation.output_dataset = PopulaceBelgiumDataset( + simulation.output_dataset = MicrocosmBelgiumDataset( id=simulation.id, name=dataset.name, description=dataset.description, diff --git a/src/policyengine/tax_benefit_models/us/legacy_inputs.py b/src/policyengine/tax_benefit_models/us/legacy_inputs.py index 38fb02495..f108ccd54 100644 --- a/src/policyengine/tax_benefit_models/us/legacy_inputs.py +++ b/src/policyengine/tax_benefit_models/us/legacy_inputs.py @@ -441,7 +441,7 @@ def stored_entity_tables( renames whose live input belongs to it. policyengine-us loads an entity-table H5 (the layout of the certified - Populace default) into a multi-year dataset whose ``datasets`` map each + Microcosm default) into a multi-year dataset whose ``datasets`` map each year to that year's entity DataFrames. Those keep every stored column, including the ones the engine skipped, so they are returned as they are. diff --git a/src/policyengine/tax_benefit_models/us/legacy_spm/registry.py b/src/policyengine/tax_benefit_models/us/legacy_spm/registry.py index 4806066ee..39b2be7c1 100644 --- a/src/policyengine/tax_benefit_models/us/legacy_spm/registry.py +++ b/src/policyengine/tax_benefit_models/us/legacy_spm/registry.py @@ -62,7 +62,7 @@ class LegacySPMSource(BaseModel): #: residents without declaring SPM scope, and it was built a few hours before #: PolicyEngine/microcosm#959, so its ASEC/PUF records lack the independence #: role that the national release carries for the same records. -POPULACE_US_2024_ACS_LOCAL_BUILD_O = LegacySPMSource( +MICROCOSM_US_2024_ACS_LOCAL_BUILD_O = LegacySPMSource( name=( "populace_us_2024_acs_local@" "populace-us-2024-buildo-acs-local-767312d60-20260923T074941Z" @@ -82,7 +82,7 @@ class LegacySPMSource(BaseModel): #: the measurement under Census's ACS household-population rule, as Build O's #: are. Remove the entry once a release carries the scope natively #: (PolicyEngine/policyengine-us#9462). -POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263 = LegacySPMSource( +MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263 = LegacySPMSource( name=( "populace_us_2024_acs_local@" "populace-us-2024-buildo-acs-local-766b7c7-20261017T030317Z" @@ -91,9 +91,16 @@ class LegacySPMSource(BaseModel): spm_universe_rule="acs_household_population", ) +POPULACE_US_2024_ACS_LOCAL_BUILD_O = ( # compat: populace alias, remove after 6.20.2 + MICROCOSM_US_2024_ACS_LOCAL_BUILD_O +) +POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263 = ( # compat: populace alias, remove after 6.20.2 + MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263 +) + LEGACY_SPM_SOURCES: tuple[LegacySPMSource, ...] = ( - POPULACE_US_2024_ACS_LOCAL_BUILD_O, - POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263, + MICROCOSM_US_2024_ACS_LOCAL_BUILD_O, + MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263, ) diff --git a/tests/fixtures/release_tros/README.md b/tests/fixtures/release_tros/README.md index f64ee4bb6..f1bd29f0c 100644 --- a/tests/fixtures/release_tros/README.md +++ b/tests/fixtures/release_tros/README.md @@ -7,7 +7,7 @@ generator. They do not certify a new canonical SPM release. PolicyEngine/policyengine.py commit `3c3b4f6442f4a5adc47274734d71a6ca10103b43`, under `src/policyengine/data/bundle/`. -- `us-release_manifest.json`: published Populace release +- `us-release_manifest.json`: published Microcosm release `populace-us-2024-buildp-sparse-rmloss100-cae8640-20260728T011454Z`, at `https://huggingface.co/datasets/policyengine/populace-us/resolve/populace-us-2024-buildp-sparse-rmloss100-cae8640-20260728T011454Z/releases/populace-us-2024-buildp-sparse-rmloss100-cae8640-20260728T011454Z/release_manifest.json`. Its raw SHA256 is diff --git a/tests/test_be_axiom_pilot.py b/tests/test_be_axiom_pilot.py index b75aec797..1e5d5f465 100644 --- a/tests/test_be_axiom_pilot.py +++ b/tests/test_be_axiom_pilot.py @@ -25,7 +25,7 @@ REMUNERATION, AxiomBelgiumPilot, BEYearData, - PopulaceBelgiumDataset, + MicrocosmBelgiumDataset, ) from policyengine.tax_benefit_models.be import model as be_model_module @@ -155,7 +155,7 @@ def pilot_dataset(tmp_path): weights="household_weight", ) path = tmp_path / "microcosm_be_test.h5" - PopulaceBelgiumDataset( + MicrocosmBelgiumDataset( name="microcosm-be-test", description="four-person nonuniform-weight fixture", filepath=str(path), @@ -164,7 +164,7 @@ def pilot_dataset(tmp_path): data=BEYearData(person=person, household=household), ).save() # Exercise load(), including metadata and _time_period, during the run. - return PopulaceBelgiumDataset( + return MicrocosmBelgiumDataset( name="microcosm-be-test", description="four-person nonuniform-weight fixture", filepath=str(path), @@ -295,7 +295,7 @@ def test_output_metadata_round_trips_only_after_a_distinct_path_is_chosen( output.filepath = str(output_path) output.save() - reloaded = PopulaceBelgiumDataset( + reloaded = MicrocosmBelgiumDataset( name=output.name, description=output.description, filepath=str(output_path), @@ -309,7 +309,7 @@ def test_output_metadata_round_trips_only_after_a_distinct_path_is_chosen( def test_dataset_rejects_a_mislabeled_hdf5_period(pilot_dataset): - mislabeled = PopulaceBelgiumDataset( + mislabeled = MicrocosmBelgiumDataset( name=pilot_dataset.name, description=pilot_dataset.description, filepath=pilot_dataset.filepath, @@ -481,7 +481,7 @@ def test_dataset_rejects_a_mismatched_legacy_person_weight(tmp_path): time_period=2026, ).save(path) - dataset = PopulaceBelgiumDataset( + dataset = MicrocosmBelgiumDataset( name="legacy-mismatch", description="invalid redundant person weights", filepath=str(path), @@ -524,7 +524,7 @@ def test_real_source_stack_computes_the_worker_slice(pilot_dataset): @pytest.fixture def in_memory_pilot_dataset(): - return PopulaceBelgiumDataset( + return MicrocosmBelgiumDataset( name="in-memory-pilot", description="two-person household-authoritative weight fixture", year=2026, diff --git a/tests/test_certify_data_release.py b/tests/test_certify_data_release.py index e3069d32d..b3bc472b7 100644 --- a/tests/test_certify_data_release.py +++ b/tests/test_certify_data_release.py @@ -132,7 +132,7 @@ def _release_manifest_payload() -> dict: } -def _populace_manifest_payload_without_regions() -> dict: +def _microcosm_manifest_payload_without_regions() -> dict: payload = _release_manifest_payload() payload["metadata"] = {} payload["artifacts"].pop("states/AK") @@ -385,7 +385,7 @@ def test__given_manifest__then_pins_data_package_and_default(self): assert payload["model_package"]["sha256"] == "d" * 64 assert payload["model_package"]["wheel_url"] == "https://example/wheel" - def test__given_populace_area_h5_artifact__then_omits_it_from_runtime_bundle(self): + def test__given_microcosm_area_h5_artifact__then_omits_it_from_runtime_bundle(self): payload = self._payload() assert "states/AK" not in payload["datasets"] @@ -406,7 +406,7 @@ def test__given_release_scoped_diagnostics__then_rewrites_paths(self): f"releases/{TAG}/us_source_coverage.json" ) - def test__given_populace_region_templates__then_only_national_is_carried_through( + def test__given_microcosm_region_templates__then_only_national_is_carried_through( self, ): payload = self._payload() @@ -415,13 +415,13 @@ def test__given_populace_region_templates__then_only_national_is_carried_through "national": {"path_template": "populace_us_2024.h5"} } - def test__given_populace_manifest_without_regions__then_adds_national_template( + def test__given_microcosm_manifest_without_regions__then_adds_national_template( self, ): payload = build_country_manifest_payload( country="us", manifest=DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ), uri_parts=parse_manifest_uri(MANIFEST_URI), policyengine_version="9.9.9", @@ -452,7 +452,7 @@ def test__given_build_provenance__then_certification_carries_it(self): class TestMergeUSStateReleaseManifest: def test__given_state_manifest__then_does_not_vendor_state_region_artifacts(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) states = DataReleaseManifest.model_validate(_state_release_manifest_payload()) @@ -474,7 +474,7 @@ def test__given_state_manifest__then_does_not_vendor_state_region_artifacts(self def test__given_missing_state_artifact__then_raises(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) states = DataReleaseManifest.model_validate( _state_release_manifest_payload(missing={"CA"}) @@ -485,7 +485,7 @@ def test__given_missing_state_artifact__then_raises(self): def test__given_malformed_state_path__then_raises(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) states = DataReleaseManifest.model_validate( _state_release_manifest_payload(malformed={"CA": "state/CA.h5"}) @@ -496,7 +496,7 @@ def test__given_malformed_state_path__then_raises(self): def test__given_state_without_hash__then_raises(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) states = DataReleaseManifest.model_validate( _state_release_manifest_payload(without_hash={"CA"}) @@ -507,7 +507,7 @@ def test__given_state_without_hash__then_raises(self): def test__given_duplicate_state_artifact__then_warns_and_ignores_duplicate(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) state_payload = _state_release_manifest_payload() state_payload["artifacts"]["states/CA_duplicate"] = { @@ -529,7 +529,7 @@ def test__given_duplicate_state_artifact__then_warns_and_ignores_duplicate(self) class TestMergeUSLocalAreaReleaseManifest: def test__given_typed_local_area_release__then_certifies_shared_dataset(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) regional = DataReleaseManifest.model_validate( _local_area_release_manifest_payload() @@ -581,7 +581,7 @@ def test__given_invalid_release_role__then_rejects_it( message, ): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) regional_payload = _local_area_release_manifest_payload() regional_payload[field] = value @@ -592,7 +592,7 @@ def test__given_invalid_release_role__then_rejects_it( def test__given_more_than_one_microdata_artifact__then_rejects_it(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) regional_payload = _local_area_release_manifest_payload() regional_payload["artifacts"]["second"] = { @@ -606,7 +606,7 @@ def test__given_more_than_one_microdata_artifact__then_rejects_it(self): def test__given_legacy_regional_release__then_uses_state_merge(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) states = DataReleaseManifest.model_validate(_state_release_manifest_payload()) @@ -619,7 +619,7 @@ def test__given_legacy_regional_release__then_uses_state_merge(self): def test__given_unknown_regional_role__then_rejects_it(self): primary = DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ) regional_payload = _local_area_release_manifest_payload() regional_payload["dataset_role"] = "unknown" @@ -630,7 +630,7 @@ def test__given_unknown_regional_role__then_rejects_it(self): class TestCertifyDataRelease: - def test__given_fetched_populace_manifest__then_updates_bundle_manifest( + def test__given_fetched_microcosm_manifest__then_updates_bundle_manifest( self, tmp_path ): bundle_path = tmp_path / "manifest.json" @@ -694,7 +694,7 @@ def test__given_us_local_area_manifest__then_certifies_shared_regional_dataset( primary_response = MagicMock() primary_response.status_code = 200 primary_response.content = json.dumps( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ).encode() regional_response = MagicMock() regional_response.status_code = 200 @@ -827,7 +827,7 @@ def fake_main(argv: list[str]) -> int: "--skip-artifact-check", ] - def test__given_missing_populace_us_source_coverage__then_raises(self, tmp_path): + def test__given_missing_microcosm_us_source_coverage__then_raises(self, tmp_path): response = MagicMock() response.status_code = 200 response.content = json.dumps(_release_manifest_payload()).encode() @@ -946,7 +946,7 @@ def test__given_vendored_bundle_manifest__then_tro_sidecar_binds_it(self): def _source_enrichment_manifest_payload() -> dict: """A `microcosm-data` release whose sidecars use the `evidence` kind. - This is the shape the Populace US producer publishes for source-enrichment + This is the shape the Microcosm US producer publishes for source-enrichment releases: the data package is named `microcosm-data` rather than `populace-data`, and release-directory sidecars are labelled `evidence` rather than `diagnostics`. @@ -966,7 +966,7 @@ def _source_enrichment_manifest_payload() -> dict: class TestSourceEnrichmentProducerRelease: - """The `microcosm-data` producer name must keep every Populace rule armed. + """The `microcosm-data` producer name must keep every Microcosm rule armed. A release published under the newer producer name previously fell through every `populace-data` guard, which both skipped the per-artifact @@ -1336,7 +1336,7 @@ def test__given_us_area_coded_national__then_rejects_it(self): merge_area_coded_national_release_manifest( "us", DataReleaseManifest.model_validate( - _populace_manifest_payload_without_regions() + _microcosm_manifest_payload_without_regions() ), DataReleaseManifest.model_validate(_efrs_release_payload()), ) diff --git a/tests/test_dataset_materialization.py b/tests/test_dataset_materialization.py index 5180ebd88..f7dfa04fa 100644 --- a/tests/test_dataset_materialization.py +++ b/tests/test_dataset_materialization.py @@ -77,7 +77,7 @@ def test_resolve_bundle_dataset_uses_cross_package_overlay(tmp_path): assert dataset.revision == "populace-release" -def test_bundled_uk_populace_dataset_uses_dataset_repository_url(): +def test_bundled_uk_microcosm_dataset_uses_dataset_repository_url(): dataset = _resolve_bundle_dataset("uk", "populace_uk_2023") url = https_dataset_uri( @@ -163,7 +163,7 @@ def test_country_data_package_uses_model_repository_url(tmp_path): ) -def test_populace_package_uses_dataset_repository_url(tmp_path): +def test_microcosm_package_uses_dataset_repository_url(tmp_path): session = _Session(_Response(b"populace-data")) manifest = _manifest_with_hash( _sha256(b"populace-data"), diff --git a/tests/test_entity_utils.py b/tests/test_entity_utils.py index 17a1fc5a2..deb1dd615 100644 --- a/tests/test_entity_utils.py +++ b/tests/test_entity_utils.py @@ -161,7 +161,7 @@ def test__given_matching_value__then_returns_filtered_entities(self): def test__given_us_numeric_geography__then_filters_state_and_district( self, us_test_dataset ): - """Given: US data with Populace geography columns + """Given: US data with Microcosm geography columns When: Filtering by state FIPS and congressional district GEOID Then: Related entities are preserved for matching households only """ diff --git a/tests/test_microcosm_compatibility.py b/tests/test_microcosm_compatibility.py new file mode 100644 index 000000000..89f96a7ec --- /dev/null +++ b/tests/test_microcosm_compatibility.py @@ -0,0 +1,149 @@ +"""Public Microcosm names retain their previous import aliases.""" + +import runpy +from importlib import import_module +from pathlib import Path +from types import SimpleNamespace +from unittest.mock import Mock + +import numpy as np +import pytest + +from policyengine.provenance.certification import ( + MicrocosmDataProducerCertificationStrategy, + certification_strategy, +) + + +@pytest.mark.parametrize( + "module_name,current_name,legacy_name", + [ + ( + "policyengine.tax_benefit_models.be", + "MicrocosmBelgiumDataset", + "PopulaceBelgiumDataset", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.tax_benefit_models.be.datasets", + "MicrocosmBelgiumDataset", + "PopulaceBelgiumDataset", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.tax_benefit_models.be.model", + "MicrocosmBelgiumDataset", + "PopulaceBelgiumDataset", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.provenance.certification", + "MicrocosmDataProducerCertificationStrategy", + "PopulaceDataProducerCertificationStrategy", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.provenance.certification", + "MICROCOSM_US_SOURCE_COVERAGE_FILE", + "POPULACE_US_SOURCE_COVERAGE_FILE", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.provenance.certification", + "MICROCOSM_DATA_PACKAGES", + "POPULACE_DATA_PACKAGES", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.provenance.certification", + "MICROCOSM_RELEASE_REPOS", + "POPULACE_RELEASE_REPOS", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.tax_benefit_models.us.legacy_spm.registry", + "MICROCOSM_US_2024_ACS_LOCAL_BUILD_O", + "POPULACE_US_2024_ACS_LOCAL_BUILD_O", # compat: populace alias, remove after 6.20.2 + ), + ( + "policyengine.tax_benefit_models.us.legacy_spm.registry", + "MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263", + "POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263", # compat: populace alias, remove after 6.20.2 + ), + ], +) +def test_previous_public_names_resolve_to_current_objects( + module_name, current_name, legacy_name +): + module = import_module(module_name) + + assert getattr(module, legacy_name) is getattr(module, current_name) + + +@pytest.mark.parametrize( + "country,data_producer", + [("uk", None), ("uk", "populace"), ("us", "populace")], +) +def test_current_certification_strategy_preserves_the_published_producer( + country, data_producer +): + strategy = certification_strategy(country, data_producer) + + assert type(strategy) is MicrocosmDataProducerCertificationStrategy + assert strategy.data_producer == "populace" + + +@pytest.mark.parametrize( + "current_path,legacy_path,expected_path", + [ + ("current.h5", None, "current.h5"), + (None, "legacy.h5", "legacy.h5"), + ("current.h5", "legacy.h5", "current.h5"), + ], +) +def test_belgium_example_accepts_both_dataset_environment_names( + monkeypatch, current_path, legacy_path, expected_path +): + be = import_module("policyengine.tax_benefit_models.be") + simulation_module = import_module("policyengine.core.simulation") + legacy_env_name = ( + "POPULACE_BE_DATASET" # compat: populace alias, remove after 6.20.2 + ) + for name, value in ( + ("MICROCOSM_BE_DATASET", current_path), + (legacy_env_name, legacy_path), + ): + if value is None: + monkeypatch.delenv(name, raising=False) + else: + monkeypatch.setenv(name, value) + monkeypatch.setenv("RULESPEC_BE_ROOT", "test-rules") + dataset_type = Mock() + model_type = Mock(return_value=SimpleNamespace(version="test-model")) + output = SimpleNamespace( + year=2026, + policy_period=2025, + data=SimpleNamespace( + person={ + be.EMPLOYEE_SSC: np.asarray([0.0]), + be.PIT_BEFORE_WITHHOLDING: np.asarray([0.0]), + } + ), + ) + simulation = Mock(output_dataset=output) + monkeypatch.setattr(be, "MicrocosmBelgiumDataset", dataset_type) + monkeypatch.setattr(be, "AxiomBelgiumPilot", model_type) + monkeypatch.setattr(simulation_module, "Simulation", Mock(return_value=simulation)) + + runpy.run_path( + Path(__file__).resolve().parents[1] / "examples/belgium_axiom_pilot.py" + ) + + assert dataset_type.call_args.kwargs["filepath"] == expected_path + simulation.run.assert_called_once_with() + + +def test_belgium_example_names_the_new_variable_when_neither_is_set(monkeypatch): + for name in ( + "MICROCOSM_BE_DATASET", + "POPULACE_BE_DATASET", # compat: populace alias, remove after 6.20.2 + ): + monkeypatch.delenv(name, raising=False) + + with pytest.raises(SystemExit, match="MICROCOSM_BE_DATASET"): + runpy.run_path( + Path(__file__).resolve().parents[1] / "examples/belgium_axiom_pilot.py" + ) diff --git a/tests/test_release_manifests.py b/tests/test_release_manifests.py index fb2023d71..70bb32254 100644 --- a/tests/test_release_manifests.py +++ b/tests/test_release_manifests.py @@ -67,7 +67,7 @@ "hf://policyengine/populace-us/" f"{US_DATA_RELEASE_FOLDER}/populace_us_2024.h5@{US_DATA_RELEASE_REVISION}" ) -# Certified local-area dataset: a Populace US artifact published in its own +# Certified local-area dataset: a Microcosm US artifact published in its own # immutable release. It remains non-default nationally and is selected for # states and congressional districts. US_LOCAL_AREA_DATASET = "populace_us_2024_acs_local" @@ -102,10 +102,10 @@ "hf://policyengine/policyengine-uk-data-private/frs_2024_25.h5@1.58.1" ) # The prior certified default, kept resolvable via dataset_overlays. -UK_POPULACE_RELEASE_ID = "populace-uk-2023-dd68c73-4aa4b14-20260619T023711Z" -UK_POPULACE_DATASET_URI = ( +UK_MICROCOSM_2023_RELEASE_ID = "populace-uk-2023-dd68c73-4aa4b14-20260619T023711Z" +UK_MICROCOSM_2023_DATASET_URI = ( f"hf://policyengine/populace-uk-private/populace_uk_2023.h5" - f"@{UK_POPULACE_RELEASE_ID}" + f"@{UK_MICROCOSM_2023_RELEASE_ID}" ) UK_CERTIFICATION_SOURCE = "policyengine.py bundle certification" UK_CERTIFIED_DATASET_URI = ( @@ -171,7 +171,7 @@ def _response_with_json(payload: dict) -> MagicMock: def _legacy_us_country_manifest( version: str = "1.73.0", package_name: str = "policyengine-us-data" ) -> CountryReleaseManifest: - """Pin the legacy fixture independently of the installed Populace bundle.""" + """Pin the legacy fixture independently of the installed Microcosm bundle.""" return CountryReleaseManifest.model_validate( { "country_id": "us", @@ -389,7 +389,7 @@ def test__given_uk_legacy_dataset_names__then_resolves_bundled_aliases(self): ) assert ( resolve_dataset_reference("uk", "populace_uk_2023") - == UK_POPULACE_DATASET_URI + == UK_MICROCOSM_2023_DATASET_URI ) assert ( resolve_dataset_reference("uk", "enhanced_frs_2024_25") @@ -403,7 +403,7 @@ def test__given_explicit_url__then_resolution_is_noop(self): assert resolve_dataset_reference("us", url) == url def test__given_existing_local_path__then_resolution_is_noop(self, tmp_path): - dataset = tmp_path / "smoke_test_populace_us_2024.h5" + dataset = tmp_path / "smoke_test_microcosm_us_2024.h5" dataset.write_bytes(b"") assert resolve_dataset_reference("us", str(dataset)) == str(dataset) @@ -524,7 +524,7 @@ def test__given_explicit_uri__then_managed_resolution_requires_opt_in(self): ) def test__given_local_path__then_managed_resolution_requires_opt_in(self, tmp_path): - dataset = tmp_path / "smoke_test_populace_us_2024.h5" + dataset = tmp_path / "smoke_test_microcosm_us_2024.h5" dataset.write_bytes(b"") try: diff --git a/tests/test_us_legacy_inputs_integration.py b/tests/test_us_legacy_inputs_integration.py index 182d39af9..23a445123 100644 --- a/tests/test_us_legacy_inputs_integration.py +++ b/tests/test_us_legacy_inputs_integration.py @@ -1,7 +1,7 @@ """The legacy WIC take-up draw reaches real policyengine-us simulations. Each test builds a tiny US household that stores its WIC take-up draw as -``would_claim_wic`` (the layout of the certified Populace default, see +``would_claim_wic`` (the layout of the certified Microcosm default, see PolicyEngine/microcosm#1026), loads it through one of the load paths, and checks that a WIC-eligible person whose stored draw is ``False`` gets no WIC, while the same person gets WIC when the mapping is switched off. @@ -105,7 +105,7 @@ def _in_memory_dataset(directory, frames=None) -> PolicyEngineUSDataset: def _write_entity_tables(path) -> str: - """Write the household in the certified Populace default's layout.""" + """Write the household in the certified Microcosm default's layout.""" with pd.HDFStore(path, mode="w") as store: for entity, frame in _frames().items(): store.put(entity, frame, format="table", data_columns=True) @@ -161,7 +161,7 @@ def mapped_run(tmp_path_factory): def mapped_managed(tmp_path_factory): """Load path 2 over the household's entity-table file, mapping on.""" path = _write_entity_tables( - tmp_path_factory.mktemp("mapped_managed") / "populace_layout.h5" + tmp_path_factory.mktemp("mapped_managed") / "microcosm_layout.h5" ) return pe.us.managed_microsimulation(dataset=path, allow_unmanaged=True) @@ -432,7 +432,7 @@ def test_managed_without_the_mapping_gives_every_eligible_person_wic( tmp_path, monkeypatch ): monkeypatch.setattr(legacy_inputs, "LEGACY_INPUT_RENAMES", {}) - path = _write_entity_tables(tmp_path / "populace_layout.h5") + path = _write_entity_tables(tmp_path / "microcosm_layout.h5") microsim = pe.us.managed_microsimulation(dataset=path, allow_unmanaged=True) eligible = microsim.calculate("is_wic_eligible", MONTHS[0]).values @@ -445,7 +445,7 @@ def test_managed_without_the_mapping_gives_every_eligible_person_wic( def test_managed_reform_maps_its_baseline_too(tmp_path): - path = _write_entity_tables(tmp_path / "populace_layout.h5") + path = _write_entity_tables(tmp_path / "microcosm_layout.h5") microsim = pe.us.managed_microsimulation( dataset=path, allow_unmanaged=True, @@ -482,7 +482,7 @@ def test_managed_core_h5_with_a_part_year_draw_is_refused(tmp_path): def engine_microsim(tmp_path_factory): """A real managed Microsimulation the property below maps draws onto.""" path = _write_entity_tables( - tmp_path_factory.mktemp("engine_microsim") / "populace_layout.h5" + tmp_path_factory.mktemp("engine_microsim") / "microcosm_layout.h5" ) return pe.us.managed_microsimulation(dataset=path, allow_unmanaged=True) @@ -545,7 +545,7 @@ def test_both_load_paths_give_the_same_take_up_and_wic(mapped_run, mapped_manage def _create_year_file(directory): """Cut the household's entity-table file into a year file.""" - source = _write_entity_tables(directory / "populace_layout.h5") + source = _write_entity_tables(directory / "microcosm_layout.h5") created = create_datasets( datasets=[source], years=[YEAR], @@ -771,7 +771,7 @@ def test_ensure_datasets_regenerates_a_year_file_with_only_the_renames_record( def test_create_datasets_stamps_each_year_file_after_saving_it(tmp_path): - source = _write_entity_tables(tmp_path / "populace_layout.h5") + source = _write_entity_tables(tmp_path / "microcosm_layout.h5") events = [] save = PolicyEngineUSDataset.save stamp = us_datasets.write_year_file_stamp @@ -807,7 +807,7 @@ def recording_stamp(path, value): def test_a_year_file_whose_stamp_was_never_written_is_out_of_date(tmp_path): - source = _write_entity_tables(tmp_path / "populace_layout.h5") + source = _write_entity_tables(tmp_path / "microcosm_layout.h5") def stop(path, value): raise RuntimeError("stopped before stamping") diff --git a/tests/test_us_legacy_spm.py b/tests/test_us_legacy_spm.py index 7654cee5d..3a78c5622 100644 --- a/tests/test_us_legacy_spm.py +++ b/tests/test_us_legacy_spm.py @@ -39,17 +39,17 @@ independence_roles, ) from policyengine.tax_benefit_models.us.legacy_spm.registry import ( - POPULACE_US_2024_ACS_LOCAL_BUILD_O, - POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263, + MICROCOSM_US_2024_ACS_LOCAL_BUILD_O, + MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263, ) from policyengine.tax_benefit_models.us.legacy_spm.universe import ( classify_acs_household_population, ) ACS = "acs_2024_1yr" -BUILD_O = POPULACE_US_2024_ACS_LOCAL_BUILD_O +BUILD_O = MICROCOSM_US_2024_ACS_LOCAL_BUILD_O #: The bundle's certified ACS-local file: scope rule only, roles stored. -REBUILD = POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263 +REBUILD = MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263 def _tables(): diff --git a/tests/test_us_legacy_spm_integration.py b/tests/test_us_legacy_spm_integration.py index 22c3b85ca..7d4c8c776 100644 --- a/tests/test_us_legacy_spm_integration.py +++ b/tests/test_us_legacy_spm_integration.py @@ -69,15 +69,15 @@ SPM_MEASUREMENT_VARIABLES, ) from policyengine.tax_benefit_models.us.legacy_spm.registry import ( # noqa: E402 - POPULACE_US_2024_ACS_LOCAL_BUILD_O, - POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263, + MICROCOSM_US_2024_ACS_LOCAL_BUILD_O, + MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263, ) from policyengine.tax_benefit_models.us.model import PolicyEngineUSLatest # noqa: E402 # The ``us`` package's ``model`` attribute is the model version, not the module. us_model = importlib.import_module("policyengine.tax_benefit_models.us.model") -BUILD_O = POPULACE_US_2024_ACS_LOCAL_BUILD_O +BUILD_O = MICROCOSM_US_2024_ACS_LOCAL_BUILD_O LIST_PIN = BUILD_O.independence_list YEAR = 2026 ACS = "acs_2024_1yr" @@ -792,7 +792,7 @@ def test_other_sources_get_no_declarations(tmp_path): # --- The microcosm#1263 rebuild: scope rule, roles stored ------------------- -REBUILD = POPULACE_US_2024_ACS_LOCAL_MICROCOSM_1263 +REBUILD = MICROCOSM_US_2024_ACS_LOCAL_MICROCOSM_1263 #: The roles the rebuilt source stores: ACS head, ASEC head and the ASEC teen #: who heads their own SPM unit. REBUILD_ROLES = [True, False, False, False, True, True] diff --git a/tests/test_us_regional_input_surface.py b/tests/test_us_regional_input_surface.py index 76b11f786..261c02573 100644 --- a/tests/test_us_regional_input_surface.py +++ b/tests/test_us_regional_input_surface.py @@ -36,7 +36,7 @@ MANIFEST_URI, US_LOCAL_AREA_MANIFEST_URI, _local_area_release_manifest_payload, - _populace_manifest_payload_without_regions, + _microcosm_manifest_payload_without_regions, _response, _tmp_bundle, _without_releases_record, @@ -420,7 +420,7 @@ def local_area_release() -> dict: def national_release() -> dict: - release = _populace_manifest_payload_without_regions() + release = _microcosm_manifest_payload_without_regions() release["compatible_model_packages"] = [ {"name": "policyengine-us", "specifier": f">={BUILT_WITH},<1.725"} ] diff --git a/tests/test_us_regions.py b/tests/test_us_regions.py index f1cba3611..8d6517f34 100644 --- a/tests/test_us_regions.py +++ b/tests/test_us_regions.py @@ -190,7 +190,7 @@ def test__given_ca_first_district__then_has_correct_format(self): def test__given_at_large_district__then_filter_uses_zero_district_geoid(self): """Given: an at-large congressional district When: Checking its row filter - Then: It uses the Populace/Census SS00 district GEOID convention + Then: It uses the Microcosm/Census SS00 district GEOID convention """ # When ak_al = us_region_registry.get("congressional_district/AK-01")