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/us-bundle-17224.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refresh the bundled US release manifest to policyengine-us 1.722.4.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uk = [
]
us = [
"policyengine_core==3.26.1",
"policyengine-us==1.715.2",
"policyengine-us==1.722.4",
]
dev = [
"pytest",
Expand All @@ -64,7 +64,7 @@ dev = [
"ruff>=0.9.0",
"policyengine_core==3.26.1",
"policyengine-uk==2.88.20",
"policyengine-us==1.715.2",
"policyengine-us==1.722.4",
"towncrier>=24.8.0",
"mypy>=1.11.0",
"pytest-cov>=5.0.0",
Expand Down
14 changes: 7 additions & 7 deletions src/policyengine/data/release_manifests/us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"policyengine_version": "4.14.2",
"model_package": {
"name": "policyengine-us",
"version": "1.715.2",
"sha256": "abf079828419762f5c4b0291a70f6e424744200f237e1ae0f06e25f10130c399",
"wheel_url": "https://files.pythonhosted.org/packages/45/a1/1d56bdbb69d7ce06bedd3892203a75ac3350a90c0b5fcea2fb50db46670f/policyengine_us-1.715.2-py3-none-any.whl"
"version": "1.722.4",
"sha256": "691d4aa9b1512d71d283b0b5805af5ba95ffed798fe471a97cf2195f4950b6e3",
"wheel_url": "https://files.pythonhosted.org/packages/20/fc/f6fa4ffbc79129a267d92782aba6889145fabfcb39023423fed1f468af3f/policyengine_us-1.722.4-py3-none-any.whl"
},
"data_package": {
"name": "policyengine-us-data",
"version": "1.115.5",
"repo_id": "policyengine/policyengine-us-data",
"release_manifest_path": "release_manifest.json",
"release_manifest_revision": "d47fb5475144260a75467d2f2e22b2d5d53d4d57"
"release_manifest_path": "releases/1.115.5/release_manifest.json",
"release_manifest_revision": "9531fe1d096244fe7eb45d791d52ef61b8a2a0a5"
},
"certified_data_artifact": {
"data_package": {
Expand All @@ -23,14 +23,14 @@
},
"build_id": "policyengine-us-data-1.115.5",
"dataset": "enhanced_cps_2024",
"uri": "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@d47fb5475144260a75467d2f2e22b2d5d53d4d57",
"uri": "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@9531fe1d096244fe7eb45d791d52ef61b8a2a0a5",
"sha256": "0a6b961ad363a421bde99f2c8e5d8f20370bcba45fd303050537a25bdd805b14"
},
"certification": {
"compatibility_basis": "legacy_compatible_model_package",
"data_build_id": "policyengine-us-data-1.115.5",
"built_with_model_version": "1.700.0",
"certified_for_model_version": "1.715.2",
"certified_for_model_version": "1.722.4",
"certified_by": "policyengine-us-data release manifest",
"data_build_fingerprint": "sha256:b0862de383ffcbe45f4ba0aa9c6aaec286cd4c6688c6ccb33f939bc176f9a8a0"
},
Expand Down
25 changes: 11 additions & 14 deletions src/policyengine/data/release_manifests/us.trace.tro.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@
"trov:hasArtifact": {
"@id": "composition/1/artifact/data_release_manifest"
},
"trov:hasLocation": "https://huggingface.co/policyengine/policyengine-us-data/resolve/d47fb5475144260a75467d2f2e22b2d5d53d4d57/release_manifest.json"
"trov:hasLocation": "https://huggingface.co/policyengine/policyengine-us-data/resolve/9531fe1d096244fe7eb45d791d52ef61b8a2a0a5/releases/1.115.5/release_manifest.json"
},
{
"@id": "arrangement/1/location/dataset",
"@type": "trov:ArtifactLocation",
"trov:hasArtifact": {
"@id": "composition/1/artifact/dataset"
},
"trov:hasLocation": "https://huggingface.co/policyengine/policyengine-us-data/resolve/d47fb5475144260a75467d2f2e22b2d5d53d4d57/enhanced_cps_2024.h5"
"trov:hasLocation": "https://huggingface.co/policyengine/policyengine-us-data/resolve/9531fe1d096244fe7eb45d791d52ef61b8a2a0a5/enhanced_cps_2024.h5"
},
{
"@id": "arrangement/1/location/model_wheel",
"@type": "trov:ArtifactLocation",
"trov:hasArtifact": {
"@id": "composition/1/artifact/model_wheel"
},
"trov:hasLocation": "https://files.pythonhosted.org/packages/45/a1/1d56bdbb69d7ce06bedd3892203a75ac3350a90c0b5fcea2fb50db46670f/policyengine_us-1.715.2-py3-none-any.whl"
"trov:hasLocation": "https://files.pythonhosted.org/packages/20/fc/f6fa4ffbc79129a267d92782aba6889145fabfcb39023423fed1f468af3f/policyengine_us-1.722.4-py3-none-any.whl"
}
]
}
Expand All @@ -75,14 +75,14 @@
"@type": "trov:ResearchArtifact",
"schema:name": "policyengine.py bundle manifest for us",
"trov:mimeType": "application/json",
"trov:sha256": "c6d064defe7eafb2f2c69732d5b54f2df3477f933726beb38dc5396c0d8996d8"
"trov:sha256": "a920dc3f674025578ed0f8befae0af4f08d5aa197152ebd4b50bc70c20faf5e6"
},
{
"@id": "composition/1/artifact/data_release_manifest",
"@type": "trov:ResearchArtifact",
"schema:name": "policyengine-us-data release manifest 1.115.5",
"trov:mimeType": "application/json",
"trov:sha256": "577fbf704da44f63d0432dc3e80f3686eb3a32020d13ca6b7b6cf7eb60b4742c"
"trov:sha256": "16ba5b9ea74b8f5aa996cc66f6d28f64d2def4ea4ce087aec8d35c04ac706fc2"
},
{
"@id": "composition/1/artifact/dataset",
Expand All @@ -94,31 +94,28 @@
{
"@id": "composition/1/artifact/model_wheel",
"@type": "trov:ResearchArtifact",
"schema:name": "policyengine-us==1.715.2 wheel",
"schema:name": "policyengine-us==1.722.4 wheel",
"trov:mimeType": "application/zip",
"trov:sha256": "abf079828419762f5c4b0291a70f6e424744200f237e1ae0f06e25f10130c399"
"trov:sha256": "691d4aa9b1512d71d283b0b5805af5ba95ffed798fe471a97cf2195f4950b6e3"
}
],
"trov:hasFingerprint": {
"@id": "composition/1/fingerprint",
"@type": "trov:CompositionFingerprint",
"trov:sha256": "f8fc7d3c16b969ad8ef1522661631163613053aa2328428a6e59302567381ab5"
"trov:sha256": "3e324b0ae99e0ce580e9dffae19e4643be5c74723f2caf8a3b139ee09085aa0b"
}
},
"trov:hasPerformance": {
"@id": "trp/1",
"@type": "trov:TransparentResearchPerformance",
"pe:builtWithModelVersion": "1.700.0",
"pe:certifiedBy": "policyengine-us-data release manifest",
"pe:certifiedForModelVersion": "1.715.2",
"pe:ciGitRef": "refs/heads/main",
"pe:ciGitSha": "3b5979918486892fff7465e03e99176532593cb3",
"pe:ciRunUrl": "https://github.com/PolicyEngine/policyengine.py/actions/runs/27094103103",
"pe:certifiedForModelVersion": "1.722.4",
"pe:compatibilityBasis": "legacy_compatible_model_package",
"pe:dataBuildFingerprint": "sha256:b0862de383ffcbe45f4ba0aa9c6aaec286cd4c6688c6ccb33f939bc176f9a8a0",
"pe:dataBuildId": "policyengine-us-data-1.115.5",
"pe:emittedIn": "github-actions",
"rdfs:comment": "Certification of build policyengine-us-data-1.115.5 for policyengine-us 1.715.2.",
"pe:emittedIn": "local",
"rdfs:comment": "Certification of build policyengine-us-data-1.115.5 for policyengine-us 1.722.4.",
"trov:accessedArrangement": {
"@id": "arrangement/1"
},
Expand Down
27 changes: 18 additions & 9 deletions src/policyengine/provenance/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,17 @@ def refresh_release_bundle(
data_package_json = manifest_json["data_package"]
release_manifest_json = None
new_release_manifest_revision = None
current_release_manifest_revision = data_package_json.get(
"release_manifest_revision"
)
release_manifest_override = (
release_manifest_path is not None or release_manifest_revision is not None
)
new_release_manifest_path = release_manifest_path or data_package_json.get(
"release_manifest_path"
)
should_fetch_release_manifest = new_release_manifest_path is not None and (
new_data != old_data
or release_manifest_path is not None
or release_manifest_revision is not None
new_data != old_data or new_model != old_model or release_manifest_override
)
if should_fetch_release_manifest:
if release_manifest_path is None:
Expand All @@ -510,7 +514,11 @@ def refresh_release_bundle(
old_data=old_data,
new_data=new_data,
)
fetch_revision = release_manifest_revision or new_data
fetch_revision = release_manifest_revision or (
current_release_manifest_revision
if release_manifest_path is None and new_data == old_data
else new_data
)
release_manifest_fetch = _fetch_data_release_manifest(
repo_id=repo_id,
release_manifest_path=new_release_manifest_path,
Expand Down Expand Up @@ -560,7 +568,12 @@ def refresh_release_bundle(
)
dataset_repo_id = data_artifact_json.get("repo_id", repo_id)
dataset_path = data_artifact_json.get("path", dataset_path)
dataset_revision = data_artifact_json.get("revision", new_data)
dataset_revision_default = (
_old_revision
if new_data == old_data and not release_manifest_override
else new_data
)
dataset_revision = data_artifact_json.get("revision", dataset_revision_default)
if (
release_manifest_json is not None
and new_release_manifest_revision is not None
Expand All @@ -569,10 +582,6 @@ def refresh_release_bundle(
):
dataset_revision = new_release_manifest_revision

release_manifest_override = (
release_manifest_path is not None or release_manifest_revision is not None
)

# Only hit HF if the data version or release manifest target changed.
if new_data != old_data or release_manifest_override:
new_dataset_sha256 = data_artifact_json.get("sha256") or _hf_dataset_sha256(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"has_income_tax": true,
"has_region_registry": true,
"model_package_name": "policyengine-us",
"num_parameters_bucketed_100s": 883,
"num_variables_bucketed_100s": 51,
"num_parameters_bucketed_100s": 896,
"num_variables_bucketed_100s": 52,
"region_registry_country": "us"
}
82 changes: 79 additions & 3 deletions tests/test_bundle_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def sandbox(tmp_path: Path) -> dict:
},
"build_id": "policyengine-us-data-1.70.0",
"dataset": "enhanced_cps_2024",
"uri": "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@1.70.0",
"uri": "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@old-dataset-commit",
"sha256": "d" * 64,
},
"certification": {
Expand Down Expand Up @@ -208,6 +208,25 @@ def fake_urlopen(request, *args, **kwargs):
url = request.full_url
if "pypi.org" in url:
return _pypi_response("policyengine-us", "1.653.3")
if url.endswith("releases/1.70.0/release_manifest.json"):
return _data_release_manifest_response(
data_version="1.70.0",
dataset_sha256="d" * 64,
compatible_model_packages=[
{"name": "policyengine-us", "specifier": "==1.600.0"},
{"name": "policyengine-us", "specifier": "==1.653.3"},
],
extra_artifacts={
"enhanced_cps_2024": {
"kind": "microdata",
"path": "enhanced_cps_2024.h5",
"repo_id": "policyengine/policyengine-us-data",
"revision": "old-dataset-commit",
"sha256": "d" * 64,
}
},
headers={"x-repo-commit": "old-release-manifest-commit"},
)
raise AssertionError(f"Unexpected URL fetched: {url}")

with patch("policyengine.provenance.bundle.urlopen", side_effect=fake_urlopen):
Expand Down Expand Up @@ -239,6 +258,41 @@ def fake_urlopen(request, *args, **kwargs):
== "old-release-manifest-commit"
)
assert written["certified_data_artifact"]["sha256"] == "d" * 64
assert (
written["certified_data_artifact"]["uri"]
== "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@old-dataset-commit"
)


def test__bump_model_only_requires_data_release_manifest_compatibility(
sandbox,
) -> None:
def fake_urlopen(request, *args, **kwargs):
url = request.full_url
if "pypi.org" in url:
return _pypi_response("policyengine-us", "1.653.3")
if url.endswith("releases/1.70.0/release_manifest.json"):
return _data_release_manifest_response(
data_version="1.70.0",
model_version="1.600.0",
compatible_model_packages=[
{"name": "policyengine-us", "specifier": "==1.600.0"},
],
headers={"x-repo-commit": "old-release-manifest-commit"},
)
raise AssertionError(f"Unexpected URL fetched: {url}")

with patch("policyengine.provenance.bundle.urlopen", side_effect=fake_urlopen):
with pytest.raises(
ValueError,
match="Data release manifest is not certified",
):
refresh_release_bundle(
country="us",
model_version="1.653.3",
manifest_dir=sandbox["manifest_dir"],
pyproject_path=sandbox["pyproject_path"],
)


def test__bump_data_only_streams_hf_and_updates_uri(sandbox) -> None:
Expand Down Expand Up @@ -871,8 +925,30 @@ def fake_urlopen(request, *args, **kwargs):


def test__update_pyproject_false_leaves_pins_alone(sandbox) -> None:
def fake_urlopen(*args, **kwargs):
return _pypi_response("policyengine-us", "1.653.3")
def fake_urlopen(request, *args, **kwargs):
url = request.full_url
if "pypi.org" in url:
return _pypi_response("policyengine-us", "1.653.3")
if url.endswith("releases/1.70.0/release_manifest.json"):
return _data_release_manifest_response(
data_version="1.70.0",
dataset_sha256="d" * 64,
compatible_model_packages=[
{"name": "policyengine-us", "specifier": "==1.600.0"},
{"name": "policyengine-us", "specifier": "==1.653.3"},
],
extra_artifacts={
"enhanced_cps_2024": {
"kind": "microdata",
"path": "enhanced_cps_2024.h5",
"repo_id": "policyengine/policyengine-us-data",
"revision": "old-dataset-commit",
"sha256": "d" * 64,
}
},
headers={"x-repo-commit": "old-release-manifest-commit"},
)
raise AssertionError(f"Unexpected URL fetched: {url}")

with patch("policyengine.provenance.bundle.urlopen", side_effect=fake_urlopen):
result = refresh_release_bundle(
Expand Down
10 changes: 5 additions & 5 deletions tests/test_import_policyengine_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ def test_import_policyengine_bundle_verifies_and_vendors_release(
us_manifest = json.loads((release_manifest_dir / "us.json").read_text())
assert us_manifest["bundle_id"] == "us-4.14.0"
assert us_manifest["policyengine_version"] == "4.14.0"
assert us_manifest["model_package"]["version"] == "1.715.2"
assert us_manifest["model_package"]["version"] == "1.722.4"
assert (
us_manifest["certified_data_artifact"]["uri"]
== "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@data-sha"
)
assert us_manifest["certification"]["certified_for_model_version"] == "1.715.2"
assert us_manifest["certification"]["certified_for_model_version"] == "1.722.4"

pyproject = pyproject_path.read_text()
assert '"policyengine_core==3.26.1"' in pyproject
assert '"policyengine-us==1.715.2"' in pyproject
assert '"policyengine-us==1.722.4"' in pyproject
assert '"policyengine-uk==3.0.0"' in pyproject
assert (changelog_dir / "policyengine-bundle-4.14.0.changed.md").exists()

Expand Down Expand Up @@ -140,7 +140,7 @@ def _bundle_manifest(version: str) -> dict:
},
"policyengine-us": {
"name": "policyengine-us",
"version": "1.715.2",
"version": "1.722.4",
"resolution_status": "pinned",
},
"policyengine-uk": {
Expand All @@ -167,7 +167,7 @@ def _bundle_manifest(version: str) -> dict:

def _country_bundle(country_id: str, version: str) -> dict:
model_package = "policyengine-us" if country_id == "us" else "policyengine-uk"
model_version = "1.715.2" if country_id == "us" else "3.0.0"
model_version = "1.722.4" if country_id == "us" else "3.0.0"
data_package = (
"policyengine-us-data" if country_id == "us" else "policyengine-uk-data"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ def test_has_release_manifest_metadata(self):
assert us_latest.release_manifest is not None
assert us_latest.release_manifest.country_id == "us"
assert us_latest.model_package.name == "policyengine-us"
assert us_latest.model_package.version == "1.715.2"
assert us_latest.model_package.version == "1.722.4"
assert us_latest.data_package.name == "policyengine-us-data"
assert us_latest.data_package.version == "1.115.5"
assert (
us_latest.default_dataset_uri
== "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@d47fb5475144260a75467d2f2e22b2d5d53d4d57"
== "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@9531fe1d096244fe7eb45d791d52ef61b8a2a0a5"
)

def test_has_hundreds_of_parameters(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_release_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
PYPROJECT.read_text(),
re.MULTILINE,
).group(1)
US_MODEL_VERSION = "1.715.2"
US_MODEL_VERSION = "1.722.4"
US_BUILT_WITH_MODEL_VERSION = "1.700.0"
US_DATA_RELEASE_VERSION = "1.115.5"
US_DATA_RELEASE_PATH = "release_manifest.json"
US_DATA_RELEASE_REVISION = "d47fb5475144260a75467d2f2e22b2d5d53d4d57"
US_DATA_RELEASE_PATH = "releases/1.115.5/release_manifest.json"
US_DATA_RELEASE_REVISION = "9531fe1d096244fe7eb45d791d52ef61b8a2a0a5"
US_CERTIFICATION_SOURCE = "policyengine-us-data release manifest"
US_DEFAULT_DATASET_URI = (
"hf://policyengine/policyengine-us-data/"
Expand Down
Loading
Loading