Repository navigation
Description
On a Mac running macOS 27.0.1, sargent_surico stops partway through. Its gensys calls scipy.linalg.ordqz(g0, g1, output='complex', sort=...), and on one of the lecture's pencils that call raises:
ValueError: Reordering of (A, B) failed because the transformed matrix pair (A, B) would be too far from generalized Schur form; the problem is very ill-conditioned. (A, B) may have been partially reordered.
The cause looks to be Apple's Accelerate, which SciPy's default macOS arm64 wheel uses for LAPACK, rather than the lecture or the model. We found it while benchmarking the lecture, and we're opening this to investigate further.
What happens. In QuantEcon/benchmarks#25, the lecture was run three times on an Apple M6 with macOS 27.0.1. All three runs fail at the code cell that prints scaling tau and sigma_e together leaves h(0) untouched:, and 27 code cells fail from there on. The error comes from the lecture's 14th call to ordqz; the 13 calls before it succeed. The results are in lectures/results/qe-mini1/2026-11-02/lecture-python/sargent_surico/ in QuantEcon/benchmarks. The lecture on main today is the same file as the one run, at 087518ec0.
What we checked:
| Setting | Result |
|---|---|
| Apple M6, macOS 27.0.1, SciPy 1.18.1's default wheel (Accelerate), the lecture's environment | Fails |
| The same, in a fresh environment with SciPy, NumPy and pytest | Fails |
| The same Mac, SciPy 1.18.1's OpenBLAS wheel | Succeeds, with backward errors of about 1e-15 |
| Apple M5 Pro, macOS 26.7.1, the same packages as the M6, Accelerate | The whole lecture runs without an error |
The M6 under Accelerate, with output='real', or with qz(..., output='complex') without reordering |
Succeeds |
SciPy's own ordqz and qz tests (17) on the M6 under Accelerate |
All pass |
The failing pencil isn't close to the sort's boundary. Its generalized eigenvalues have moduli of 0.326, 0.578, 1.082, 1.273 (a complex pair), 1.771, 1.990, 5.578, 8.470 and ∞. The sort keeps |λ| > 1/1.01, and the nearest eigenvalue to that threshold is 9% away. So the problem itself doesn't look ill-conditioned, despite what the error says. The failure seems to be in the reordering step of Accelerate's LAPACK (ztgsen).
A standalone reproducer, with the failing pencil copied from the lecture:
import numpy as np, scipy
from scipy.linalg import ordqz
A_entries = {(0, 0): 1.0, (0, 1): -0.2603218874814671, (0, 4): 0.2846894038603883, (0, 8): -0.4622093966650994, (1, 1): 1.0, (1, 3): 0.24020924953894632, (1, 5): 0.043981731726475765, (1, 8): -0.24020924953894632, (1, 9): -0.6602304875700922, (2, 0): -1.0, (2, 1): -3.4742998268554066, (2, 2): 1.0, (2, 3): 0.8345589540822284, (2, 5): 0.8345589540822284, (2, 6): -0.8345589540822284, (2, 7): -1.0, (3, 2): 1.0, (4, 4): 1.0, (5, 5): 1.0, (6, 6): 1.0, (7, 7): 1.0, (8, 0): 1.0, (9, 1): 1.0}
B_entries = {(0, 0): 0.5278906033349006, (1, 1): 0.3397695124299078, (2, 1): -3.4742998268554066, (2, 3): 0.8345589540822284, (2, 5): 0.8345589540822284, (2, 6): -0.8345589540822284, (3, 2): 0.11806911267458574, (4, 4): 0.5645, (5, 5): 0.9241, (6, 6): 0.5024, (8, 8): 1.0, (9, 9): 1.0}
A, B = np.zeros((10, 10)), np.zeros((10, 10))
for (i, j), v in A_entries.items(): A[i, j] = v
for (i, j), v in B_entries.items(): B[i, j] = v
print("SciPy", scipy.__version__, scipy.show_config(mode="dicts")["Build Dependencies"]["lapack"]["name"])
S, T, alpha, beta, Q, Z = ordqz(A, B, output="complex", sort=lambda a, b: abs(b) < 1.01 * abs(a))
print("ok:", np.abs(Q @ S @ Z.conj().T - A).max(), np.abs(Q @ T @ Z.conj().T - B).max())On the M6, it prints SciPy 1.18.1 Accelerate and then raises the ValueError above. With the OpenBLAS wheel on the same Mac, it prints ok: and two residuals of about 1e-15. The OpenBLAS wheel was installed with uv pip install --python-platform aarch64-apple-darwin --only-binary :all: scipy==1.18.1, which picks SciPy's macosx_12_0 wheel. That is also a workaround for anyone who hits this.
Not yet known:
- macOS 27 or the M6: whether this is Accelerate on macOS 27 for every Mac, or only on the M6. Running the reproducer on an older Mac upgraded to macOS 27 would tell.
- SciPy or Apple: whether to report it to SciPy (which has passed Accelerate regressions to Apple before, as in BUG: large number of fails with macOS 15.1 using Accelerate scipy/scipy#21862), to Apple directly, or both. A SciPy report is drafted and waiting on the check above.
- What the lecture should do: whether it needs anything in the meantime, such as a note for Mac users, or a fallback in
gensys.
Environment of the failing runs:
| Machine | Apple M6 (Mac18,5), macOS 27.0.1 |
| Python | 3.12.15 |
| SciPy | 1.18.1, the default macOS arm64 wheel (LAPACK: Accelerate) |
| NumPy | 2.5.4 |
| JAX | 0.12.0.1, on the CPU, as the lecture pins it |
Activity
mmcky commentedon Nov 3, 2026
The reproducer runs cleanly on an older Mac on macOS 27.2. On an Apple M1 Pro (
MacBookPro18,3) with macOS 27.2 (26B123), SciPy 1.18.1's default wheel (Accelerate), NumPy 2.5.4 and Python 3.12.13, it prints:So it isn't Accelerate on macOS 27 for every Mac. That leaves two explanations this run can't separate: the M6, or macOS 27.0.1, with a fix by 27.2. The M6 that failed is still on 27.0.1, so the next step is to run the reproducer there once it is on 27.2. If it passes, upgrading macOS is the fix, and Mac users on 27.0.1 only need telling to upgrade. If it fails, the problem is the M6's, and the SciPy report goes ahead.
mmcky commentedon Nov 9, 2026
Update (2026-11-09): this was macOS 27.0.1's Accelerate, and macOS 27.2 behaves. We upgraded the same Apple M6 (
Mac18,5) to macOS 27.2 (26B123) and ran the reproducer above again, in a fresh environment with SciPy 1.18.1's default wheel (Accelerate), NumPy 2.5.4 and Python 3.12.15. It passes, three runs out of three:An Apple M1 Pro on macOS 27.2 (26B123) gave the same residuals on 2026-11-03. Only macOS changed on the M6, so the fault was in Accelerate on 27.0.1, not in the M6, the lecture or SciPy, and there's nothing to report to SciPy or Apple.
For the lecture: nothing needs to change. A Mac user on macOS 27.0.1 who hits the
ValueErrorcan upgrade to 27.2, or install SciPy's OpenBLAS wheel as described above. Unless we want a note for Mac users, this issue can be closed.mmcky commentedon Nov 9, 2026
Closing, as the comment above recommends: macOS 27.2 behaves, and the lecture needs no change. Mac users on 27.0.1 who hit the
ValueErrorcan upgrade to 27.2, or use SciPy's OpenBLAS wheel as the issue body describes.