From 471fc47a6136898dfa53995485c8e6a3baae1122 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 14:28:46 +0000 Subject: [PATCH 1/7] v0.3.0 amendment: design and predictions for R1-R4 and V6 (commit A) Pre-registers, before any code and before any re-run, the review-driven changes to the v0.3 checks (R1 verdict with declared coverage, R2 one field convention, R3 exogenous paths against the request, R4 GE target of T3 in the provider convention, V6 split), the new quantities, the re-run design (ii, iii) and the cells expected to differ from v0.2. Plan section 10 gets one line pointing to the new document. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaLSoFg2N1x4mzFYiwrgVT --- docs/CHECKS_PLAN_v0_3.md | 2 + docs/CHECKS_v0_3_0_AMENDMENT.md | 246 ++++++++++++++++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 docs/CHECKS_v0_3_0_AMENDMENT.md diff --git a/docs/CHECKS_PLAN_v0_3.md b/docs/CHECKS_PLAN_v0_3.md index fb71138..27e5680 100644 --- a/docs/CHECKS_PLAN_v0_3.md +++ b/docs/CHECKS_PLAN_v0_3.md @@ -332,6 +332,8 @@ Summary: V is predicted to catch 18 of the 25 v0.1 mutants (M17 unsure), to miss None at the time of the pre-registration commit. None after it either: the mutants, patches, predictions, detection rule and runner were used as committed in P, and the thresholds as committed in T (the implementation notes in section 4 do not change the registered design). Results: `docs/MUTATION_v0_2.md`. +2026-10-22, after results: the review-driven changes for release v0.3.0 (R1–R4, V6 split) and their re-run are registered separately in `docs/CHECKS_v0_3_0_AMENDMENT.md`; nothing above is changed. + ## Appendix A. Mutant generation: prompt, inputs and complete output ### A.1 Inputs given to the agent diff --git a/docs/CHECKS_v0_3_0_AMENDMENT.md b/docs/CHECKS_v0_3_0_AMENDMENT.md new file mode 100644 index 0000000..b19ff2d --- /dev/null +++ b/docs/CHECKS_v0_3_0_AMENDMENT.md @@ -0,0 +1,246 @@ +# v0.3.0 release candidate: review-driven changes to the v0.3 checks, and their re-run + +Status: **design and predictions** (commit A on branch `v0_3_0-rc`). Written and pushed before any code of this amendment and before any re-run. Code, tests and the thresholds of the new quantities follow in commit B (section 5 is filled in there, before any mutant is run); the re-run outputs in commit C; the results in commit D (section 10). Release metadata (version 0.3.0) is commit E. + +Starting point: `main` at `281de19` (v0.3, unreleased; the last release is v0.2.1, concept DOI 10.5281/zenodo.23489176). Pre-registration of v0.3: `docs/CHECKS_PLAN_v0_3.md` ("the plan"); its results: `docs/MUTATION_v0_2.md`. + +## 1. Why + +A pre-release review of v0.3 (GPT, 2026-10-22) found no P0 or P1 defect. It reproduced **74 passed, 3 xfailed** in a separate Windows environment, confirmed that the 88 thresholds follow the rule of the plan (section 4), and that the pre-registration order and the reported numbers (14/20, 19/20, 25/25) agree with the record. It raised four P2 items, fixed here before the release, and P3 documentation items (section 8): + +- **R1. Missing, non-finite and skipped values can hide a verdict** (`tests/test_v0_3_checks.py`). + - `_assert_below({'hh_budget': [0.0, NaN]}, ...)` passes: `max` keeps the leading 0.0. With the order reversed it fails. + - `[0.0, None]` passes: None is dropped. + - If one quantity of a test has no value, the whole test is skipped, even when another quantity of the same test is above its threshold. Example: V1 direct with the proportional-income value absent and 10.0 for the countercyclical one gives a skip. + - `_assert_paths` uses the same `max`, and `_paths` collects only the paths the provider returned, so a missing part of a path set is not visible. +- **R2. The optional-field convention of `hank_limits/interface.py` and the code disagree.** + - The T5 path checks read `dB` and `dC` without checking that they exist (`checks.py`, lines 252 and 257). A provider without them gets a `KeyError` under `v0_3` → `errors`, which fails every V test on T5. + - T3: `interface.py` puts `beta` in `ss_detail`; the code reads `out['beta']`. +- **R3. The checks do not compare the shock the provider solved with the shock the caller requested.** A linear provider that applies twice the requested `G`, `r` and `rshock`, and returns paths consistent with that, passes the IKC test and every path check (largest residual 6.07e-16). +- **R4. V1 assumes that T3 is solved on the asset-market target.** An external code solved on the goods-market target, equivalent in exact arithmetic, alarms (C03). + +The V6 pin of F3 is also split in two (section 3.5). + +## 2. Rules + +1. **Scope.** Branch `v0_3_0-rc` from `main` `281de19`. A pull request to `main` is opened and not merged here. No tag and no GitHub Release: the user creates them, and Zenodo then mints the version DOI. +2. **Historical material is not changed:** `docs/CHECKS_PLAN_v0_3.md`, `docs/MUTATION_PLAN_v0_1.md`, `docs/MUTATION_v0_1.md`, `scripts/mutation_v0_1.py`, `scripts/mutation_v0_2.py`, `out/mutation_v0_1.*`, `out/mutation_v0_2.*`. Exceptions: two dated corrections in `docs/MUTATION_v0_2.md` in the form of its existing "Correction, 2026-10-22" paragraph (section 8), and one line in section 10 (Amendments) of the plan that points to this file. +3. **Model side** (`models.py`, `core.py`). No computation is changed. Allowed: new fields in the dicts the providers return, optional arguments whose default is the current behaviour, docstrings. The 276 numbers of the v0.1 check summaries must equal run B0 of `out/mutation_v0_1.json` bit for bit in the re-run baselines. +4. **Thresholds.** The 88 existing thresholds are not changed. The new quantities get thresholds by the rule of the plan, section 4, `roundup_1sig(max(100 × b_max, 10 × τ))`, with b_max from two unmodified runs of the code of commit B. They are committed in B, before any mutant is run, in a table of the plan's form (section 5). +5. **Checker principles, as in v0.3.** `checks.py` does not depend on SSJ. A new check computes its quantity directly from reported primitive quantities and from **the inputs the caller passed**. Documented values are read from `spec.py`. +6. **Order.** A (this file) → B (code, tests, thresholds) → C (re-run outputs) → D (results) → E (release metadata). Each commit is pushed on its own. + +## 3. Design + +### 3.1 R1: a verdict that missing or non-finite values cannot hide + +**Coverage is declared by the check, not inferred from what the provider returned.** In each check function, at each setting, the quantities that are expected there are declared first, with a placeholder `None` that is replaced when the quantity is computed. + +| Model | Settings | Quantities expected at each setting | +|---|---|---| +| T1 | each eps | V2, V3, V4(a) of T1 | +| T2 | each eps | per income type H and S, and the aggregates | +| T3 | each b | per incidence (acyclical, countercyclical); V1 by the reported GE target (section 3.4) | +| T4 | each eps | V2, V3, V4(a), V4(b) Euler | +| T5 | each T | steady-state quantities; path quantities **for every shock label the caller passed** (rate rule only in rule-based experiments, `exog_r` only in fixed-rate experiments) | + +Records in `res['v0_3']` (new keys; the value lists keep their v0.3 form, one entry per setting): + +- `settings`: the setting labels in order (e.g. `eps=0.2`, `b=0.001`, `T=200`); +- `at[q]`: the setting of each value in `res['v0_3'][q]` (paths: `paths[label]['at'][q]`); +- `status[q]`: coverage per quantity: number expected, number reported, the settings with a missing value, those with a non-finite value, and a state `complete`, `incomplete`, `not_reported` or `nonfinite`. Thresholds are applied by the tests, not here. + +**Verdict of one V test** (`checks.v03_verdict(v, quantities, thresholds)`, numpy only; every V test uses it through `_assert_below` and `_assert_paths`): + +1. **failed** if a v0.3 computation raised an exception (as in v0.3), or if any recorded value of any of the test's quantities is non-finite (NaN, ±inf), negative, or not below its threshold. This holds whatever else is missing. Every V quantity is an absolute value or a maximum of absolute values, so a negative number can only be a malformed report (V1(a) is a value the provider reports); +2. otherwise **skipped** ("not reported", with the reasons recorded under `skipped`) if none of the test's quantities has a value at any setting: the provider does not support the check, as in v0.3; +3. otherwise **incomplete** if any expected value is missing: pytest skip with a message that starts with "incomplete" and lists the missing settings. It is never a pass; +4. otherwise **passed**. + +A quantity that the check declared at no setting does not apply and is ignored, e.g. the goods-market V1 quantities when every T3 solve is on the asset market. For a hand-made `v0_3` dict without coverage records (as in the regression tests), every listed quantity is expected and each list entry is one setting. + +**Regression tests** use the real helpers `_assert_below` and `_assert_paths` of `tests/test_v0_3_checks.py` and `checks.v03_verdict`: + +- `{'hh_budget': [0.0, NaN]}` → failed (also with the order reversed); `[0.0, inf]` → failed; +- `{'hh_budget': [0.0, None]}` → incomplete; +- V1 direct with the proportional-income quantity absent and `[10.0]` for the countercyclical one → failed; +- T5 paths: `[0.0, NaN]` → failed; a declared path value that is missing, and a shock label the provider did not return (through `check_ikc` and a fake provider) → incomplete. + +They are in a new file `tests/test_v0_3_0_checker.py`. It uses no model code, so no mutant can change it; the mutation runner maps it to no group. + +### 3.2 R2: one field convention, in the documentation and in the code + +- **T5 paths: fields per equation.** Fiscal rule (dB, dTax); government budget (dB, dTax, dr, dG); goods market (dY, dC, dG); rate rule (dr, dY, and the caller's rshock, section 3.3). A missing field skips only that equation, recorded under `skipped` with the path label and the missing field. It is no longer an error that fails every V test. +- **Steady-state quantities: fields per equation as well.** A missing income vector y no longer skips the market-clearing residuals that do not use it, and so on. +- **T3 `beta`** is read from `ss_detail['beta']`, as documented. The SSJ provider already reports it there; the top-level `beta` it also returns stays, so existing callers do not break. +- **`interface.py` lists every field that the checks read**, v0.1 part and V part, as required or optional, per provider, with the V quantities each optional field feeds. The code reads no other field (enforced by the fake providers below). +- **Two fake providers per check** in the regression tests: + - one that returns exactly the documented required and optional fields: every V test reaches a verdict (passed or failed) and no error is recorded; + - one that returns only the required fields: no error is recorded. Every V test that needs an optional field is skipped or incomplete, and `skipped` lists the reasons. The checks that need only required fields and the caller's inputs (the T5 rate rule, `exog_G`, `exog_r`; section 3.3) reach a verdict. + +### 3.3 R3: the solved shock against the requested shock + +- **New path quantities** in `_v03_fiscal`, normalised by s (the largest absolute requested input) like the other path checks: + - `exog_G` = max_t |dG_t − G_t| / s, with G the path the caller requested, or zero when the experiment has no G shock; + - `exog_r` = max_t |dr_t − r_t| / s in the fixed-rate experiments (requested r, or zero). In rule-based experiments dr is endogenous and the rate rule checks it; + - `exog_rshock` = max_t |drshock_t − rshock_t| / s (requested rshock, or zero; `drshock` stays an optional field). +- **The rate-rule residual uses the requested rshock**, not the reported drshock: max_t |dr_t − φ_y dY_t − rshock_t| / s. +- **The fiscal rule, the government budget and the goods market keep using the reported dG and dr.** The exog quantities compare those with the request. So a wrong exogenous path is attributed to `exog_*`, and a violated equation to that equation; together they are equivalent to evaluating the equations at the requested paths. +- **Tests** (group V): `test_v4_exogenous_G_as_requested`, `test_v4_exogenous_r_as_requested`, `test_v4_exogenous_rshock_as_requested`. +- **Regression test:** a small linear fake fiscal provider that applies twice the requested G, r and rshock, and returns paths consistent with that. It passes the IKC check (v0.1 part) and the fiscal-rule, budget and goods-market path checks, and fails the three exog tests and the rate rule. +- **Threshold** by the rule of section 2. The SSJ provider takes the exogenous paths from the inputs (`get` in `ssj_fiscal_provider`), so b_max is expected to be exactly 0, and τ = 1e-14 ("exact up to rounding", plan section 4) gives 1e-13. + +### 3.4 R4: the GE target of T3 in the provider convention + +**Provider.** + +- `WerningProvider` reports `ge_target` ∈ {`'asset_mkt'`, `'goods_mkt'`}: the market whose clearing the solve imposed. + - Absent: `'asset_mkt'` is assumed and recorded as assumed (backward compatible). + - Any other value: V1 is skipped at that setting as "applicability condition not met". The placeholder stays missing, so a mix with settings whose target is known is incomplete, not passed. +- New optional field `J_C` = {'Y': J^{C,Y}, 'r': J^{C,r}} (T × T) for the goods-market residual. `J_A` stays as it is. +- SSJ reference provider: optional argument `ge_target='asset_mkt'` (the default is the current behaviour). `targets = [ge_target]` is passed to the solve, and **the same variable** gives the reported `ge_target` and `diag['ge_target_resid']`, the residual of the solved target. A change of the solve's target, like C03, therefore shows in what is reported. + +**Checker.** V1 computes the residual of the reported target directly and divides it by b. dr is the rate path the check passed, as before. + +| Quantity | Target | Definition | Threshold | +|---|---|---|---| +| `ge_target_resid_direct_{acyc,cyc}` | asset market | max \|J_A['Y'] dY + J_A['r'] dr\| / b | 2e-12 (unchanged) | +| `ge_target_resid_direct_goods_{acyc,cyc}` | goods market | max \|dY − J_C['Y'] dY − J_C['r'] dr\| / b | new (section 5) | +| `ge_target_resid_reported_{acyc,cyc}` | asset market | V1(a): `diag['ge_target_resid']` / b, must be finite and non-negative | 2e-12 (unchanged) | +| `ge_target_resid_reported_goods_{acyc,cyc}` | goods market | V1(a) as above | new (section 5) | + +- **The other market's residual** is recorded without a threshold, where its Jacobians are reported: `v0_3['diagnostics']`, `goods_mkt_resid_direct_*` for an asset-market solve, `asset_mkt_resid_direct_*` for a goods-market solve. The target of each setting is recorded in `v0_3['ge_target']`. +- **Thresholds of the goods-market quantities:** two unmodified runs of the reference provider with `ge_target='goods_mkt'`, both incidences and all seven b, by the rule of section 2, τ = 1e-14 (linear solve). +- **Documentation:** `interface.py` and the V1 rows of both READMEs: the target convention, and that V1 applies to a T3 solve on one of the two markets. + +### 3.5 V6 split + +`test_v6_f3_hetinput_hetoutput_two_sided` becomes two strict xfails, each with SSJ code only: + +- `test_v6a_f3_hetinput_two_sided`: the hetinput derivative that `HetBlock` uses equals the central difference (fails: always one-sided); +- `test_v6b_f3_hetoutput_two_sided`: the hetoutput Jacobian with `twosided=True` equals the one obtained when the stored default is honoured (fails: one-sided even when two-sided differences are requested). + +If only one part is fixed upstream, only that test turns XPASS. + +### 3.6 Model side, in full, and patch anchors + +Only `ssj_werning_provider` changes: + +- signature (`ge_target='asset_mkt'`); +- a new line `targets = [ge_target]`, and the solve line passes `targets`; +- new return fields `ge_target` and `J_C`; +- `diag['ge_target_resid']` reads `irf[targets[0]]`; +- the docstring: it said "(goods market)" while the target is the asset market (P3). + +No other line of `models.py` or `core.py` changes. + +Patch anchors (checked against the plan's patch lists): + +- **M04 and C03** (v0.1) anchor on the T3 solve line, which now passes `targets`. They are re-anchored, the same change at the new location: + - M04: the same one-period shift of the rate path, on the new solve line; + - C03: `targets = [ge_target]` → `targets = ['goods_mkt']`. The target the solve imposes changes, as in the original patch; by design (R4) the reported target follows it. +- **M12** anchors on the `options=` line, which does not change. +- **No v0.2 patch** anchors on a changed line. + +`scripts/mutation_v0_2.py` has an empty `REANCHOR` and is not changed (rule 2). The re-run therefore uses a copy, `scripts/mutation_v0_3_0.py`, with only these changes: the two `REANCHOR` entries, its own module name as the pytest plugin and in the environment record, the default output path, and the docstring. + +## 4. New quantities and tests + +| Test (group V) | Quantity | Model | Fields used | +|---|---|---|---| +| `test_v1_werning_ge_target_resid_reported` | `ge_target_resid_reported_goods_{acyc,cyc}` (new), besides the asset-market ones | T3 | `ge_target`, `diag['ge_target_resid']` | +| `test_v1_werning_ge_target_resid_direct` | `ge_target_resid_direct_goods_{acyc,cyc}` (new), besides the asset-market ones | T3 | `ge_target`, dY, *`J_C`* (new, optional); dr from the caller | +| `test_v4_exogenous_G_as_requested` | `exog_G` | T5 paths | irfs dG; G from the caller | +| `test_v4_exogenous_r_as_requested` | `exog_r` (fixed-rate experiments) | T5 paths | irfs dr; r from the caller | +| `test_v4_exogenous_rshock_as_requested` | `exog_rshock` | T5 paths | irfs drshock; rshock from the caller | +| `test_v6a_f3_hetinput_two_sided` | as V6 (i) | – | SSJ only | +| `test_v6b_f3_hetoutput_two_sided` | as V6 (ii) | – | SSJ only | + +- **Changed meaning:** `rate_rule` uses the requested rshock (section 3.3). +- **Diagnostics without threshold:** `goods_mkt_resid_direct_*`, `asset_mkt_resid_direct_*` (section 3.4). +- **Group V** after B has 37 tests: 33, minus the V6 test, plus V6a, V6b and the three exog tests. Every other test name is unchanged. +- **The checker regression tests** are in `tests/test_v0_3_0_checker.py`, outside group V. + +## 5. Thresholds of the new quantities + +Rule and τ classes: plan, section 4. The table is filled in by commit B from two unmodified runs of the B candidate: the full suite for the T5 quantities, and `suite.run_t3(ge_target='goods_mkt')` for the goods-market quantities. + +*(filled in by commit B)* + +## 6. Re-run design + +- **Suite.** The v0.3.0 candidate is the tree of commit B (`hank_limits/`, `tests/`, `pytest.ini`, extracted with `git archive` as before). +- **Designs.** + - (ii) the 20 v0.2 mutants and 3 controls × the candidate (23 runs); + - (iii) the 28 v0.1 mutants and controls × the candidate (28 runs); + - two unmutated baselines (B0, B1): 53 runs in all. + - Design (i), the v0.2.1 suite, does not change and is not re-run; comparisons with it use its v0.2 results. +- **Runner.** `python3 scripts/mutation_v0_3_0.py --v03-ref --design ii iii --out out/mutation_v0_3_0_rerun` (the copy of section 3.6). Detection rule, time limits, parallelism (4 runs, one BLAS thread each) and summaries are those of v0.2. The patches are those of the plan and of v0.1, re-anchored only as in section 3.6, and recorded in the output. +- **Outputs.** `out/mutation_v0_3_0_rerun.{json,csv}`. +- **Comparison with v0.2,** per run and group: verdicts, the tests that changed outcome, and the values of the v0.3 quantities. +- **The original results stay as the record of the checks as they were** (19/20, 25/25, the C03 alarm). This is a re-run of the suite as revised after review. + +## 7. Predictions + +**Basis.** The code changes above. For R1, a scan of `out/mutation_v0_2.json` made while writing this section: in the 53 runs of the v0.3 suite (both baselines, designs (ii) and (iii)), no v0.3 quantity is None, NaN or ±inf, no v0.3 computation recorded an error or a skip reason, and no V test was skipped. The one fixture error is t3 under N19 (root bracket, ValueError). For R3: the SSJ provider returns the requested exogenous paths because it takes them from the inputs, and no v0.1 or v0.2 patch touches `ssj_fiscal_provider` or the inputs. For the same reason the reported `drshock` equals the requested rshock in every run. + +**P1. Baselines.** +- All tests pass except four strict xfails (F1, F2, V6a, V6b). +- B0 and B1 are identical in every outcome and every summarised number. +- All 276 numbers of the v0.1 summaries equal v0.1 run B0. Against v0.1 run B1 only the known two-valued number differs (plan, section 8). + +**P2. Groups T1–T6 and D.** In all 51 runs, the same verdict and the same changed tests as in the v0.2 runs. + +**P3. Existing V tests.** Every test of v0.2's group V except the V6 test has the same outcome as in v0.2, in every run, **except C03** (P6). + +**P4. Values.** Every v0.3 quantity that exists in the v0.2 data equals its v0.2 value in the same run, except: +- C03's V1 quantities, now goods-market ones; +- possibly rounding-level differences in the two T5 settings that no V test uses (as seen between threshold runs in the plan, section 4). + +**P5. New tests.** +- `exog_G`, `exog_r` and `exog_rshock` are exactly 0 in every run, and the three exog tests pass in every run: they catch nothing. +- V6a and V6b xfail in every run. + +**P6. C03** (GE target goods market). +- The provider reports `goods_mkt`, and V1 is judged on the goods-market residual. Its values equal those of the goods-market threshold runs, so V1 passes, and C03 no longer alarms. +- **This is not independent evidence.** Its thresholds come from unmodified runs with the same setting as C03. +- The asset-market residual is now a diagnostic without threshold, and equals the values that alarmed in v0.2. Divided by b, the maximum over the seven b is 2.96e-6 with proportional income and 2.44e-3 with countercyclical income. + +**P7. Suite level.** +- (ii): 19 of 20 mutants caught, N20 missed, no alarm on K01–K03. +- (iii): 25 of 25 caught, no alarm on C01–C03. +- Against the original pre-registered predictions: (ii) unchanged (167 of 168 firm cells held). (iii): the C03/V cell now differs from the pre-registered "catch (false alarm)", by design of R4. + +**P8. Checker self-tests** (`tests/test_v0_3_0_checker.py`) pass in every run. + +**Cells expected to differ from v0.2** (cells as in `docs/MUTATION_v0_2.md`, sections 3 and 9): + +| Design | ID | Group | v0.2 | Predicted in the re-run | Why | +|---|---|---|---|---|---| +| (iii) | C03 | V | **2/33** (alarm: V1 reported and direct) | · (no alarm) | R4: judged on the reported goods-market target, with thresholds from the same setting | +| (ii), (iii) | every run | V | n/33 | the same n, out of 37 | V6 split, three exog tests; none expected to change outcome | + +No other cell is expected to change. R1 to R3 change how missing, non-finite and wrongly sized exogenous values are judged. No run of the v0.2 data produced such values, so their evidence is the regression tests with fake providers (sections 3.1–3.3), not this re-run. + +## 8. Documentation (P3) + +| Item | Where | Commit | +|---|---|---| +| `docs/MUTATION_v0_2.md` line 17: "Every V catch … factor of 1e4 or more" is wrong. N18's largest margin is about 7,577 (asset market) and 9,742 (goods market). By failing test, N12's TANK goods-market test is about 526. Recompute from the data, separating the largest margin per mutant from the smallest margin per failing test. Dated correction; no effect on 19/20 | `docs/MUTATION_v0_2.md` | D | +| Same file, line 242: "any goods-market solve" → what was observed with this reference provider, calibration and solver setting. Dated correction | `docs/MUTATION_v0_2.md` | D | +| `models.py` (~line 310): the `ssj_werning_provider` docstring says "(goods market)"; the target is `asset_mkt` | `models.py` | B | +| V1 rows: target convention and scope (R4) | both READMEs | B | +| V3 rows: aggregate income = Y, with the reference per model: T2 income per type and the weighted sum, T4 w L, T5 Y − Tax | both READMEs | E | +| "bit-identical": limited to "in the report's baseline runs, the 276 existing summary numbers were exactly equal" | both READMEs | E | +| "41 passed, 2 xfailed" (README.md ~line 69, README_ko.md ~line 68) and section 11: marked as the v0.2.1 result, with a link to the current result | both READMEs | E | + +## 9. What can and cannot be claimed + +- The re-run shows whether the revision changed detection on the same two samples (20 + 3 v0.2 runs, 28 v0.1 runs). It is not new independent evidence beyond v0.2. +- If C03 no longer alarms, that holds by construction (section 3.4); it shows only that the target convention works as built. +- R1–R3 address failure modes (missing, non-finite and wrongly sized exogenous values) that neither the reference provider nor the mutants produced. Their evidence is the regression tests with fake providers. +- The thresholds of the new quantities are regression thresholds for this calibration, like the others. + +## 10. Results + +*(commit D)* From a290c753d090831ade3ee9507ec98517493d3b5a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 14:44:58 +0000 Subject: [PATCH 2/7] v0.3.0: R1-R4 and V6 split in code, tests and thresholds (commit B) - R1: coverage declared by the check (placeholders per setting, income type and requested shock; res['v0_3']['at'], ['status']), and checks.v03_verdict: a non-finite, negative or too large value fails whatever else is missing; a missing value without failure is "incomplete" (pytest skip), never a pass. - R2: each V quantity computed from the fields of its own equation (T5 paths no longer raise KeyError without dB/dC); T3 beta read from ss_detail; interface.py lists every field the checks read. - R3: exog_G, exog_r, exog_rshock compare the solved exogenous paths with the caller's request; the rate rule uses the requested rshock. - R4: the Werning provider reports ge_target (optional argument, default asset_mkt, the same variable as the solve) and J_C; V1 judges the residual of the reported target, the other market is a diagnostic. - V6 split into V6a (hetinput) and V6b (hetoutput), strict xfail. - New thresholds by the plan's rule from two unmodified runs of the candidate (out/thresholds_v0_3_0_run{1,2}.json); the 88 existing ones are unchanged. Checker regression tests with fake providers in tests/test_v0_3_0_checker.py. Re-run runner scripts/mutation_v0_3_0.py (copy of the v0.2 runner with M04 and C03 re-anchored). - models.py: only ssj_werning_provider (new fields, optional argument, docstring); no computation changed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaLSoFg2N1x4mzFYiwrgVT --- README.md | 2 +- README_ko.md | 2 +- docs/CHECKS_v0_3_0_AMENDMENT.md | 30 +- hank_limits/checks.py | 566 ++++++++++---- hank_limits/interface.py | 111 ++- hank_limits/models.py | 13 +- out/thresholds_v0_3_0_run1.json | 237 ++++++ out/thresholds_v0_3_0_run2.json | 239 ++++++ scripts/mutation_v0_3_0.py | 1258 +++++++++++++++++++++++++++++++ scripts/thresholds_v0_3_0.py | 125 +++ tests/test_v0_3_0_checker.py | 368 +++++++++ tests/test_v0_3_checks.py | 259 ++++--- 12 files changed, 2944 insertions(+), 266 deletions(-) create mode 100644 out/thresholds_v0_3_0_run1.json create mode 100644 out/thresholds_v0_3_0_run2.json create mode 100644 scripts/mutation_v0_3_0.py create mode 100644 scripts/thresholds_v0_3_0.py create mode 100644 tests/test_v0_3_0_checker.py diff --git a/README.md b/README.md index f7bd7e0..d26742c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Not released: the version in `pyproject.toml`, the tags and the citation metadat | Item | v0.3 change | |---|---| -| V1 | T3 records and tests the GE target (asset-market) residual, both as reported by the solver and computed directly from the reported Jacobians. V1 assumes that T3 is solved on the asset-market target: its threshold (2e-12, on the residual divided by b) comes from the asset-market solve's own residual. A solve on the goods-market target, equivalent in exact arithmetic, leaves an asset-market residual far above it: up to 3.0e-6·b with proportional income, where F3 plays no role, and up to 2.4e-3·b with countercyclical income, where F3 adds an O(h) error. V1 therefore alarms on such a solve (control C03; `docs/MUTATION_v0_2.md`, section 8). | +| V1 | T3 records and tests the residual of the GE target that the provider reports in `ge_target` (`'asset_mkt'` or `'goods_mkt'`; if absent, `'asset_mkt'` is assumed and recorded as assumed), divided by b: as reported by the solver, and computed directly from the reported Jacobians and the rate path the check passed (asset market J^{A,Y} dY + J^{A,r} dr from `J_A`; goods market dY − J^{C,Y} dY − J^{C,r} dr from `J_C`). Thresholds: 2e-12 for the asset market, from the asset-market solve's own residual (unchanged); 9e-12 (proportional income) and 2e-11 (countercyclical income) for the goods market, from the reference provider solved on the goods market (v0.3.0). The other market's residual is recorded without a threshold. Scope: V1 applies to a T3 solve on one of these two markets; for any other reported target it is skipped as not applicable. Until v0.3.0, V1 assumed the asset-market target and alarmed on an equivalent goods-market solve (control C03): its asset-market residual is up to 3.0e-6·b with proportional income, where F3 plays no role, and up to 2.4e-3·b with countercyclical income, where F3 adds an O(h) error (`docs/MUTATION_v0_2.md`, section 8; `docs/CHECKS_v0_3_0_AMENDMENT.md`). | | V2 | Steady-state residuals computed in the checks from reported primitive quantities: government budget, goods and asset markets (fiscal HANK, TANK, Huggett), capital market, firm first-order conditions and goods market (Aiyagari), and the aggregate household budget in every model. | | V3 | Income normalisation: Π row-stochastic, E[e] = 1 under the stationary distribution of the reported Π, aggregate income = Y (Y − Tax in the fiscal model), and Σ π e ζ = 0 for the countercyclical incidence. | | V4 | Specification pins against the documented values in `hank_limits/spec.py` (not read from `models.py`): reported parameters, the Aiyagari Euler equation at the documented β and EIS, and the fiscal rule, government budget, real-rate rule and goods market along the T5 paths. | diff --git a/README_ko.md b/README_ko.md index 8f82c29..0b0a3ba 100644 --- a/README_ko.md +++ b/README_ko.md @@ -33,7 +33,7 @@ | 항목 | v0.3 변경 | |---|---| -| V1 | T3 의 일반균형 목표(자산시장) 잔차를 기록하고 시험합니다. 풀이기가 보고한 값과, 보고된 야코비안으로 직접 계산한 값을 모두 봅니다. V1 은 T3 를 자산시장 목표로 푼다고 전제합니다. 임계값(잔차를 b 로 나눈 값에 대해 2e-12)은 자산시장 풀이 자신의 잔차에서 나왔습니다. 정확한 산술에서는 같은 해를 주는 재화시장 목표로 풀면, 자산시장 잔차가 이보다 훨씬 큽니다. 비례 소득에서는 F3 와 무관하게 최대 3.0e-6·b, 경기역행 소득에서는 F3 의 O(h) 오차가 더해져 최대 2.4e-3·b 입니다. 따라서 V1 은 그런 풀이에 경보를 냅니다(대조군 C03; `docs/MUTATION_v0_2.md` 8절). | +| V1 | 공급자가 `ge_target` 으로 보고한 T3 일반균형 목표(`'asset_mkt'` 또는 `'goods_mkt'`; 없으면 `'asset_mkt'` 로 보고 "assumed" 로 기록)의 잔차를 b 로 나눠 기록하고 시험합니다. 풀이기가 보고한 값과, 보고된 야코비안과 검사가 넘긴 금리 경로로 직접 계산한 값을 모두 봅니다(자산시장은 `J_A` 로 J^{A,Y} dY + J^{A,r} dr, 재화시장은 `J_C` 로 dY − J^{C,Y} dY − J^{C,r} dr). 임계값: 자산시장은 자산시장 풀이 자신의 잔차에서 나온 2e-12(그대로), 재화시장은 참조 공급자를 재화시장 목표로 푼 실행에서 나온 9e-12(비례 소득)와 2e-11(경기역행 소득)입니다(v0.3.0). 다른 시장의 잔차는 임계값 없이 기록만 합니다. 적용 범위: 두 시장 가운데 하나로 푼 T3 에만 적용하고, 다른 목표가 보고되면 적용 조건 미충족으로 skip 합니다. v0.3.0 전에는 V1 이 자산시장 목표를 전제했으므로, 정확한 산술에서는 같은 해를 주는 재화시장 풀이(대조군 C03)에 경보를 냈습니다. 그 풀이의 자산시장 잔차는 비례 소득에서 F3 와 무관하게 최대 3.0e-6·b, 경기역행 소득에서 F3 의 O(h) 오차가 더해져 최대 2.4e-3·b 입니다(`docs/MUTATION_v0_2.md` 8절, `docs/CHECKS_v0_3_0_AMENDMENT.md`). | | V2 | 공급자(provider)가 보고한 기본 수량으로 검사 쪽에서 직접 계산하는 정상상태 잔차: 정부 예산, 재화·자산시장(재정 HANK, TANK, Huggett), 자본시장·기업 1계 조건·재화시장(Aiyagari), 모든 모형의 집계 가계 예산. | | V3 | 소득 정규화: Π 의 행 합이 1, 보고된 Π 의 정상분포에서 E[e] = 1, 총소득 = Y(재정 모형은 Y − Tax), 경기역행 귀착에서 Σ π e ζ = 0. | | V4 | `hank_limits/spec.py` 의 문서화된 값으로 명세 고정(specification pins). `models.py` 에서 읽지 않습니다. 보고된 모수, 문서화된 β·EIS 에서의 Aiyagari 오일러 식, T5 경로에서의 재정 준칙·정부 예산·실질금리 준칙·재화시장을 확인합니다. | diff --git a/docs/CHECKS_v0_3_0_AMENDMENT.md b/docs/CHECKS_v0_3_0_AMENDMENT.md index b19ff2d..5f1b0a9 100644 --- a/docs/CHECKS_v0_3_0_AMENDMENT.md +++ b/docs/CHECKS_v0_3_0_AMENDMENT.md @@ -165,7 +165,35 @@ Patch anchors (checked against the plan's patch lists): Rule and τ classes: plan, section 4. The table is filled in by commit B from two unmodified runs of the B candidate: the full suite for the T5 quantities, and `suite.run_t3(ge_target='goods_mkt')` for the goods-market quantities. -*(filled in by commit B)* +**Filled in by commit B.** b_max from two runs of `scripts/thresholds_v0_3_0.py` on the B candidate (2026-10-22, 14:46 and 14:47 UTC). The candidate is a local commit, `e9fd7e1`, with the same `hank_limits/`, `tests/` and `pytest.ini` trees as B; B adds this table and the two run files `out/thresholds_v0_3_0_run{1,2}.json`. The script calls the check functions exactly as the pytest fixtures do. Environment as in v0.2: Python 3.13.16, sequence-jacobian 1.0.0, numpy 2.5.3 (scipy-openblas 0.3.34), scipy 1.18.1, numba 0.68.0. The two runs gave identical numbers. Path quantities are the largest over the four shocks and three horizons; T3 quantities the largest over the seven b. + +| Model | Quantity | b_max (run 1, run 2) | τ (source) | Threshold | +|---|---|---|---|---| +| T3, goods-market target | `ge_target_resid_reported_goods_acyc` | 8.67e-14, 8.67e-14 | 1e-14 (exact up to rounding (linear solve)) | 9e-12 | +| T3, goods-market target | `ge_target_resid_reported_goods_cyc` | 1.39e-13, 1.39e-13 | 1e-14 (exact up to rounding (linear solve)) | 2e-11 | +| T3, goods-market target | `ge_target_resid_direct_goods_acyc` | 8.75e-14, 8.75e-14 | 1e-14 (exact up to rounding (linear solve)) | 9e-12 | +| T3, goods-market target | `ge_target_resid_direct_goods_cyc` | 1.27e-13, 1.27e-13 | 1e-14 (exact up to rounding (linear solve)) | 2e-11 | +| T5 | `exog_G` (path, max over labels) | 0, 0 | 1e-14 (exact up to rounding) | 1e-13 | +| T5 | `exog_r` (path, fixed-rate labels) | 0, 0 | 1e-14 (exact up to rounding) | 1e-13 | +| T5 | `exog_rshock` (path, max over labels) | 0, 0 | 1e-14 (exact up to rounding) | 1e-13 | + +**Notes on the table** + +- **The goods-market quantities are about ten times the asset-market ones** (b_max 1.1e-14 to 1.5e-14 there). Both are rounding-level residuals of a linear solve. Both are largest at b = 1e-4, where the division by b is largest. Before the division, the goods-market residual is about 1e-17 and the asset-market one about 1e-18. +- **Residuals of the other market,** recorded without threshold. Divided by b and maximised over the seven b: + - the asset-market solve of the reference provider leaves a goods-market residual of 1.36e-7 (proportional income) and 2.52e-6 (countercyclical income); + - the goods-market solve leaves an asset-market residual of 2.96e-6 and 2.44e-3. These equal, bit for bit, the V1 values with which C03 alarmed in v0.2. +- **The 88 existing quantities** have, in these runs, the b_max of the plan's table to three significant digits, except the T5 path `goods_market`: 3.11e-13 here, 3.12e-13 in the plan. This is the run-to-run rounding variation described below. Their thresholds are unchanged. + +**Observations at B, before any mutant was run** + +- **Full pytest on the candidate:** 107 passed, 4 xfailed. That is 77 tests in the suite's groups and the 30 checker tests of `tests/test_v0_3_0_checker.py`; the xfails are F1, F2, V6a and V6b. +- **The 276 v0.1 numbers.** Two baseline runs of the re-run runner (`scripts/mutation_v0_3_0.py --baseline-only v0.3`; output not kept) gave, in both runs, all 276 v0.1 summary numbers equal to v0.1 run B0. Against v0.1 run B1 only the known two-valued number differs. Test outcomes were identical. +- **Rounding-level differences between B0 and B1.** The two baselines differed in five T5 goods-market path residuals (dY − dC − dG; values between 1e-15 and 4e-6): + - one is in the refined setting that the V tests use: `G_debt_r_rule` at T = 300, 3.11556e-13 in one run and 3.11383e-13 in the other, against a threshold of 4e-11; + - the other four are in the two settings that no V test uses; two of them are the quantities that the plan (section 4) already saw vary between runs. + - The refined-setting quantity also took the value 3.11383e-13 in the threshold runs, and 3.11556e-13 (the v0.2 value) in a pytest run in the repository. This is the run-to-run rounding variation of dC that the plan describes. No number of the v0.1 summaries and no test outcome is affected. +- **Effect on the predictions.** Prediction P1 ("B0 and B1 identical in every summarised number") and prediction P4 ("equal to the v0.2 value", where the refined setting is not exempted) are therefore expected to fail at rounding level for these quantities. The predictions stay as registered, and the outcome is reported in section 10. ## 6. Re-run design diff --git a/hank_limits/checks.py b/hank_limits/checks.py index 4e472b3..759b504 100644 --- a/hank_limits/checks.py +++ b/hank_limits/checks.py @@ -20,12 +20,21 @@ def _tolist(x): # --------------------------------------------------------------------------- -# v0.3 checks (docs/CHECKS_PLAN_v0_3.md): steady-state residuals (V2), income normalisation -# (V3) and specification pins (V4), computed here from primitive quantities the provider -# reports in the optional fields `ss_detail`, `J_A`, `policy` and the paths. They are stored -# under res['v0_3'] (one list entry per setting of the check), so the v0.1 part of every -# result is unchanged. A missing field skips the quantities that need it; the reason is -# recorded in res['v0_3']['skipped']. +# v0.3 checks (docs/CHECKS_PLAN_v0_3.md; revised for v0.3.0, docs/CHECKS_v0_3_0_AMENDMENT.md): +# GE target residual of T3 (V1), steady-state residuals (V2), income normalisation (V3) and +# specification pins (V4), computed here from primitive quantities the provider reports in the +# optional fields (`hank_limits.interface`) and from the inputs the caller passed. They are +# stored under res['v0_3'] (one list entry per setting of the check), so the v0.1 part of every +# result is unchanged. +# +# v0.3.0: coverage is declared by the check, not inferred from what the provider returned. At +# each setting the expected quantities get a placeholder None, replaced when the quantity is +# computed; res['v0_3']['at'][q] holds the setting of each value of q and +# res['v0_3']['status'][q] the coverage of q. Each quantity is computed from the fields its own +# equation needs; if one is missing, the placeholder stays and the reason is recorded in +# res['v0_3']['skipped']. `v03_verdict` turns the values into the verdict of a test: a +# non-finite, negative or too large value fails whatever else is missing, and a missing value +# without failure is "incomplete", never a pass. # --------------------------------------------------------------------------- def stationary_marginal(Pi): @@ -39,15 +48,30 @@ def stationary_marginal(Pi): return np.linalg.solve(A, b) +def _pi_row_sum_err(Pi): + return float(np.max(np.abs(Pi.sum(1) - 1))) + + +def _pi_negative(Pi): + return float(max(0.0, -Pi.min())) + + +def _mean_e_err(pi, e): + return float(abs(pi @ np.asarray(e, float) - 1)) + + +def _agg_income_err(pi, y, Y_ref): + return float(abs(pi @ np.asarray(y, float) - Y_ref) / abs(Y_ref)) + + def income_report(e, Pi, y=None, Y_ref=None): """V3: Pi row-stochastic, E_pi[e] = 1 and, if y is given, sum_e pi_e y_e = Y_ref.""" Pi = np.asarray(Pi, float) pi = stationary_marginal(Pi) - out = dict(pi_row_sum_err=float(np.max(np.abs(Pi.sum(1) - 1))), - pi_negative=float(max(0.0, -Pi.min())), - mean_e_err=float(abs(pi @ np.asarray(e, float) - 1))) + out = dict(pi_row_sum_err=_pi_row_sum_err(Pi), pi_negative=_pi_negative(Pi), + mean_e_err=_mean_e_err(pi, e)) if y is not None and Y_ref is not None: - out['agg_income_err'] = float(abs(pi @ np.asarray(y, float) - Y_ref) / abs(Y_ref)) + out['agg_income_err'] = _agg_income_err(pi, y, Y_ref) return out, pi @@ -83,8 +107,30 @@ def euler_errors(Pi, a_grid, a_pol, c_pol, D, r, beta, eis, bind_tol=1e-10, mass if np.any(binding & has_mass) else 0.0) +# --- records: settings, placeholders, values, skips ------------------------------------------ + def _new_v03(): - return dict(skipped=[]) + return dict(skipped=[], settings=[], at={}) + + +def _expect(v, keys, where): + """Declare that each quantity in `keys` is expected at setting `where` (placeholder None).""" + at = v.setdefault('at', {}) + for k in keys: + v.setdefault(k, []).append(None) + at.setdefault(k, []).append(where) + + +def _put(v, key, value, where): + """Record a value at setting `where`: it replaces the placeholder of a quantity declared + there, and is appended with its setting otherwise.""" + x = None if value is None else float(value) + vals, at = v.setdefault(key, []), v.setdefault('at', {}).setdefault(key, []) + if at and at[-1] == where and vals[-1] is None: + vals[-1] = x + else: + vals.append(x) + at.append(where) def _guard(v, fn, *args): @@ -96,171 +142,392 @@ def _guard(v, fn, *args): v.setdefault('errors', []).append(f'{fn.__name__}: {type(exc).__name__}: {exc}'[:300]) -def _put(v, key, value): - v.setdefault(key, []).append(None if value is None else float(value)) - - def _skip(v, what, missing): msg = f"{what}: provider does not report {', '.join(missing)}" if msg not in v['skipped']: v['skipped'].append(msg) -def _need(d, keys): - return [k for k in keys if d is None or k not in d] +class _Fields: + """The fields of one provider result that the V checks read: `f[name]` is the value, + `f.missing(names)` names the fields not reported (e.g. "ss_detail['y']"). `top` are + top-level fields; keyword arguments name a nested field and its keys + (`ss_detail=('Y', 'C')`, `policy=('a', 'c')`).""" + + def __init__(self, out, top=(), **nested): + self.val, self.lab = {}, {} + for k in top: + self.lab[k] = k + if k in out: + self.val[k] = out[k] + for field, keys in nested.items(): + d = out.get(field) + for k in keys: + self.lab[k] = f"{field}['{k}']" if isinstance(d, dict) else field + if isinstance(d, dict) and k in d: + self.val[k] = d[k] + + def __getitem__(self, k): + return self.val[k] + + def missing(self, names): + return list(dict.fromkeys(self.lab[n] for n in names if n not in self.val)) + + +def _eq(v, key, where, tag, f, names, fn): + """Compute one quantity if the provider reports every field its equation needs (R2: fields + per equation); otherwise keep the placeholder and record the missing fields.""" + miss = f.missing(names) + if miss: + return _skip(v, f'{key} ({tag})', miss) + _put(v, key, fn(), where) -def _pin(v, key, value, ref, rel=False): - _put(v, key, abs(value - ref) / (abs(ref) if rel else 1.0)) +def _dev(x, ref, rel=False): + return abs(x - ref) / (abs(ref) if rel else 1.0) -def _income(v, suffix, e, Pi, y, Y_ref): - inc, pi = income_report(e, Pi, y, Y_ref) - for k, x in inc.items(): - _put(v, k + suffix, x) +def _pin(v, key, where, tag, f, name, ref, rel=False): + _eq(v, key, where, tag, f, [name], lambda: _dev(f[name], ref, rel)) + + +def _income(v, sfx, where, tag, f, e, Pi, y, ref_names, ref): + """V3 for one income chain (field names e, Pi, y in f; the aggregate-income reference ref() + needs the fields ref_names). Returns the stationary distribution of Pi, or None.""" + pi = None if f.missing([Pi]) else stationary_marginal(f[Pi]) + _eq(v, 'pi_row_sum_err' + sfx, where, tag, f, [Pi], + lambda: _pi_row_sum_err(np.asarray(f[Pi], float))) + _eq(v, 'pi_negative' + sfx, where, tag, f, [Pi], lambda: _pi_negative(np.asarray(f[Pi], float))) + _eq(v, 'mean_e_err' + sfx, where, tag, f, [e, Pi], lambda: _mean_e_err(pi, f[e])) + _eq(v, 'agg_income_err' + sfx, where, tag, f, [y, Pi, *ref_names], + lambda: _agg_income_err(pi, f[y], ref())) return pi -def _v03_rank(v, out, spec): - d = out.get('ss_detail') - miss = _need(d, ('Y', 'C', 'A', 'r', 'eis', 'a_min', 'e_grid', 'Pi', 'y')) - if miss: - return _skip(v, 'V2/V3/V4 (T1)', miss) - pi = _income(v, '', d['e_grid'], d['Pi'], d['y'], d['Y']) - _put(v, 'hh_budget', household_budget_resid(d['C'], d['A'], d['r'], d['y'], pi)) +def _coverage(at, vals): + missing = [w for w, x in zip(at, vals) if x is None] + nonfinite = [w for w, x in zip(at, vals) if x is not None and not np.isfinite(x)] + n = len(vals) - len(missing) + state = ('nonfinite' if nonfinite else 'not_reported' if n == 0 else + 'incomplete' if missing else 'complete') + return dict(state=state, n_expected=len(vals), n_reported=n, missing=missing, + nonfinite=nonfinite) + + +def _finish(v): + """Coverage summary per quantity, res['v0_3']['status'] (T5 paths: 'paths.