Add entity-table checkpoint save/load primitives#8
Merged
Conversation
Country-agnostic pipeline checkpoint primitives that persist a named dict of entity DataFrames to parquet + ``metadata.json`` and read them back. Country-specific wrappers (microplex-us, microplex-uk, ...) can use these to serialize their bundle dataclasses at a named pipeline stage — ``post_imputation``, ``post_microsim``, etc. — so a downstream rerun can resume from a saved state without repeating synthesis, donor imputation, or tax-benefit microsim. - ``save_entity_table_checkpoint(tables, path, *, stage, extra_metadata)`` - ``load_entity_table_checkpoint(path, *, expected_stage=None)`` - ``extra_metadata`` is attached under ``"extra"`` and round-trips unchanged — useful for config/source fingerprints that a caller wants to check for cache invalidation. Tests: 7 round-trip cases covering multi-table dicts, ``None`` entries, metadata schema, ``expected_stage`` mismatch, overwrite behavior, and invalid-stage rejection. All 20 ``tests/core/*`` pass. Motivation: microplex-us currently holds an equivalent pattern (``save_us_pipeline_checkpoint``, ``load_us_pipeline_checkpoint``) that reimplements the same parquet-dir + metadata layout. Hoisting the generic primitive here avoids duplicating it across every country package and makes the save/load format consistent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
metadata.json.save_entity_table_checkpoint(tables, path, *, stage, extra_metadata)/load_entity_table_checkpoint(path, *, expected_stage=None).extra_metadataround-trips unchanged under an"extra"key — callers use this for config/source fingerprints to decide if a checkpoint is stale.Motivation
microplex-ushassave_us_pipeline_checkpoint/load_us_pipeline_checkpointthat reimplement the same parquet-dir + metadata layout. Hoisting the generic primitive here avoids duplicating it across every country package (UK / US / others) and keeps the save/load format consistent. Enablespost_imputation/post_microsimrecalibration flows that skip the ~11 h synthesis step.Test plan
tests/core/test_checkpoints.py(round-trip, None tables, metadata schema, extra_metadata, missing-path, expected_stage mismatch, overwrite, empty-stage rejection).tests/core/*pass locally.microplex-usswappingsave_us_pipeline_checkpointto delegate tosave_entity_table_checkpoint.