diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 315b1b9..57b8aba 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,8 +1,10 @@ name: Publish to PyPI -# Builds cp310-cp314 BINARY wheels (Linux x86_64+aarch64, macOS arm64 and -# x86_64, Windows AMD64) with GSL bundled, plus the pure-Python wheel and the -# sdist, and publishes them all on a v* tag. +# Builds abi3 BINARY wheels, cp310-abi3, one per platform (Linux x86_64+aarch64, +# macOS arm64 and x86_64, Windows AMD64) with GSL bundled and smoke-tested on +# cp310-cp315, plus the pure-Python wheel and the sdist, and publishes them all +# on a v* tag. Up to 0.3.4 the wheels were per minor version and stopped at +# cp314: on CPython 3.15 pip took the pure wheel in silence (BUG-0031). # # macOS: macosx_11_0 wheels for both processors, as atsw-gui's .dmg (macOS 11 # on Apple Silicon and Intel). arm64 on macos-15, x86_64 on macos-15-intel; @@ -69,7 +71,7 @@ jobs: platforms: aarch64 - name: Build wheels - uses: pypa/cibuildwheel@v3.4.1 + uses: pypa/cibuildwheel@v4.3.5 # 4.x: CPython 3.15 and abi3audit env: CIBW_ARCHS_LINUX: "x86_64 aarch64" MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos_target }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 802c7a5..8bf06fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ compiled C engine. ## Unreleased +**One abi3 wheel per platform, for every CPython from 3.10 on (BUG-0031).** +The binary wheels were per minor version and stopped at cp314; on CPython +3.15 pip took the pure wheel and every fit ran on the port. Now the wheel is +`cp310-abi3` and is smoke-tested on cp310–cp315 (cibuildwheel 4.3.5, with +abi3audit). The pure `py3-none-any` wheel stays, for every platform without a +binary (free-threaded builds, 32-bit Windows, others). + +**DRVARMA_NO_ENGINE reaches `elf_c` and `marma_c` (BUG-0032).** Only +`estimate_w` read it, so the ladder went on computing in C while +`engine_backend()` said "python". + **The own MA factors, each read alone, are said when outside the circle** — the C's `own_ma_outside` (atsw-gui #223). The likelihood is evaluated only where the MA operator of the system is invertible, and the ladder does not diff --git a/RELEASING.md b/RELEASING.md index 6340eaf..d409d72 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -6,13 +6,19 @@ of that workflow's matrix, and a manual upload leaves users without them. ## What gets published -* **Binary wheels**, cp310–cp314, with the GSL bundled (cibuildwheel): +* **Binary wheels**, one `cp310-abi3` per platform, with the GSL bundled + (cibuildwheel), smoke-tested on cp310–cp315. abi3 serves every CPython from + 3.10 on, later ones included (BUG-0031); when a new CPython goes final, add it + to `[tool.cibuildwheel] build` so the wheel is tested on it + (`bugs/BUG-0031-repro/repro.py` keeps the list of final versions). Not + covered: free-threaded builds and 32-bit Windows, which get the pure wheel: Linux x86_64 and aarch64, macOS arm64 and x86_64 (`macosx_11_0`, built on macos-15 and macos-15-intel), Windows AMD64. `tools/check_macos_minos.py` stops the build if a macOS binary asks for a newer system than its tag. * **Pure-Python wheel** `py3-none-any` (built with `DRVARMA_NO_ENGINE=1`), the - fallback for any other platform. + fallback for any other platform. It stays: every platform gets drvarma, and + the port warns when it computes (BUG-0005). * **sdist**, which ships `csrc/` and builds the engine where GSL is present. All three carry the bug register (`tools/sync_material.py` copies it into diff --git a/TODO.md b/TODO.md index 238904c..a91ad5d 100644 --- a/TODO.md +++ b/TODO.md @@ -703,6 +703,58 @@ the CFFI engine is an optional accelerator only. Ordered PP1 → PP5. solo en la copia empotrada. Ahí va el arreglo y el test del `diff`. - [ ] Single source of truth for forecasting/diagnostics: numpy (current) vs the C. +## ESTUDIO — La velocidad del port en Python (no es un bug) + +**No va al registro de defectos.** `_as311.elf` es un port fiel, bucle a bucle, +de `elfvarma.c`: da la misma verosimilitud con un error de ~1e-10, y para eso +existe. Su lentitud es el coste de esa fidelidad. Lo que se estudia es si se +puede ganar velocidad sin perder la homologación. + +**Por qué importa (rodaje de la P08, 2026-11-27).** Cinco grupos acabaron con +el port porque no tenían rueda binaria para su Python (`bugs/BUG-0031`). sima +mete el polinomio AR univariante de cada serie dentro de Phi(B). En el VAR +monetario de EE. UU. (IPI, IPC, WTI, FF, 1990-2007), elf recibe m = 4, +n = 215 y p = 15, y un `estimate` de sima lo llama 3 293 veces con p = 0 y +8 795 con p = 1. Con el motor tarda 15 s y 46 s; con el port, unos 40 min y +1,7 h. Dos grupos dejaron sima por statsmodels o MCO, y otros relajaron las +tolerancias o renunciaron al VAR completo. fue en Python también es lento, +pero se puede usar. + +**Lo medido.** El punto de partida es `bench/velocidad_elf_port.py`. + +| Caso | C (ms por evaluación) | Port (ms por evaluación) | Cociente | +|---|---|---|---| +| Sintético, m = 4, n = 215, p = 2 | 0,12 | 19–56 | 166–379 | +| Sintético, m = 4, n = 215, p = 15 | 8–15 | 300–575 | ~37 | +| Sistema monetario real, p = 15 | 4,9 | 704 | 143 | + +La documentación (DEVELOPER_GUIDE 4.1: 13–100 veces; README: 20–250 veces) +mide `estimate_w` con p ≤ 3. No dice el coste absoluto con los órdenes de sima. + +**El perfil.** 150 s de un `estimate` con p = 0 en el port: +- el 99,7 % se va en `elf`; +- 93,6 s son sus propios bucles: [3.1]/[3.2], seis bucles anidados en Python; +- 35,7 s son `cgamma`; +- 15,0 s son 31,9 millones de llamadas a la función `gval`, unas 65 000 por evaluación; +- el 57 % del tiempo total son las hessianas por diferencias finitas (`fd_covariance`). + +**El estudio, por pasos:** +- [ ] Perfil completo con `bench/velocidad_elf_port.py` a varios (m, p, q): + dónde crece el coste y cuánto se lleva cada bloque de `elf` y de `cgamma`. +- [ ] Vectorizar [3.1]/[3.2] y `cgamma` por bloques (m × m) con numpy, y medir + la desviación frente al C. El criterio es la homologación a 1e-10 + (`HOMOLOGATION.md`), y donde importe hay que conservar el orden de suma + del C. +- [ ] Si no basta, otras vías, cada una con su coste de fidelidad: numba como + dependencia opcional, o el acceso empaquetado a gamma sin closure. +- [ ] Cuántas evaluaciones pide la escalera. ¿Hacen falta las hessianas de los + univariantes de la puerta, que no se usan, o en cada peldaño intermedio? + Afecta a los dos motores. +- [ ] Documentar el coste absoluto junto al cociente: «con los órdenes de sima + (p ~ 15, m = 4) una evaluación tarda ~0,6 s y un ajuste necesita miles». +- Objetivo orientativo: menos de 50 ms por evaluación con m = 4 y p = 15, es + decir, un `estimate` con p = 1 por debajo de 5 minutos sin motor. + ## ESTUDIO — El criterio de parada del optimizador (no es un bug) **Esto no va al registro de defectos, y la distinción es sustantiva.** diff --git a/bench/velocidad_elf_port.py b/bench/velocidad_elf_port.py new file mode 100644 index 0000000..fa0bd4e --- /dev/null +++ b/bench/velocidad_elf_port.py @@ -0,0 +1,69 @@ +"""Speed of the pure-Python elf (_as311.elf) against the compiled one, at the +orders sima sends it. Starting measurement of the study in TODO.md +(«ESTUDIO — La velocidad del port en Python»); not a bug: the port is a +faithful, loop-by-loop port of elfvarma.c. + +sima's fits carry each series' univariate AR polynomial expanded inside +Phi(B): on the US monetary system (IPI, IPC, WTI, FF, 1990-2007) elf receives +m = 4, n = 215, p = 15, and a sima estimate calls it 3,293 times with p = 0 +and 8,795 with p = 1. The documented ratio (DEVELOPER_GUIDE 4.1, 13-100x; +README, 20-250x) was measured with estimate_w and p <= 3. + +The script scores the same synthetic stationary VAR(p), m = 4, n = 215, with +the engine and with the port at p = 2 and p = 15, and prints the time per +evaluation and the ratio. Measured 2026-11-27, Linux x86_64: 0.12 / 46 ms +(379x) at p = 2, 14.9 / 550 ms (37x) at p = 15; on the real system 4.9 / 704 +ms (143x), so about 40 min (p = 0) and 1.7 h (p = 1) for a sima estimate. + + python3 bench/velocidad_elf_port.py +""" +import os +import sys +import time +import warnings + +import numpy as np + +warnings.simplefilter("ignore") +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "src")) +import drvarma._engine as EN # noqa: E402 + +if EN._load_c() is None: + sys.exit("the compiled engine is needed to compare (build it first)") + +m, n = 4, 215 +rng = np.random.default_rng(31) + + +def case(p): + phi = np.zeros((p, m, m)) + for k in range(p): # small, decaying: stationary + phi[k] = rng.normal(0, 0.04, (m, m)) * 0.8 ** k + phi[0] += np.diag([0.3, 0.2, 0.25, 0.1]) + qq = np.eye(m) + w = np.zeros((n + p, m)) + e = rng.normal(size=(n + p, m)) + for t in range(p, n + p): + w[t] = e[t] + sum(phi[k] @ w[t - k - 1] for k in range(p)) + return (m, n, p, 0, np.zeros(m), phi, np.zeros((0, m, m)), qq, w[p:]) + + +def per_eval(args, reps): + t = time.perf_counter() + for _ in range(reps): + out = EN.elf_c(*args) + return (time.perf_counter() - t) / reps, out[0] + + +real = EN._load_c +for p in (2, 15): + args = case(p) + tc, lc = per_eval(args, 20) + EN._load_c = lambda: None # what the py3-none-any wheel gives + tp, lp = per_eval(args, 1) + EN._load_c = real + r = tp / tc + print(f"m={m} n={n} p={p:2d}: C {tc*1e3:7.2f} ms port {tp*1e3:8.1f} ms " + f"{r:5.0f}x (logL {lc:.6f} / {lp:.6f})") +print(f"a sima estimate of that size: ~3,300 (p = 0) to ~8,800 (p = 1) evaluations") diff --git a/bugs/BUG-0031-repro/repro.py b/bugs/BUG-0031-repro/repro.py new file mode 100644 index 0000000..cc4a5d8 --- /dev/null +++ b/bugs/BUG-0031-repro/repro.py @@ -0,0 +1,42 @@ +"""BUG-0031: the binary wheels stop at cp314, and a pure-Python wheel is always +there to catch any other interpreter in silence. + +[tool.cibuildwheel] builds "cp310-* ... cp314-*" and skips "*-win32" and the +free-threaded "cp31?t-*"; py3-none-any is published next to them. CPython 3.15.0 +is final since 2026-10-09, and `uv tool install` (how the course installs the +suite) takes the newest Python it finds or downloads. On 3.15, a free-threaded +build or a 32-bit Windows Python, pip and uv install the py3-none-any wheel +without a word and every system estimate runs on the port (hours where the engine takes +seconds: TODO.md, the speed study). + +The repro reads pyproject.toml offline and exits 1 while the build list leaves +out a CPython that is final, or while the pure wheel is published with no +binary for it. FINAL lists the released minor versions (update it). + + python3 bugs/BUG-0031-repro/repro.py # exits 1 while open +""" +import os +import re +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +FINAL = ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] # 3.15.0: 2026-10-09 +txt = open(os.path.join(HERE, "..", "..", "pyproject.toml"), encoding="utf-8").read() +block = txt.split("[tool.cibuildwheel]", 1)[1].split("\n[", 1)[0] +build = re.search(r'build\s*=\s*"([^"]*)"', block).group(1).split() +skip = re.search(r'skip\s*=\s*"([^"]*)"', block) +skip = skip.group(1).split() if skip else [] +built = {f"3.{mm.group(1)}" for b in build if (mm := re.match(r"cp3(\d+)-", b))} +missing = [v for v in FINAL if v not in built] +print("cibuildwheel build:", " ".join(build)) +print("cibuildwheel skip :", " ".join(skip)) +print("final CPython without a binary wheel:", ", ".join(missing) or "none") +for s in skip: + if s in ("*-win32",) or "t-*" in s: + print(f" also no binary for: {s} -> py3-none-any, the port (it warns: BUG-0005)") +# The fix is an abi3 wheel (setup.py): one binary per platform for every +# CPython >= 3.10. Without it a version in the list is still per-version only. +setup = open(os.path.join(HERE, "..", "..", "setup.py"), encoding="utf-8").read() +abi3 = "py_limited_api" in setup and '"cp310"' in setup +print("abi3 wheel (one binary for every CPython >= 3.10):", "yes" if abi3 else "NO") +sys.exit(1 if missing or not abi3 else 0) diff --git a/bugs/BUG-0031-sin-rueda-para-python-3-15-se-instala-el-port-en-silencio.md b/bugs/BUG-0031-sin-rueda-para-python-3-15-se-instala-el-port-en-silencio.md new file mode 100644 index 0000000..d7db01e --- /dev/null +++ b/bugs/BUG-0031-sin-rueda-para-python-3-15-se-instala-el-port-en-silencio.md @@ -0,0 +1,103 @@ +--- +id: BUG-0031 +title: Binary wheels stop at cp314 (and skip win32 and free-threaded); on CPython 3.15, final since 2026-10-09, pip and uv install the py3-none-any wheel in silence and every fit runs on the port +status: fixed +severity: high +component: packaging +found_in: 0.3.4 +fixed_in: unreleased (after 0.3.4) +reported: 2026-11-27 +reporter: David / Claude — the P08 run of the course (UCM) +tags: [packaging, wheels, engine, python-3.15, windows, macos] +references: + - pyproject.toml [tool.cibuildwheel] build / skip + - .github/workflows/publish.yml (cp310-cp314) + - bugs/BUG-0031-repro/repro.py + - BUG-0005, BUG-0022, BUG-0024 (the same silence, other causes) + - TODO.md «ESTUDIO — La velocidad del port en Python» (what the port costs) +--- + +## Summary + +`[tool.cibuildwheel]` builds `cp310-* … cp314-*` and skips `*-win32` and +`cp31?t-*` (free-threaded). A `py3-none-any` wheel is published next to them. +Any interpreter outside that list gets the pure wheel without a word: +- CPython 3.15, final since 2026-10-09; +- a free-threaded build; +- a 32-bit Python on Windows. `sys.platform` and `platform.machine()` still + print "win32 AMD64", so the provenance does not show it. + +drvarma then computes on the port, which is a faithful port of the C and on sima's orders costs hours where the engine takes seconds (TODO.md, the speed study). fue publishes the same set of +wheels and falls back the same way. + +The course installs the suite with `uv tool install atsw==…`, and uv takes the +newest Python it finds or downloads. In October and November 2026 that is 3.15. + +## Impact + +In the P08 the sima scripts record `drvarma engine python` on Windows AMD64 +(drvarma 0.3.1, 0.3.3 and 0.3.4) and on macOS arm64 (0.3.1 and 0.3.2), all +versions that publish a binary for that platform up to cp314. The Windows +wheels do carry the engine: GSL is static, and the only imports are the CRT, +`VCRUNTIME140.dll` and `python3.dll`, checked on 0.3.1 and 0.3.4 cp312. + +So an interpreter without a wheel is the most likely cause, and 3.15 the most +likely interpreter. This is not confirmed: the scripts do not record the +Python version (sima BUG-0020). The same groups' art scripts show fue on +«motor Python» too. On macOS 0.3.1, which only had `macosx_14_0` wheels, +macOS < 14 also fell back. + +## Reproduction + +`python3 bugs/BUG-0031-repro/repro.py` reads pyproject.toml offline and exits +1 while a final CPython has no binary wheel (the list FINAL is kept by hand): + +``` +cibuildwheel build: cp310-* cp311-* cp312-* cp313-* cp314-* +cibuildwheel skip : *-win32 *-manylinux_i686 pp* cp31?t-* +final CPython without a binary wheel: 3.15 + also no binary for: *-win32 -> py3-none-any, the port, in silence + also no binary for: cp31?t-* -> py3-none-any, the port, in silence +``` + +To confirm on an affected machine: +- Windows: `%APPDATA%\uv\tools\atsw\Scripts\python.exe -c "import sys, drvarma; print(sys.version); print(drvarma.engine_backend(), drvarma.engine_load_error())"` +- macOS: the same with `~/.local/share/uv/tools/atsw/bin/python`. + +## Root cause + +The build list is a fixed set of minor versions, and the pure wheel turns +"no binary for this Python" into a successful install instead of an error or +a build from the sdist. + +## Fix + +- Build cp315, and add a release-time check that the newest final CPython is + in the list. Consider an abi3 wheel: the extension already links + `python3.dll`, which would cover future versions. +- Stop publishing `py3-none-any`, or publish it under an extra or another + name, so that an unsupported interpreter builds from the sdist (and fails + loudly without a compiler) instead of degrading. +- On the user side, the suite's installation guide should pin the Python: + `uv tool install --python 3.13 atsw==…`. + +## Validation + +The repro passes (cp315 built). On a 3.15 interpreter `pip install drvarma` +brings a binary wheel and `engine_backend()` says "c". + +## Resolution (2026-11-27) + +- The extension is built for the limited API (`py_limited_api`, setup.py) and + the wheel is tagged `cp310-abi3`: one binary per platform serves every + CPython from 3.10 on, 3.15 and the ones after it included. cffi already + compiled against the limited API; abi3audit finds 0 violations. +- cibuildwheel 4.3.5 (CPython 3.15, abi3audit after the repair step) builds + it once on cp310 and smoke-tests it on cp310–cp315. +- The `py3-none-any` wheel is NOT dropped: the pure-Python port stays the + drvarma of every platform without a binary (David, 27-nov-2026), and it + warns when it computes (BUG-0005). Making that warning reach sima's user is + sima BUG-0020. +- Still without a binary: free-threaded builds (no limited API) and 32-bit + Windows. They get the port, with its warning. +- The repro now also checks the abi3 configuration. diff --git a/bugs/BUG-0032-drvarma-no-engine-no-llega-a-elf-c.md b/bugs/BUG-0032-drvarma-no-engine-no-llega-a-elf-c.md new file mode 100644 index 0000000..6305f96 --- /dev/null +++ b/bugs/BUG-0032-drvarma-no-engine-no-llega-a-elf-c.md @@ -0,0 +1,62 @@ +--- +id: BUG-0032 +title: DRVARMA_NO_ENGINE makes engine_backend() answer "python" but elf_c and marma_c ignore it and compute in C +status: fixed +severity: low +component: engine +found_in: 0.3.4 +fixed_in: unreleased (after 0.3.4) +reported: 2026-11-27 +reporter: David / Claude — timing the port for the speed study (TODO.md) +tags: [engine, environment, diagnostics] +references: + - src/drvarma/_engine.py:42 (engine_backend), :73 (estimate_w), :166 (marma_c), :205 (elf_c) + - bugs/BUG-0032-repro/repro.py +--- + +## Summary + +The variable is documented as "asks for the port". `estimate_w` honours it, and +so does `engine_backend()`, which then answers "python". `marma_c` and `elf_c` +call `_load_c()` directly and keep computing in C. Those two functions are what +the ladder, and so sima, use. + +## Impact + +The diagnosis is misleading. Timing sima "on the port" with the variable +measures the C: 11-12 s in both cases on the monetary system, while the real +port does not finish in 36 minutes. That is how the first measurement of the +port's speed (2026-11-27) went wrong. And a provenance that records +`engine_backend()` would say "python" for a computation done in C. + +## Reproduction + +`python3 bugs/BUG-0032-repro/repro.py` + +``` +engine_backend() with DRVARMA_NO_ENGINE=1: 'python' +elf_c: 0.15 ms without the variable, 0.13 ms with it, 15.7 ms on the port +OPEN: the variable says python and elf_c computes in C +``` + +## Root cause + +The check `if not os.environ.get("DRVARMA_NO_ENGINE")` only appears in +`estimate_w`. The other entry points were added later (the ladder's scored +likelihood) and call `_load_c()`. + +## Fix + +Move the check into `_load_c()`, or into one helper used by every entry point, +so that the variable means the same thing everywhere `engine_backend()` speaks. + +## Validation + +The repro: with the variable set, `elf_c` costs what the port costs. + +## Resolution (2026-11-27) + +The check moved into `_load_c()`, which every entry point uses: with the +variable set it returns None and `engine_load_error()` says +"DRVARMA_NO_ENGINE is set". `estimate_w` and `engine_backend()` lost their own +copies. `tests/test_bug_0032_no_engine_en_todas.py`. diff --git a/bugs/BUG-0032-repro/repro.py b/bugs/BUG-0032-repro/repro.py new file mode 100644 index 0000000..1afab85 --- /dev/null +++ b/bugs/BUG-0032-repro/repro.py @@ -0,0 +1,49 @@ +"""BUG-0032: DRVARMA_NO_ENGINE is documented as "asks for the port", and +engine_backend() then answers "python"; but elf_c and marma_c do not read it +and keep computing in C. Anyone timing the port with the variable (as the +2026-11-27 investigation did) measures the C and concludes both engines cost +the same. + + python3 bugs/BUG-0032-repro/repro.py # exits 1 while open +""" +import os +import sys +import time +import warnings + +import numpy as np + +warnings.simplefilter("ignore") +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "src")) +import drvarma._engine as EN # noqa: E402 + +if EN._load_c() is None: + sys.exit("needs the compiled engine") +m, n, p = 3, 200, 2 +rng = np.random.default_rng(33) +w = rng.normal(size=(n, m)) +args = (m, n, p, 0, np.zeros(m), np.zeros((p, m, m)) + 0.05, np.zeros((0, m, m)), + np.eye(m), w) + + +def t(reps=5): + s = time.perf_counter() + for _ in range(reps): + EN.elf_c(*args) + return (time.perf_counter() - s) / reps + + +c = t() +os.environ["DRVARMA_NO_ENGINE"] = "1" +said, asked = EN.engine_backend(), t() +real = EN._load_c +EN._load_c = lambda: None +port = t(1) +EN._load_c = real +print(f"engine_backend() with DRVARMA_NO_ENGINE=1: {said!r}") +print(f"elf_c: {c*1e3:.2f} ms without the variable, {asked*1e3:.2f} ms with it, " + f"{port*1e3:.1f} ms on the port") +bad = said == "python" and asked < port / 5 +print("OPEN: the variable says python and elf_c computes in C" if bad else "fixed") +sys.exit(1 if bad else 0) diff --git a/bugs/README.md b/bugs/README.md index 0c02980..e2edd8f 100644 --- a/bugs/README.md +++ b/bugs/README.md @@ -1,10 +1,10 @@ # Bug reports -In-repo bug tracker for **drvarma-python**. One Markdown file per bug (`BUG-NNNN-slug.md`); this index is generated by `art-bug index`. +In-repo bug tracker for **drvarma**. One Markdown file per bug (`BUG-NNNN-slug.md`); this index is generated by `art-bug index`. 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 …`. -**30 report(s), 4 open.** +**32 report(s), 4 open.** | id | status | sev | component | title | fixed in | |----|--------|-----|-----------|-------|----------| @@ -34,6 +34,8 @@ New report: `art-bug new` (or copy `TEMPLATE.md`). Validate: `art-bug check`. | [BUG-0028](BUG-0028-the-c-ols-start-does-not-fall-back-to-zero.md) | fixed | medium | ladder | The ols start falls back to zero in the port but not in the C ladder, which starts from the inadmissible least-squares point and fails | 0.4.0 | | [BUG-0029](BUG-0029-factor-test-frees-an-own-coefficient-held-at-zero.md) | fixed | medium | ladder | factor_test frees in its alternative an own coefficient the model holds at zero, and tests that zero with the row factor | 0.4.0 | | [BUG-0030](BUG-0030-the-ladder-evaluated-points-the-c-refuses-and-walked-the-parameters-in-another-order.md) | fixed | high | ladder | The ladder evaluated points the C's ladder refuses (fue's MA flip in the cast), packed the parameters in another order and seeded ols with another arithmetic — on the MA wall it did not end where the C does | 0.4.0 | +| [BUG-0031](BUG-0031-sin-rueda-para-python-3-15-se-instala-el-port-en-silencio.md) | fixed | high | packaging | Binary wheels stop at cp314 (and skip win32 and free-threaded); on CPython 3.15, final since 2026-10-09, pip and uv install the py3-none-any wheel in silence and every fit runs on the port | unreleased (after 0.3.4) | +| [BUG-0032](BUG-0032-drvarma-no-engine-no-llega-a-elf-c.md) | fixed | low | engine | DRVARMA_NO_ENGINE makes engine_backend() answer "python" but elf_c and marma_c ignore it and compute in C | unreleased (after 0.3.4) | | [BUG-0009](BUG-0009-load-data-toma-la-columna-de-fecha-como-serie.md) | wontfix | medium | mcp | load_data takes a date column as a series, and the sample start is not read from it | — | | [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 | — | diff --git a/pyproject.toml b/pyproject.toml index 30ebd50..7040fc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,8 +93,15 @@ testpaths = ["tests"] # The fix is the shape fue already uses: per-platform binary wheels WITH GSL # bundled, plus the pure wheel as the last resort for platforms not built. [tool.cibuildwheel] -build = "cp310-* cp311-* cp312-* cp313-* cp314-*" -skip = "*-win32 *-manylinux_i686 pp* cp31?t-*" # cp31?t: free-threaded, built by default since cibuildwheel 3.1 +# ONE abi3 wheel per platform (setup.py, BUG-0031): cibuildwheel builds it on +# cp310 and, for every later identifier in the list, reuses it and runs the +# smoke test on that Python. So the list is the versions TESTED, not the ones +# served: the wheel installs on any CPython >= 3.10, the next ones too. When a +# CPython goes final, add it here (bugs/BUG-0031-repro checks it). +build = "cp310-* cp311-* cp312-* cp313-* cp314-* cp315-*" +# Without a binary, pip takes the py3-none-any wheel: the port, which is kept on +# purpose (every platform gets drvarma) and says so when it computes (BUG-0005). +skip = "*-win32 *-manylinux_i686 pp* cp31?t-*" # cp31?t: free-threaded, no limited API # Smoke-test every wheel: it must import, estimate, and report how the # optimiser terminated. NOT the golden battery — exact log-likelihoods are diff --git a/setup.py b/setup.py index 4ddeedc..3e20ac8 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ import importlib.util import os +import sysconfig from setuptools import setup @@ -37,9 +38,20 @@ def _cffi_extension(): # carry the engine (the binary wheels, a CI job): then it fails loudly # instead of dropping the engine with a warning (BUG-0022, BUG-0024). ext.optional = not os.environ.get("DRVARMA_REQUIRE_ENGINE") + # abi3 (BUG-0031): cffi already compiles against the limited API (the .pyd + # links python3.dll), so one wheel per platform serves every CPython from + # 3.10 on, the ones released after the wheel included. The wheels were + # per minor version and stopped at cp314; on 3.15 pip took the + # py3-none-any wheel and every fit ran on the port. A free-threaded + # build has no limited API: it keeps a version-specific extension. + ext.py_limited_api = _ABI3 return ext +# The limited API does not exist on a free-threaded CPython (3.13t, 3.14t...). +_ABI3 = not sysconfig.get_config_var("Py_GIL_DISABLED") + + def _sync_material(): """Copy bugs/ into the package (tools/sync_material.py) when building from a checkout. The copy is generated and ignored by git, so without this an @@ -69,4 +81,7 @@ def _sync_material(): raise print("drvarma: skipping C engine extension (%s); pure-Python install." % exc) -setup(ext_modules=ext_modules) +# The abi3 tag goes on the wheel only when it carries the extension: the pure +# wheel stays py3-none-any, the port for every platform without a binary. +options = {"bdist_wheel": {"py_limited_api": "cp310"}} if ext_modules and _ABI3 else {} +setup(ext_modules=ext_modules, options=options) diff --git a/src/drvarma/_engine.py b/src/drvarma/_engine.py index 9eb7c6e..025a7ce 100644 --- a/src/drvarma/_engine.py +++ b/src/drvarma/_engine.py @@ -30,6 +30,13 @@ def _load_c(): not caching keeps honest the tests that block the module to force the port. """ global _C_ERROR + # DRVARMA_NO_ENGINE asks for the port at EVERY entry point (BUG-0032): it + # was read only by estimate_w and engine_backend, so elf_c and marma_c -- + # the ladder's, and sima's -- went on computing in C while the backend + # answered "python". + if os.environ.get("DRVARMA_NO_ENGINE"): + _C_ERROR = "DRVARMA_NO_ENGINE is set (the port was asked for)" + return None try: from drvarma._drvarma_engine import ffi, lib except ImportError as e: @@ -42,8 +49,6 @@ def _load_c(): def engine_backend() -> str: """"c" when the compiled engine loads, "python" when drvarma falls back to the pure-Python port (or DRVARMA_NO_ENGINE asks for it).""" - if os.environ.get("DRVARMA_NO_ENGINE"): - return "python" return "c" if _load_c() is not None else "python" @@ -83,12 +88,9 @@ def estimate_w(w, p, q, include_mean=False, # Runtime opt-out: DRVARMA_NO_ENGINE forces the pure-Python estimator (e.g. to # dodge a C-engine issue) without rebuilding. Otherwise use the C engine if # built, falling back to pure-Python when it is not. - c = None - if not os.environ.get("DRVARMA_NO_ENGINE"): - c = _load_c() - if c is None: - _warn_python_fallback() + c = _load_c() if c is None: + _warn_python_fallback() from .estimate_py import estimate_w_py return estimate_w_py(w, p, q, include_mean=include_mean, diag_ar=diag_ar, diag_ma=diag_ma, diag_cov=diag_cov, diff --git a/tests/test_bug_0032_no_engine_en_todas.py b/tests/test_bug_0032_no_engine_en_todas.py new file mode 100644 index 0000000..db4af62 --- /dev/null +++ b/tests/test_bug_0032_no_engine_en_todas.py @@ -0,0 +1,37 @@ +"""BUG-0032: DRVARMA_NO_ENGINE asks for the port at every entry point, not only +in estimate_w: elf_c and marma_c (the ladder's, and sima's) computed in C while +engine_backend() answered "python".""" +import numpy as np +import pytest + +import drvarma +from drvarma import _engine, _as311 + + +def test_la_variable_llega_a_elf_c_y_marma_c(monkeypatch): + m, n, p = 2, 60, 1 + w = np.random.default_rng(32).normal(size=(n, m)) + phi = np.full((p, m, m), 0.05) + called = [] + real = _as311.elf + + def spy(*a, **k): + called.append("port") + return real(*a, **k) + + monkeypatch.setattr(_as311, "elf", spy) + monkeypatch.setenv("DRVARMA_NO_ENGINE", "1") + assert drvarma.engine_backend() == "python" + assert "DRVARMA_NO_ENGINE" in drvarma.engine_load_error() + _engine.elf_c(m, n, p, 0, np.zeros(m), phi, np.zeros((0, m, m)), np.eye(m), w) + assert called == ["port"] + lg, *_ = _engine.marma_c(m, n, p, 0, np.zeros(m), phi, np.zeros((0, m, m)), + np.eye(m), w) + assert np.isfinite(lg) + + +def test_sin_la_variable_elf_c_usa_el_motor(monkeypatch): + pytest.importorskip("drvarma._drvarma_engine") + monkeypatch.delenv("DRVARMA_NO_ENGINE", raising=False) + assert drvarma.engine_backend() == "c" + assert drvarma.engine_load_error() is None