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: 6 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 }}
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
69 changes: 69 additions & 0 deletions bench/velocidad_elf_port.py
Original file line number Diff line number Diff line change
@@ -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")
42 changes: 42 additions & 0 deletions bugs/BUG-0031-repro/repro.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading