PolicyEngine / PolicyEngine/policyengine-api
Persist and return the resolved model/data release bundle in policyengine-api
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18
- Forks
- 33
- Avg merge
- 23h 40m
- Merged PRs (30d)
- 22
Description
Problem
policyengine-api currently records or exposes package versions in a few places, but it does not persist and return the resolved immutable execution bundle for a simulation.
That creates three reproducibility problems:
- household calculations run against whatever country package is installed in-process, with no explicit model/data pin at execution time
- economy flows have partial
model_versionplumbing but effectively no real data-version pinning - cache keys are based on request payloads rather than the resolved execution bundle
Relevant code paths:
- household execution instantiates the installed country package
Simulation(...)directly and only reports the installed package version in metadata:policyengine_api/country.py - economy setup hardcodes dataset version resolution to
None, builds dataset aliases like...@None, and strips that suffix back off during setup:policyengine_api/data/model_setup.py,policyengine_api/services/economy_service.py - the Modal adapter drops
data_versionbefore job submission:policyengine_api/libs/simulation_api_modal.py - cache keys are hashes of request bodies, not of the resolved bundle:
policyengine_api/utils/cache_utils.py - the bump workflow only updates country package versions, so deployment automation also treats package version as the whole contract:
gcp/bump_country_package.py
Desired contract
For every simulation or cached result, the API should persist and return a resolved immutable bundle, not just a country ID or API version.
At minimum that bundle should include:
- orchestrator version if applicable (
policyengine.pyor equivalent) - country model package name/version
- country data package name/version
- resolved dataset artifact locator or manifest revision
- checksum or manifest ID for verification
This should apply to both household-style in-process calculations and economy/report-style asynchronous calculations.
What should change
- Resolve and persist the execution bundle at simulation creation time.
- Return that bundle in simulation metadata and user-facing API responses.
- Stop dropping
data_versionor equivalent bundle identity before job submission. - Make cache keys and dedupe keys include the resolved bundle identity.
- Update deployment/version-bump tooling so it does not treat country package version alone as the full runtime contract.
- Keep backward compatibility for existing clients where possible, but add new structured provenance fields rather than overloading the current
api_versionfield.
Acceptance criteria
- Household calculations and economy calculations both persist the resolved model/data bundle used at execution time.
- API responses expose structured provenance fields rather than only
api_versionor country package version. - The economy pipeline no longer hardcodes dataset version resolution to
None. - The Modal submission path preserves the resolved bundle, including data release identity.
- Cache and dedupe keys include the resolved bundle identity so floating defaults cannot collide across releases.
- Deployment/version bump workflows can update or verify the full runtime bundle, not just the country model package version.
Upstream dependencies
This should consume the data-release contracts from:
- PolicyEngine/policyengine-us-data#724
- PolicyEngine/policyengine-uk-data#322
And it should stay aligned with the orchestration work in:
- PolicyEngine/policyengine.py#270
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the household and economy flows through policyengine_api/country.py, policyengine_api/data/model_setup.py, and policyengine_api/services/economy_service.py, then inspect the Modal and cache paths in policyengine_api/libs/simulation_api_modal.py and policyengine_api/utils/cache_utils.py. Done means both calculation paths persist and return the resolved model/data bundle, preserve it through submission, and include it in cache and dedupe identities; also review gcp/bump_country_package.py for deployment coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend, devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100