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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,10 @@ writing the H5 as manifest artifacts: `input_coverage.json`,
record the per-run QRF tail register (`qrf_tail_register`), the export-mass
reference and the stored-input verdict (`stored_inputs`), so a waiver ships
with the release it waives, and a `gate_evidence` block that says of each
verdict whether it is bound, skipped by flag or never evaluated.
verdict whether it is bound, skipped by flag or never evaluated. A
`--scf-education-debt` build also lists its two SCF education-debt fit tables,
`us_scf_education_debt_fit.json` and `us_scf_education_debt_calibrated_fit.json`,
as manifest artifacts (microcosm#1074).

The QRF tail gate checks a sparse QRF output only when it has 500 or more
carriers, the records with positive weighted absolute mass, and reports one
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1074-publish-scf-education-debt-fits.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A `--scf-education-debt` release now publishes its two SCF education-debt fit tables, `us_scf_education_debt_fit.json` (at the pre-calibration weights) and `us_scf_education_debt_calibrated_fit.json` (at the shipped weights). The release tool writes both into the release directory, not the artifacts directory, and the release manifest lists them as `diagnostics` artifacts, so `microcosm-publish-release-build` publishes them into the build's folder, `releases/<release>/<build>/`, without `--extra-file`. Before, the manifest listed neither, so a publish left both on the run host. A build without the flag writes and lists neither, and a flagged build missing either table fails before it writes a manifest (#1074).
17 changes: 11 additions & 6 deletions docs/us-fact-to-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ borrower is a person whose federal balance is positive.
Parent PLUS row ($117.9B, 6.8% of the loan-type dollar rows) is a lower
bound on the stage's `federal_parent_plus_loan_balance`, which holds the
balances the stage classifies as Parent PLUS, consolidated or not. That is
an inference, not FSA's statement. Every other family pins the total, so a target on
either side of FSA's split (Parent PLUS, or every other loan type) would
still constrain the split. Both rows stay diagnostic, and the receipt compares the host's
Parent PLUS share with FSA's.
an inference, not FSA's statement. Every other family pins the total, so a
target on either side of FSA's split (Parent PLUS, or every other loan type)
would still constrain the split. Both rows stay diagnostic, and the receipt
compares the host's Parent PLUS share with FSA's.
- **The reference date.** The latest quarter every bound table publishes, FY2026
Q2 (31 March 2026) in the chronicle#347 packages: the location workbook
publishes only that date, so the age and debt-size tables bind at it too
Expand Down Expand Up @@ -272,13 +272,18 @@ borrower is a person whose federal balance is positive.
materializer. While the stage is opt-in the family stays off the one-surface
target-parity contract (`_without_opt_in_student_loan_targets`).
- **The release's own fit table.** A `--scf-education-debt` build writes the
stage's fit table (`us_scf_education_debt_fit_table`) twice in its artifacts
stage's fit table (`us_scf_education_debt_fit_table`) twice in its release
directory: at the staged frame's pre-calibration weights
(`us_scf_education_debt_fit.json`), and at the weights it ships, on the
frame it exports, before any post-export scoring or terminal gate
(`us_scf_education_debt_calibrated_fit.json`). The second reports the share
of households with debt, by age, race and income quintile, at the weights
the release ships.
the release ships. The release manifest lists both as `diagnostics`
artifacts (`us_scf_education_debt_fit` and
`us_scf_education_debt_calibrated_fit`), so `microcosm-publish-release-build`
publishes them into the build's folder, `releases/<release>/<build>/`,
without `--extra-file`. A build without the flag writes neither and lists
neither.
- **Known limits, measured.** The receipt
(`experiments/1074-fsa-calibration-receipts.md`) refits the published
default with and without the family. The stage gives balances to reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
_REASON_LOAN_TYPE_DOLLARS = (
"FSA's notes don't say whether its Parent PLUS row leaves out loans the Secretary "
"paid off through consolidation (34 CFR 685.220(f)), the stage's column holds "
"the balances it classifies as Parent PLUS, and every other family pins the total."
"the balances the stage classifies as Parent PLUS, consolidated or not, and "
"every other family pins the total."
)
_REASON_STAFFORD_SUBTOTAL = (
"Stafford (Combined) is a subtotal of rows the table already lists."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ def fake_with_inputs(base_frame, *, seed, time_period, scf_education_debt_donor)
scf_2025_summary_extract=Path("rscfp2025.dta"),
scf_2025_full_extract=Path("p25i6.dta"),
)
fit_path = tmp_path / "artifacts" / "us_scf_education_debt_fit.json"
fit_path = tmp_path / "release" / "us_scf_education_debt_fit.json"
assert (
builder._with_scf_education_debt_stage(
frame, args=args, telemetry=None, fit_path=fit_path
Expand Down Expand Up @@ -2305,7 +2305,7 @@ def test_scf_education_debt_fit_is_written_at_calibrated_weights_before_scoring(
lambda base_frame: seen.append(base_frame) or fit,
)
name = builder.US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME
path = tmp_path / "artifacts" / name
path = tmp_path / "release" / name
builder._write_us_scf_education_debt_fit(
path, frame, weights="calibrated_household_weights"
)
Expand Down Expand Up @@ -2344,7 +2344,7 @@ def position(predicate) -> int:
assert ast.unparse(statement.test) == "args.scf_education_debt"
(call,) = calls(statement, "_write_us_scf_education_debt_fit")
assert [ast.unparse(arg) for arg in call.args] == [
"artifact_root / US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME",
"release_dir / US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME",
"export_frame",
]
assert {kw.arg: ast.unparse(kw.value) for kw in call.keywords} == {
Expand Down Expand Up @@ -13289,6 +13289,128 @@ def score_holdout(name, consumer, **kwargs):
assert failures == []


def _write_scf_education_debt_fits(builder, monkeypatch, release_dir, filenames):
monkeypatch.setattr(
builder,
"us_scf_education_debt_fit_table",
lambda frame: {"households": {"share_with_federal_education_debt": 0.2}},
)
for filename in filenames:
builder._write_us_scf_education_debt_fit(
release_dir / filename, object(), weights="calibrated_household_weights"
)


SCF_EDUCATION_DEBT_FIT_ARTIFACT_PATHS = {
"us_scf_education_debt_fit": "us_scf_education_debt_fit.json",
"us_scf_education_debt_calibrated_fit": "us_scf_education_debt_calibrated_fit.json",
}


@pytest.mark.parametrize("flag", (True, False), ids=("flag", "no_flag"))
def test_build_manifests_lists_scf_education_debt_fits_only_with_the_flag(
monkeypatch, tmp_path, flag
) -> None:
"""microcosm#1074: a --scf-education-debt build's two fit tables are
diagnostics artifacts of its release, so the publisher publishes them into
the build's folder, releases/<release>/<build>/. A build without the flag
lists neither, even beside stray copies in its release directory."""
from microcosm.data.contract import (
_check_local_artifact_hashes,
_check_release_manifest,
)
from microcosm.data.release import (
_release_manifest_release_artifacts,
_release_manifest_root_artifacts,
)

builder = _load_builder_module()
assert builder.US_SCF_EDUCATION_DEBT_FIT_ARTIFACTS == (
SCF_EDUCATION_DEBT_FIT_ARTIFACT_PATHS
)
release_id, release_dir, artifact_root = _gate_evidence_release_dir(
builder, monkeypatch, tmp_path, coverage={}
)
filenames = set(SCF_EDUCATION_DEBT_FIT_ARTIFACT_PATHS.values())
_write_scf_education_debt_fits(builder, monkeypatch, release_dir, filenames)
builder._build_manifests(
**_minimal_manifest_kwargs(builder, release_id, release_dir, artifact_root),
scf_education_debt=flag,
)

manifest = json.loads((release_dir / "release_manifest.json").read_text())
listed = {
key: entry
for key, entry in manifest["artifacts"].items()
if entry["path"] in filenames
}
published = set(_release_manifest_release_artifacts(release_dir))
assert not filenames & set(_release_manifest_root_artifacts(release_dir))
if not flag:
assert listed == {}
assert not filenames & published
return
assert listed == {
key: {
"kind": "diagnostics",
"path": filename,
"repo_id": builder.REPO_ID,
"revision": release_id,
"sha256": hashlib.sha256((release_dir / filename).read_bytes()).hexdigest(),
}
for key, filename in SCF_EDUCATION_DEBT_FIT_ARTIFACT_PATHS.items()
}
assert filenames <= published
failures: list[str] = []
_check_release_manifest(manifest, release_id, failures)
_check_local_artifact_hashes(release_dir, manifest, failures)
assert failures == []


def test_build_manifests_refuses_a_scf_education_debt_build_missing_a_fit(
monkeypatch, tmp_path
) -> None:
builder = _load_builder_module()
release_id, release_dir, artifact_root = _gate_evidence_release_dir(
builder, monkeypatch, tmp_path, coverage={}
)
_write_scf_education_debt_fits(
builder, monkeypatch, release_dir, [builder.US_SCF_EDUCATION_DEBT_FIT_FILENAME]
)
with pytest.raises(RuntimeError, match="us_scf_education_debt_calibrated_fit"):
builder._build_manifests(
**_minimal_manifest_kwargs(builder, release_id, release_dir, artifact_root),
scf_education_debt=True,
)
assert not (release_dir / "build_manifest.json").exists()
assert not (release_dir / "release_manifest.json").exists()


def test_main_writes_scf_education_debt_fits_where_its_manifest_lists_them() -> None:
"""_main writes the pre-calibration fit into the release directory (the
calibrated one is pinned above) and lists both only under the flag."""
import ast
import inspect

builder = _load_builder_module()
tree = ast.parse(inspect.getsource(builder._main))

def keywords(function: str) -> dict[str, str]:
(call,) = [
node
for node in ast.walk(tree)
if isinstance(node, ast.Call) and getattr(node.func, "id", "") == function
]
return {kw.arg: ast.unparse(kw.value) for kw in call.keywords}

assert keywords("_with_scf_education_debt_stage")["fit_path"] == (
"release_dir / US_SCF_EDUCATION_DEBT_FIT_FILENAME if dry_run is None else None"
)
assert keywords("_build_manifests")["scf_education_debt"] == (
"args.scf_education_debt"
)


@pytest.mark.parametrize("readable", (True, False), ids=("available", "unavailable"))
def test_build_manifests_selects_population_structure_holdout_for_publication(
monkeypatch, tmp_path, readable
Expand Down
56 changes: 53 additions & 3 deletions tools/build_us_fiscal_refresh_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,14 +1078,25 @@ def _env_default(name: str, default: str) -> str:
"reported_has_subsidized_marketplace_health_coverage_at_interview"
)
US_ACA_REPORTED_MARKETPLACE_COVERAGE = "has_marketplace_health_coverage_at_interview"
#: The SCF education-debt fit table (microcosm#1073), in the artifacts
#: The SCF education-debt fit table (microcosm#1073), in the release
#: directory of a ``--scf-education-debt`` build: at the staged frame's
#: pre-calibration weights, and at the release's calibrated weights before any
#: post-export scoring (microcosm#1074).
US_SCF_EDUCATION_DEBT_FIT_FILENAME = "us_scf_education_debt_fit.json"
US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME = (
"us_scf_education_debt_calibrated_fit.json"
)
#: Both fit tables, keyed by their release-manifest artifact key. Only a
#: ``--scf-education-debt`` build writes them, so only its manifest lists
#: them, and ``microcosm-publish-release-build`` publishes them into the
#: build's folder (``releases/<release>/<build>/``) with the other
#: diagnostics, without ``--extra-file``.
US_SCF_EDUCATION_DEBT_FIT_ARTIFACTS: dict[str, str] = {
"us_scf_education_debt_fit": US_SCF_EDUCATION_DEBT_FIT_FILENAME,
"us_scf_education_debt_calibrated_fit": (
US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME
),
}
US_ACA_APTC_TARGET_TABLE = "cms_aca_aptc_recipients_by_state"
US_ACA_TARGET_ROLE_TABLES = {
"aca_ptc_recipients": US_ACA_APTC_TARGET_TABLE,
Expand Down Expand Up @@ -10583,6 +10594,35 @@ def _gate_evidence_artifacts(release_dir: Path, *, revision: str) -> dict[str, d
}


def _scf_education_debt_fit_artifacts(
release_dir: Path, *, revision: str
) -> dict[str, dict]:
"""Release-manifest entries for a ``--scf-education-debt`` build's fit tables.

The build writes both into the release directory before its manifests, so
a missing table fails the build instead of shipping without it.
"""
missing = sorted(
filename
for filename in US_SCF_EDUCATION_DEBT_FIT_ARTIFACTS.values()
if not (release_dir / filename).is_file()
)
if missing:
raise RuntimeError(
"A --scf-education-debt build must write its fit tables before its "
f"manifests; {release_dir} is missing {missing}."
)
return {
key: _artifact_entry(
filename,
_sha256(release_dir / filename),
kind="diagnostics",
revision=revision,
)
for key, filename in US_SCF_EDUCATION_DEBT_FIT_ARTIFACTS.items()
}


def _gate_evidence_status(
gate_evidence_artifacts: Mapping[str, object],
*,
Expand Down Expand Up @@ -11013,6 +11053,7 @@ def _build_manifests(
post_export_scoring: Mapping[str, object] | None = None,
diagnostics_outcome: DiagnosticsWriteOutcome | None = None,
scf_wealth_signal: Mapping[str, object] | None = None,
scf_education_debt: bool = False,
) -> None:
dataset_path = artifact_root / dataset_filename
calibration_path = artifact_root / calibration_filename
Expand Down Expand Up @@ -11053,6 +11094,13 @@ def _build_manifests(
# rather than only in loose diagnostics that never ship. The same blocks
# ride build_manifest.json and release_manifest.json's build section.
gate_evidence_artifacts = _gate_evidence_artifacts(release_dir, revision=release_id)
# microcosm#1074: checked before either manifest is written, so a build
# missing a fit table writes neither manifest.
scf_education_debt_fit_artifacts = (
_scf_education_debt_fit_artifacts(release_dir, revision=release_id)
if scf_education_debt
else {}
)
qrf_tail_register = _qrf_tail_register_manifest_block(release_dir)
stored_inputs = _stored_inputs_manifest_block(
release_dir, dataset_sha256=dataset_sha
Expand Down Expand Up @@ -11620,6 +11668,7 @@ def _build_manifests(
if (release_dir / "demographics.json").exists()
else {}
),
**scf_education_debt_fit_artifacts,
**gate_evidence_artifacts,
},
}
Expand Down Expand Up @@ -14980,7 +15029,7 @@ def _main(argv: Sequence[str] | None = None) -> int | None:
args=args,
telemetry=telemetry,
fit_path=(
artifact_root / US_SCF_EDUCATION_DEBT_FIT_FILENAME
release_dir / US_SCF_EDUCATION_DEBT_FIT_FILENAME
if dry_run is None
else None
),
Expand Down Expand Up @@ -15903,7 +15952,7 @@ def _main(argv: Sequence[str] | None = None) -> int | None:
# follows the export and cleanup statements, which
# test_us_post_export_scoring runs on their own.
_write_us_scf_education_debt_fit(
artifact_root / US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME,
release_dir / US_SCF_EDUCATION_DEBT_CALIBRATED_FIT_FILENAME,
export_frame,
weights="calibrated_household_weights",
)
Expand Down Expand Up @@ -17174,6 +17223,7 @@ def _main(argv: Sequence[str] | None = None) -> int | None:
post_export_scoring=post_export_scoring,
diagnostics_outcome=diagnostics_outcome,
scf_wealth_signal=scf_wealth_signal,
scf_education_debt=args.scf_education_debt,
)
# Both manifests name the release and this build, in the build-folder
# layout, before telemetry attaches them; the directory must then pass
Expand Down
2 changes: 1 addition & 1 deletion tools/route_a/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ overnight chain is alive, unless `EARLY_START_AFTER_HEAVY=1` and its log records
| `preflight-base` | Runs `preflight_us_release_gates.py` on that H5 and the pinned feed, with the configured new-lineage mode and optional export-mass reference. Accepts 0 (clean) or 2 (AT-RISK); `RELEASE_DESPITE_PREFLIGHT_FAIL=1` also accepts 1 here. |
| `release` | Runs `build_us_fiscal_refresh_release.py --base-h5` with the feed, SSI basis, SCF extract and configured release arguments; its `--release-id` is the build ID. Requires exit 0 and `<release-out>/releases/microcosm-us-2024-national/release_manifest.json`. Staging telemetry is enabled for this stage. |
| `preflight-release` | Repeats the release-gate preflight with the candidate's release manifest. Accepts 0 or 2. |
| `publisher-preflight` | Runs `microcosm-publish-release-build --preflight-only` against the release directory, `<release-out>/releases/microcosm-us-2024-national`, where a national run writes its build, and the artifacts. Requires exit 0. The command checks the build with its release contract, prints what it would publish, and starts no emitter. |
| `publisher-preflight` | Runs `microcosm-publish-release-build --preflight-only` against the release directory, `<release-out>/releases/microcosm-us-2024-national`, where a national run writes its build, and the artifacts. Requires exit 0. The command checks the build with its release contract, prints what it would publish, and starts no emitter. It takes no `--extra-file`: the command publishes every artifact the release manifest lists, including the two SCF education-debt fit tables of a release run with `--scf-education-debt` in `RELEASE_EXTRA_ARGS`. |

Both gate preflights and the publisher preflight remove the HF credential
variables and Slack webhook variables, set `POPULACE_RELEASE_ENV=/dev/null` and
Expand Down
4 changes: 3 additions & 1 deletion tools/route_a/route_a.sh
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ fi
# --- 8. Publisher preflight, offline: microcosm-publish-release-build checks
# the build with its release contract and lists what it would publish when
# --preflight-only is set, and starts no emitter. Secrets are stripped as
# overnight_chain.sh does. ---
# overnight_chain.sh does. It takes no --extra-file: the command publishes
# every artifact the release manifest lists, a --scf-education-debt build's
# two fit tables included. ---
if ! stage_done publisher-preflight; then
write_config publisher-preflight 24 16 22 7200 14400 "$W" "$PF_ENV" -- "${NOSECRETS[@]}" \
"PATH=$W/.venv/bin:/usr/bin:/bin:/usr/sbin:/sbin" "$W/.venv/bin/microcosm-publish-release-build" \
Expand Down
Loading