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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ The binary wheels were per minor version and stopped at cp314; on CPython
abi3audit). The pure `py3-none-any` wheel stays, for every platform without a
binary (free-threaded builds, 32-bit Windows, others).

**The compiled engine is the C of record (BUG-0002).** `csrc/` was an old
copy of the C: its `.inp` path (`estimate_w`, `Model`) had drifted from
atsw-gui's (the optimizer's line search, the boundary sentinel, the MA wall
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).

**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
diagonal system can fail the likelihood where each series alone passes; the
Expand Down
24 changes: 22 additions & 2 deletions bugs/BUG-0002-c-sources-are-copies-and-have-already-drifted.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
id: BUG-0002
title: The C sources are three unsynchronised COPIES, and they have already drifted — the termcode fix lives in the embedded copy only
status: open
status: fixed
severity: high
component: csrc
found_in: 0.1.3
fixed_in:
fixed_in: unreleased (after 0.3.4)
reported: 2026-08-12
reporter: Revisión de defectos del ecosistema
tags:
Expand Down Expand Up @@ -118,3 +118,23 @@ path goes in drvarma 6.0.
Two ways to close it: bring `drvmlest.c`/`qnewtopt.c`/`nlatools.c` to the
C's and regenerate the `.inp` path's references (its standard errors become
fdhess's), or leave it until 6.0 removes the path. A decision for David.

## Resolution (2026-11-28)

Resynced, not waited for 6.0: the path is still distributed, and the port
does not part from the C while it is. `csrc/internal/` is now atsw-gui's at
d603ea1, every file identical (`drvmlest.c`, `qnewtopt.c`, `nlatools.c`,
`elfvarma.c`, `main.h`, `likhost.h`, `optimhost.h`, and `lib/lik/{lik.c,
lik.h, multshea.c}`, `lib/optim/lnsrch.c`, `lib/fuepre/tusmodel.h`, which
they now need). `drvarma_api.c` reads the verdict from `opt_termcode` /
`opt_iters`, holds `qq[1,1]` (`est_fixed`) and returns `se_how` and the MA
wall count; `estimate_w(hessian="fd")` asks the C for its own fdhess.

- `tests/data/homologation.json` records each file's sha256 and that it is
identical to the C's; `test_c_oracle.py` passes whole against d603ea1
(36 passed, with `ATSW_GUI`).
- `tests/test_inp_path_as_the_c.py`: six cases of the C's battery; with the
compiled engine the parameter table is the C's line for line.
- What the resync uncovered: the pure-Python `.inp` estimator is not the
C's on four of those cases (BUG-0033).

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
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
severity: medium
component: engine
found_in: 0.3.4
fixed_in:
reported: 2026-11-28
reporter: David / Claude — the resync of csrc with the C (BUG-0002)
tags: [inp-path, estimate_py, homologation, pure-python]
references:
- bugs/BUG-0033-repro/repro.py
- tests/test_inp_path_as_the_c.py (the four cases marked xfail)
- tests/data/inp_c/cases.json (the C's numbers)
- src/drvarma/estimate_py.py
- BUG-0002
---

## Summary

The deprecated `.inp` path (`estimate_w`, `Model`) was homologated against
the frozen 0.4.1 program, not the current C. With `csrc/` resynced to the C
of record (BUG-0002), the port with the compiled engine gives the C's
parameter table line for line on six cases of the C's battery. The
pure-Python estimator (`estimate_py`) does not, on four of them:

| case | ΔlogL (pure − C) | what |
|---|---|---|
| c1 IPC AR(1) | 0 | fdhess SEs to 1.6e-4: fine |
| c2 IPC ARMA(2,1) diag Σ | −0.00005 | on the boundary: BFGS SEs up to 2× |
| c3 PSW ARMA(1,1) | **−0.218** | stops elsewhere |
| c5 EU diag AR/MA | 0 | same logL, estimates 1e-2 apart (a flat direction?) |
| c6 IPC AR(1), method 2 | 0 | fine |
| c7 IPC ARMA(1,1) twostep | +0.0016 | the C stops lower |

## Impact

Medium. Only the deprecated `.inp` path and only without the compiled engine
(no binary wheel: free-threaded builds, 32-bit Windows, DRVARMA_NO_ENGINE).
The ladder, what sima uses, is homologated separately and is not affected.

## Reproduction

`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

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.

## Fix

—

## Validation

—
228 changes: 228 additions & 0 deletions bugs/BUG-0033-repro/PSW.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
* DRVARMA example input file - PSW (raw levels)
* 2 monthly series; modelled in log first differences
***********************************************************
** Frequency (1=A, 4=Q, 12=M):
12
** Series, observations, start (subperiod year):
2 216 1 2005
** Series names:
PSW_a PSW_b
** Box-Cox lambda, regular differences, annual differences:
0.0 1 0
** Data:
69.53 19.670
69.59 20.740
70.165 24.420
71.118 26.270
71.374 27.020
71.377 25.520
70.882 26.940
71.085 28.380
71.351 29.670
72.058 28.850
72.169 26.270
72.409 29.420
72.111 32.940
72.264 35.870
72.765 33.550
73.357 28.250
73.289 28.140
73.338 30.720
72.878 30.760
73.213 31.590
73.431 28.290
73.926 30.330
74.167 31.090
74.294 32.150
73.773 34.270
73.807 34.740
74.322 36.760
75.34 36.690
75.784 40.280
75.904 38.020
75.328 40.690
75.661 44.940
75.796 45.950
76.575 53.130
76.767 48.460
76.692 43.330
76.046 46.840
76.243 47.970
76.846 54.310
77.953 53.040
78.102 49.830
78.284 56.260
77.805 58.700
78.147 64.970
78.627 65.570
79.266 62.370
79.386 58.300
79.557 59.430
79.234 65.510
79.272 61.630
79.833 62.900
80.959 69.690
81.251 70.940
81.374 70.960
80.89 74.410
81.055 73.050
80.922 63.870
81.254 58.880
81.455 59.370
81.678 62.030
81.129 54.570
81.184 59.260
81.8 60.560
82.93 63.970
83.158 63.460
83.311 67.480
82.704 74.180
82.818 72.390
83.09 79.930
84.167 86.200
84.77 94.620
85.125 91.730
84.598 92.950
84.73 95.350
85.482 105.560
86.402 112.570
86.985 125.390
87.486 133.930
87.066 133.440
86.879 116.610
86.861 103.900
87.16 76.650
86.79 57.440
86.345 41.020
85.281 41.740
85.29 39.160
85.43 47.980
86.264 49.790
86.234 59.160
86.614 69.680
85.874 64.090
86.174 71.060
85.971 69.460
86.584 75.820
87.053 78.080
87.031 74.300
86.158 78.220
86.001 76.420
86.639 81.240
87.562 84.480
87.756 73.840
87.913 75.350
87.519 76.370
87.74 76.820
87.801 75.310
88.603 81.900
89.084 84.140
89.631 89.040
88.975 89.420
89.088 89.580
89.754 102.940
90.871 110.040
90.841 101.330
90.713 96.290
90.226 97.190
90.338 86.330
90.559 85.610
91.273 86.410
91.643 97.210
91.762 98.570
90.753 100.240
90.847 102.250
91.458 106.190
92.743 103.330
92.606 94.700
92.433 82.410
92.217 87.930
92.736 94.160
93.649 94.720
94.445 89.570
94.328 86.660
94.394 88.250
93.188 94.690
93.349 95.320
93.678 93.050
94.028 92.070
94.201 94.800
94.34 95.800
93.853 104.610
94.145 106.570
93.969 106.290
94.351 100.540
94.547 93.860
94.632 97.630
93.373 94.620
93.333 100.820
93.541 100.800
94.373 102.070
94.395 102.180
94.421 105.790
93.533 103.590
93.681 96.540
93.824 93.210
94.261 84.400
94.195 75.790
93.646 59.290
92.141 47.220
92.331 50.580
92.92 47.820
93.774 54.450
94.222 59.270
94.474 59.820
93.597 50.900
93.286 42.870
92.999 45.480
93.595 46.220
93.937 42.440
93.663 37.190
91.876 31.680
91.552 30.320
92.139 37.550
92.785 40.750
93.292 46.710
93.723 48.760
93.041 44.650
93.161 44.720
93.165 45.180
94.23 49.780
94.572 45.660
95.132 51.970
94.609 52.500
94.269 53.470
94.249 49.330
95.154 51.060
95.097 48.480
95.138 45.180
94.482 46.630
94.67 48.040
94.835 49.820
95.71 51.580
96.147 56.640
96.19 57.880
95.153 63.700
95.281 62.230
95.393 62.730
96.181 66.250
97.048 69.980
97.302 67.870
96.604 70.980
96.742 68.060
96.978 70.230
97.875 70.750
97.768 56.960
97.329 49.520
96.085 51.380
96.32 54.950
96.669 58.150
97.644 63.860
97.834 60.830
97.719 54.660
97.113 57.350
97.059 54.810
97.059 56.950
98.001 53.960
98.167 57.030
98.096 59.880
37 changes: 37 additions & 0 deletions bugs/BUG-0033-repro/repro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""BUG-0033: the pure-Python .inp path does not reach the C's optimum.

PSW, VARMA(1,1) (the C battery's case c3_psw_arma11). The C (atsw-gui
engines/drvarma, tests/banco/ref) and the port with the compiled engine end
at logL -871.32401308; the pure-Python estimator (DRVARMA_NO_ENGINE=1) at
-871.542051, 0.22 lower.

Exits 1 while the pure-Python logL is more than 1e-5 from the C's, 0 when
it is not.

python3 bugs/BUG-0033-repro/repro.py # exits 1 while open
"""
import os
import re
import shutil
import subprocess
import sys
import tempfile

HERE = os.path.dirname(os.path.abspath(__file__))
SRC = os.path.join(HERE, "..", "..", "src")
C_LOGL = -871.32401308

with tempfile.TemporaryDirectory() as t:
shutil.copy(os.path.join(HERE, "PSW.inp"), t)
env = dict(os.environ, DRVARMA_NO_ENGINE="1",
PYTHONPATH=SRC + os.pathsep + os.environ.get("PYTHONPATH", ""))
subprocess.run([sys.executable, "-m", "drvarma.cli", "PSW", "1", "1"], cwd=t,
env=env, capture_output=True, text=True, timeout=1800)
out = open(os.path.join(t, "PSW.out"), errors="replace").read()
logl = float(re.findall(r"Log-likelihood = (-?[\d.]+)", out)[-1])
print(f"pure-Python logL {logl:.6f}, the C's {C_LOGL:.6f}")
if abs(logl - C_LOGL) > 1e-5:
print("OPEN: the pure-Python .inp path stops elsewhere")
sys.exit(1)
print("closed")
sys.exit(0)
Loading
Loading