From cdcf9028c1f12736c59f71e126f987be30323ddb Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 6 Sep 2026 21:14:39 +0400 Subject: [PATCH] Make the README's python fences runnable in document order The "Linear solver backends" snippet used `scs`, `data` and `cone` roughly 45 lines before anything defined them, so running the README's python fences in order failed with `NameError: name 'scs' is not defined`. It now sets up a minimal LP first. The Usage fence built `A` with an unseeded `sp.random` while its comment asserted the status would be 'solved'; seeded so the documented output is actually reproducible. Closes #239 Co-Authored-By: Claude Opus 5 (1M context) --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index db7073e7..df9b3627 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,18 @@ selects the best available solver for the platform: - **Linux / Windows**: MKL Pardiso if available, otherwise QDLDL ```python +import numpy as np +import scipy.sparse as sp +import scs + +# A minimal LP: maximize x subject to 0 <= x <= 1 +data = { + "A": sp.csc_matrix(np.array([[1.0], [-1.0]])), + "b": np.array([1.0, 0.0]), + "c": np.array([-1.0]), +} +cone = {"l": 2} + # Auto-detect best backend (default) solver = scs.SCS(data, cone) @@ -87,6 +99,8 @@ import numpy as np import scipy.sparse as sp import scs +np.random.seed(0) # so the printed status below is reproducible + m, n = 4, 2 A = sp.random(m, n, density=0.5, format="csc") b = np.random.randn(m)