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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ count). Every vendored file is now atsw-gui's, identical, with `lib/lik` and
`lib/optim/lnsrch.c`, and with the compiled engine `Model` takes its fdhess
standard errors from the C itself (`estimate_w(hessian="fd")`): on six cases
of the C's battery the parameter table is the C's line for line
(`tests/test_inp_path_as_the_c.py`). The pure-Python `.inp` estimator is not
yet the C's on four of them (BUG-0033).
(`tests/test_inp_path_as_the_c.py`). The pure-Python `.inp` estimator is the
C's wherever there is an interior maximum; on the three cases whose search ends
on the MA wall it stops at another point of the wall, the property the ladder
already has, and they are checked with the compiled likelihood only (BUG-0033,
studied iteration by iteration: the paths agree to 1e-9 until they reach the
wall).

**The gate says when the diagonal system could not be evaluated (BUG-0020).**
With a univariate optimum whose own MA sits on the invertibility wall, the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: BUG-0033
title: The pure-Python .inp path is not the C's — on PSW VARMA(1,1) it stops 0.22 below the C's optimum, and on the boundary its BFGS standard errors are another path's
status: open
status: wontfix
severity: medium
component: engine
found_in: 0.3.4
Expand Down Expand Up @@ -45,18 +45,38 @@ The ladder, what sima uses, is homologated separately and is not affected.
`bugs/BUG-0033-repro/repro.py`: PSW VARMA(1,1) with DRVARMA_NO_ENGINE=1
gives logL −871.542051; the C, −871.32401308. Exits 1 while open.

## Root cause
## Root cause (2026-11-28)

Not studied. The C's `.inp` path moved after 0.4.1 (the line-search
objective, the boundary sentinel in `objcfunc`, `varma_lik`, the start
`init_varma`/`twostep`), and `estimate_py` followed 0.4.1. To be found by
following the two paths iteration by iteration on c3, as BUG-0030 did for
the ladder.
There is none in the port's algorithm. Followed iteration by iteration
(`estimate_w(maxits=k)` against `estimate_w_py(maxits=k)`, k = 1…500):

- **c2, c3, c7: the MA wall.** On PSW ARMA(1,1) the two paths agree to
1e-9 in every parameter up to iteration 30 and to 3e-6 at 60. From there
they part (5.6e-2 at 70) while both climb to the invertibility wall, and
both stop ON it, with an MA root of modulus 1.00005 and termcode 3: the C at
−871.324013 after 100 iterations, Python at −871.542051 after 109. c2 and
c7 end on the wall too (maximum MA modulus 1.00005, the C's
`ma_boundary` = 2). With no interior maximum the stopping point is a
property of the path, not of the model, and two arithmetics that agree to
rounding part there. This is the property `docs/HOMOLOGATION.md` already
states for the ladder (BUG-0030): on the wall, the compiled likelihood only.
- **c5: not a difference.** The model is the C's to 1e-8 (μ, Φ, Σ). Only
the unnormalised Q differs, by about 1 %: Q → cQ is a flat direction of the
concentrated likelihood, and the table prints Q on the scale the path ended
at (the C's `cov[1,1]` is 1.220120, "normalised" only in the sense that
fdhess holds it).

## Fix

—
None to the estimator: the pure-Python path is the C's wherever there is an
interior maximum. The test says so instead of marking a defect:

- c5 is compared with the C's table relative to `cov[1,1]`, and passes;
- c2, c3 and c7 are skipped without the compiled engine, with the reason,
as the ladder's wall cases; with it they are the C's line for line.

## Validation

—
`tests/test_inp_path_as_the_c.py`: with the engine 6 of 6; pure Python 3 of
3 off the wall, c5 included. The repro keeps exiting 1: it shows the
property (two points on the wall), not a defect.
4 changes: 2 additions & 2 deletions bugs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ In-repo bug tracker for **drvarma**. One Markdown file per bug (`BUG-NNNN-slug.

New report: `art-bug new` (or copy `TEMPLATE.md`). Validate: `art-bug check`. A fix commit references the id, e.g. `fix(pipeline): BUG-0001 …`.

**35 report(s), 1 open.**
**35 report(s), 0 open.**

| id | status | sev | component | title | fixed in |
|----|--------|-----|-----------|-------|----------|
| [BUG-0033](BUG-0033-el-port-puro-de-la-via-inp-no-llega-al-optimo-del-c.md) | open | medium | engine | The pure-Python .inp path is not the C's — on PSW VARMA(1,1) it stops 0.22 below the C's optimum, and on the boundary its BFGS standard errors are another path's | — |
| [BUG-0001](BUG-0001-deseason-phase-still-unpatched-in-the-c-engine.md) | fixed | high | deseason | The seasonal-adjustment phase off-by-one is fixed in the Python port but STILL LIVE in the C engine, which the standalone executable uses | the C, atsw-gui engines/drvarma BUG-0008 (2026-11-28); the port long before |
| [BUG-0002](BUG-0002-c-sources-are-copies-and-have-already-drifted.md) | fixed | high | csrc | The C sources are three unsynchronised COPIES, and they have already drifted — the termcode fix lives in the embedded copy only | unreleased (after 0.3.4) |
| [BUG-0003](BUG-0003-seasonal-adjustment-applied-in-levels-before-box-cox.md) | fixed | medium | deseason | The seasonal component is estimated and subtracted in LEVELS, before the Box-Cox log, so a multiplicative pattern on a trending index is adjusted at the wrong scale | 0.2.0 (Python); the C, atsw-gui engines/drvarma BUG-0010 (2026-11-28) |
Expand Down Expand Up @@ -43,4 +42,5 @@ New report: `art-bug new` (or copy `TEMPLATE.md`). Validate: `art-bug check`.
| [BUG-0011](BUG-0011-el-consenso-impone-un-lambda-y-el-d-maximo.md) | wontfix | low | mcp | The consensus imposes one lambda and d = max(d_i), which over-differences an I(0) series | — |
| [BUG-0012](BUG-0012-los-coeficientes-armonicos-no-cuentan.md) | wontfix | low | deseason | The harmonic seasonal coefficients are not counted in degrees of freedom, k or forecast uncertainty | — |
| [BUG-0013](BUG-0013-el-aviso-de-cointegracion-usa-valores-criticos-adf.md) | wontfix | low | mcp | The cointegration warning uses ADF critical values on a residual, and always normalises on the first series | — |
| [BUG-0033](BUG-0033-el-port-puro-de-la-via-inp-no-llega-al-optimo-del-c.md) | wontfix | medium | engine | The pure-Python .inp path is not the C's — on PSW VARMA(1,1) it stops 0.22 below the C's optimum, and on the boundary its BFGS standard errors are another path's | — |

9 changes: 7 additions & 2 deletions docs/HOMOLOGATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ recorded commit (`identical_to_c` in the record), only `drvarma_api.c` and
(`tests/banco/ref`, `tests/data/inp_c/cases.json`): with the compiled engine
the port's parameter table is the C's line for line, the standard errors
fdhess's computed by the C itself (`estimate_w(hessian="fd")`). The
pure-Python estimator matches on two of them and not yet on four (BUG-0033).
pure-Python estimator matches wherever there is an interior maximum (c1, c5,
c6; c5's Q compared relative to `cov[1,1]`, a flat direction); on the three
cases whose search ends on the MA wall it stops at another point, the
property of the wall stated above, and they are checked with the compiled
likelihood only (BUG-0033).

`-deseason` (BUG-0003; the C's BUG-0010): both engines deseasonalize on the
Box-Cox scale. `tests/test_deseason_as_the_c.py` holds the battery's 11
Expand All @@ -112,7 +116,8 @@ moves them by up to 2.5 %, and the harmonic regression's least squares

## What is not homologated against the current C

- **The pure-Python `.inp` path** on the four cases of BUG-0033.
- **The pure-Python `.inp` path on the MA wall** (BUG-0033): as the ladder's,
with the compiled likelihood only.
- **The `auto` decision of `-deseason`**: art's HAC F here, the OLS F in
the C.
- **The older `.inp` tests** (`test_estimate_cffi.py`, `test_estimate_py.py`,
Expand Down
44 changes: 31 additions & 13 deletions tests/test_inp_path_as_the_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
the C's log-likelihood, how it got the standard errors and its parameter
table. The vendored C (``csrc/``) is the C's, so with the compiled engine the
port's table is the C's line for line. The pure-Python estimator is held to
the numbers where the standard errors are fdhess's; where the optimum is on
the boundary they are BFGS's, path-dependent, and the port's path is not yet
the C's (BUG-0033)."""
the C's numbers where there is an interior maximum. Where the search ends on
the MA wall (c2, c3, c7) there is none: the point it stops at is the path's,
and the pure-Python arithmetic parts from the C's there, as on the ladder
(docs/HOMOLOGATION.md, BUG-0030); those cases are checked with the compiled
likelihood only (BUG-0033)."""
import json
import os
import re
Expand Down Expand Up @@ -53,7 +55,8 @@ def _numbers(rows):
try:
out[x[0]] = (float(x[1]), float(x[2]))
except (ValueError, IndexError):
pass
if len(x) > 2 and x[2] == "(normalised)": # cov[1,1], held
out[x[0]] = (float(x[1]), None)
return out


Expand All @@ -66,23 +69,38 @@ def test_with_the_engine_the_table_is_the_cs(case, tmp_path):
assert rows == case["table"]


# The pure-Python estimator is not yet the C's on these (BUG-0033): on PSW
# ARMA(1,1) it stops 0.22 lower, on the twostep case 0.0016 higher, on the
# boundary its BFGS standard errors are another path's, and on c5 it reaches
# the same logL at other estimates (a flat direction).
BUG_0033 = {"c2_ipc_arma21", "c3_psw_arma11", "c5_eu_diag", "c7_ipc_twostep"}
# On the MA wall (BUG-0033): no interior maximum, so the point where the search
# stops is the path's. The pure-Python path is the C's to ~1e-9 for dozens of
# iterations and parts from it there by rounding (PSW ARMA(1,1): at iteration
# ~60; both end with an MA root of modulus 1.00005, termcode 3). Checked with
# the compiled likelihood only, as the ladder's wall cases.
ON_THE_WALL = {"c2_ipc_arma21", "c3_psw_arma11", "c7_ipc_twostep"}


@pytest.mark.parametrize("case", REC["cases"], ids=[c["name"] for c in REC["cases"]])
def test_the_pure_python_estimator_gives_the_cs_numbers(case, tmp_path):
if case["name"] in BUG_0033:
pytest.xfail("BUG-0033: the pure-Python .inp path is not yet the C's here")
if case["name"] in ON_THE_WALL:
pytest.skip("on the MA wall: the stopping point is the path's; checked "
"with the compiled likelihood only (BUG-0033)")
logl, se, rows = _run(case, tmp_path, no_engine=True)
assert logl == pytest.approx(case["logL"], abs=1e-5)
assert se == case["se_method"]
got, want = _numbers(rows), _numbers(case["table"])
assert got.keys() == want.keys()
# Q is estimated unnormalised and Q -> cQ is a flat direction of the
# concentrated likelihood: the table's cov[i,j] are on an arbitrary scale,
# the one the path ended at (c5: the same model, Q 1 % apart). Compare
# them, and their standard errors, relative to cov[1,1].
gs = got.get("cov[1,1]", (1.0, None))[0]
ws = want.get("cov[1,1]", (1.0, None))[0]
for k in want:
assert got[k][0] == pytest.approx(want[k][0], abs=2e-6), k
g, w = got[k], want[k]
if k.startswith("cov["):
g = (g[0] / gs, None if g[1] is None else g[1] / gs)
w = (w[0] / ws, None if w[1] is None else w[1] / ws)
assert g[0] == pytest.approx(w[0], abs=2e-6), k
if w[1] is None: # the held cov[1,1]
assert g[1] is None, k
continue
# fdhess by finite differences in Python and in C: the last digits
assert got[k][1] == pytest.approx(want[k][1], rel=5e-4), k
assert g[1] == pytest.approx(w[1], rel=5e-4), k
Loading