Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/microcosm-name-sweep-20261106.changed.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions docs/bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ python scripts/bundle.py certify-data \
--manifest-uri hf://dataset/policyengine/populace-uk-private@<release>/releases/<release>/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 \
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/countries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions docs/engineering/skills/data-certification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions docs/microsim.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
)
Expand Down
6 changes: 3 additions & 3 deletions docs/regions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions docs/release-bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -196,7 +196,7 @@ python scripts/bundle.py certify-data --country us \
--manifest-uri "hf://dataset/policyengine/populace-us@<tag>/releases/<tag>/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 \
Expand All @@ -205,7 +205,7 @@ python scripts/bundle.py certify-data --country us --data-producer populace \
--model-version "<policyengine-us-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
Expand Down
24 changes: 16 additions & 8 deletions examples/belgium_axiom_pilot.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
"""
Expand All @@ -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,
)
Expand All @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion src/policyengine/countries/us/data/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/policyengine/countries/us/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
46 changes: 30 additions & 16 deletions src/policyengine/provenance/certification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...]] = {
Expand Down Expand Up @@ -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 ()


Expand All @@ -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]:
Expand All @@ -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", {})
Expand Down Expand Up @@ -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/")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1561,7 +1570,7 @@ def certify(
)


class PopulaceDataProducerCertificationStrategy(DataProducerCertificationStrategy):
class MicrocosmDataProducerCertificationStrategy(DataProducerCertificationStrategy):
data_producer = "populace"

def certify(
Expand Down Expand Up @@ -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}.")
Expand Down
Loading
Loading