Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ heading here; `tests/test_repo_hygiene.py` asserts that they do.

## [Unreleased]

### Drift canaries follow the pages; two pinned-model gates

- **HANK canary.** `/connect` quotes `pe-macro hank-shock --kind monetary --size -0.0025 --persistence 0.61` and "about 13bp off the policy rate on impact". The canary ran the tool's default persistence (0.9), a different experiment in which the policy rate rises on impact. It now runs 0.61 and checks the quoted number: policy rate −0.132pp on impact, with output +0.493% on impact and +0.097% at quarter 3 as regression pins (hosted and local agree at us-hank-model `58353e5`).
- **DEFINE canary.** Its quote text said "PASS — peak +0.92% vs ≈+1%"; the page says "PINNED, not a replication — peak +0.92% vs our own 0.7–1.3% band". The text now matches. The check itself is unchanged.
- **Nightly gates** (`tests/test_contract.py`, slow): the household lever must be symmetric and linear to within 2% of its peak response (0.15% at obr-macroeconomic-model `0e44ec8`; 32% and 16% at the non-converging pin in #215), and the hand-typed SVAR data-edge strings must match the last quarter of the pinned data (#225).

### BoE SVAR re-pin to `17f5d82`

- **Pin.** BoE SVAR `c827ab86` → `17f5d824` (boe-var-model #34, world CPI seasonal adjustment; #35, November 2026 MPR comparator and 2026Q3 scoring). After a redeploy the hosted `forecast_uk` and `latest_shocks` run this pin.
Expand Down
25 changes: 18 additions & 7 deletions integration/drift/canaries.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,33 @@
"tool": "hank_shock",
"args": {
"kind": "monetary",
"size": -0.0025
"size": -0.0025,
"persistence": 0.61
},
"cost": "cheap",
"local_cheap": true,
"quoted_at": "connect/index.html",
"quote": "pe-macro hank-shock --kind monetary --size -0.0025 (command quoted; no number on the page)",
"basis": "regression pin, not a site figure: the page quotes the command only. Hosted us-hank-model 19a8e5e on 6 Nov 2026 gave Y +0.361% on impact, reproduced locally at 58353e5 on 18 Nov 2026 (the +0.0025 run in r5/cross-model.md gave −0.36%, so the model is linear in the sign as expected) and +0.175% at quarter 3",
"quote": "pe-macro hank-shock --kind monetary --size -0.0025 --persistence 0.61 (the command the page quotes); the prompt beside it says about 13bp off the policy rate on impact",
"basis": "the page quotes the command at persistence 0.61 and one number, the impact fall in the policy rate (about 13bp). Before 25 Nov 2026 this canary ran the tool's default persistence, 0.9, which is a different experiment: there the policy rate rises 0.25pp on impact and output moves +0.361%. Local run at us-hank-model 58353e5 on 25 Nov 2026, persistence 0.61: policy rate i -0.1316pp on impact, output Y +0.4926% on impact and +0.0971% at quarter 3. The two output checks are regression pins, not site figures",
"checks": [
{
"name": "policy_rate_impact_pp",
"path": [
"results",
0,
"i"
],
"expected": -0.132,
"tolerance": 0.005
},
{
"name": "output_impact_pct",
"path": [
"results",
0,
"Y"
],
"expected": 0.361,
"expected": 0.493,
"tolerance": 0.005
},
{
Expand All @@ -181,11 +192,11 @@
3,
"Y"
],
"expected": 0.175,
"expected": 0.097,
"tolerance": 0.005
}
],
"quoted_anchor": "--size -0.0025"
"quoted_anchor": "--size -0.0025 --persistence 0.61"
},
{
"id": "svar_forecast_median",
Expand Down Expand Up @@ -243,7 +254,7 @@
"local_cheap": true,
"check_provenance": false,
"quoted_at": "define/validation/index.html",
"quote": "PASS — peak +0.92% vs ≈+1%",
"quote": "PINNED, not a replication — peak +0.92% vs our own 0.7–1.3% band",
"basis": "DEFINE-UK is never hosted (unlicensed upstream): the hosted check is that it still refuses; the number is checked against the cached pinned run with --local",
"checks": [
{
Expand Down
69 changes: 69 additions & 0 deletions integration/tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,75 @@ def _import_or_require(modname: str):
pytest.fail(msg) if require else pytest.skip(msg)


# ---------------------------------------------------------------------------
# Pinned-model gates (slow; the nightly contract job installs the pins)
# ---------------------------------------------------------------------------

@pytest.mark.slow
def test_svar_data_edge_strings_match_the_pinned_data():
"""The registry and model_summary state the SVAR data edge by hand.

They went stale once already: after the 2026Q2 dataset was pinned they
said 2026Q1 for a month (macro #225), while forecast_uk, which reads the
edge from the data, said 2026Q2. This reads the last quarter of the
installed data and fails when either string disagrees.

Slow-marked on purpose: the fast CI job installs boe_var from its HEAD,
not the pin, so there the data can run ahead of these strings without
anything being wrong here. The nightly contract job installs the pin.
"""
data = _import_or_require("boe_var.data")
from policyengine_macro import capabilities

edge = str(data.load_data().index[-1])
entry = capabilities.MODELS["boe-svar"]
assert entry["data_edge"] == edge, (
f"capabilities.MODELS['boe-svar']['data_edge'] says "
f"{entry['data_edge']!r}; the installed boe_var data ends {edge}"
)
assert edge in entry["data_vintage"], entry["data_vintage"]
vintage = core.svar_summary()["provenance"]["data_vintage"]
assert f"conditioning data through {edge}" in vintage, vintage
assert core._SVAR_EST_END <= edge


@pytest.mark.slow
def test_obr_household_lever_is_symmetric_and_linear():
"""A reform and its mirror image must score as mirror images.

score_reform(model="obr") injects the costing through HHDI_ADDFACTOR, so
its GDP figure is a difference of two solves on this lever. On 6 Nov
2026, at a pin where no quarter converged, +1000 and -1000 differed by
32% of the peak response and doubling the shock missed by 16% (macro
#215). At obr-macroeconomic-model 0e44ec8 both are 0.15%. The bound is
2% of the peak: loose enough for a re-pin to move it, tight enough that
a return of solver residue fails.
"""
_import_or_require("obr_macro")
run_reform = core._import_obr()

def solve(shock: float) -> list[float]:
df = run_reform(
name=f"HHDI_ADDFACTOR {shock:+g}", var="HHDI_ADDFACTOR",
shock=shock, start=core._OBR_START, end=core._OBR_DEFAULT_END,
periods=8, investment_closure=False,
)
assert df.attrs.get("solver_converged") is True, (
shock, df.attrs.get("solver_nonconverged_periods")
)
return [float(v) for v in df.delta_gdp_bn]

up, down, double = solve(1000.0), solve(-1000.0), solve(2000.0)
peak = max(abs(v) for v in up)
assert peak > 0.05, f"the household lever barely moved GDP: {up}"
# Revenue raised lowers GDP in every quarter, and the mirror raises it.
assert all(v < 0 for v in up) and all(v > 0 for v in down)
asymmetry = max(abs(a + b) for a, b in zip(up, down)) / peak
nonlinearity = max(abs(c - 2 * a) for a, c in zip(up, double)) / peak
assert asymmetry < 0.02, f"+1000 and -1000 differ by {asymmetry:.1%} of peak"
assert nonlinearity < 0.02, f"+2000 is {nonlinearity:.1%} of peak from 2 x +1000"


# ---------------------------------------------------------------------------
# boe_var (fast)
# ---------------------------------------------------------------------------
Expand Down