From ab8f5d01eddf8bd773f9b3448f0c9274e6e780b5 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Thu, 1 Aug 2024 12:02:05 +0200 Subject: [PATCH 1/2] drop support for python-3.8 --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 4 +-- noxfile.py | 18 +++++++++--- pyproject.toml | 2 +- tests/test_cost.py | 53 +++++++++++++++++++++++++++++------ tests/test_issue.py | 5 +++- 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 800182e0..f7502ca5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,7 +42,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-13, macos-14] arch: [auto, aarch64] - py: [cp38, cp39, cp310, cp311, cp312] + py: [cp39, cp310, cp311, cp312] exclude: - os: windows-latest arch: aarch64 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 34d91d57..7597e72f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,10 +24,10 @@ jobs: python-version: "3.11" installs: "numpy>=2.0.0rc1" - os: macos-14 - python-version: "3.8" + python-version: "3.9" installs: "numpy==1.21.0 scipy matplotlib" - os: ubuntu-latest - python-version: "pypy-3.8" + python-version: "pypy-3.9" - os: ubuntu-latest python-version: "3.12" installs: "'numpy>=2.0.0rc1' scipy matplotlib" diff --git a/noxfile.py b/noxfile.py index f65b6df7..2d95046f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -15,6 +15,8 @@ "COVERAGE_CORE": "sysmon", # faster coverage on Python 3.12 } +nox.options.sessions = ["test", "mintest", "maxtest"] + @nox.session(reuse_venv=True) def test(session: nox.Session) -> None: @@ -23,14 +25,14 @@ def test(session: nox.Session) -> None: session.run("pytest", *session.posargs, env=ENV) -@nox.session(reuse_venv=True) -def np2test(session: nox.Session) -> None: +@nox.session(python="3.12", reuse_venv=True) +def maxtest(session: nox.Session) -> None: """Run the unit and regular tests.""" - session.install("-e.", "scipy", "pytest", "--pre") + session.install("-e.", "scipy", "matplotlib", "pytest", "--pre") session.run("pytest", *session.posargs, env=ENV) -@nox.session(venv_backend="uv") +@nox.session(python="3.9", venv_backend="uv") def mintest(session: nox.Session) -> None: """Run the unit and regular tests.""" session.install("-e.", "--resolution=lowest-direct") @@ -38,6 +40,14 @@ def mintest(session: nox.Session) -> None: session.run("pytest", *session.posargs) +@nox.session(python="pypy3.9", venv_backend="uv") +def pypy(session: nox.Session) -> None: + """Run the unit and regular tests.""" + session.install("-e.") + session.install("pytest") + session.run("pytest", *session.posargs) + + # Python-3.12 provides coverage info faster @nox.session(python="3.12", reuse_venv=True) def cov(session: nox.Session) -> None: diff --git a/pyproject.toml b/pyproject.toml index 2ab3b87d..9533edee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ maintainers = [ { email = "hans.dembinski@gmail.com" }, ] readme = "README.rst" -requires-python = ">=3.8" +requires-python = ">=3.9" license = { file = "LICENSE" } classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/tests/test_cost.py b/tests/test_cost.py index 78233e3a..96ac8f1c 100644 --- a/tests/test_cost.py +++ b/tests/test_cost.py @@ -1066,27 +1066,62 @@ def model(x, a, b): def test_LeastSquares_2D(): - x = np.array([1.0, 2.0, 3.0]) - y = np.array([4.0, 5.0, 6.0]) - z = 1.5 * x + 0.2 * y - ze = 1.5 - def model(xy, a, b): x, y = xy return a * x + b * y - c = LeastSquares((x, y), z, ze, model, grad=numerical_model_gradient(model)) + x = np.array([1.0, 2.0, 3.0]) + y = np.array([4.0, 5.0, 6.0]) + f = model((x, y), 1.5, 0.2) + fe = 1.5 + + c = LeastSquares((x, y), f, fe, model, grad=numerical_model_gradient(model)) assert c.ndata == 3 ref = numerical_cost_gradient(c) assert_allclose(c.grad(1, 2), ref(1, 2)) + assert_equal(c.x, (x, y)) + assert_equal(c.y, f) + assert_equal(c.yerror, fe) + assert_allclose(c(1.5, 0.2), 0.0) + assert_allclose(c(2.5, 0.2), np.sum(((f - 2.5 * x - 0.2 * y) / fe) ** 2)) + assert_allclose(c(1.5, 1.2), np.sum(((f - 1.5 * x - 1.2 * y) / fe) ** 2)) + + c.y = 2 * f + assert_equal(c.y, 2 * f) + c.x = (y, x) + assert_equal(c.x, (y, x)) + + +def test_LeastSquares_3D(): + def model(xyz, a, b): + x, y, z = xyz + return a * x + b * y + a * b * z + + x = np.array([1.0, 2.0, 3.0, 4.0]) + y = np.array([4.0, 5.0, 6.0, 7.0]) + z = np.array([7.0, 8.0, 9.0, 10.0]) + + f = model((x, y, z), 1.5, 0.2) + fe = 1.5 + + c = LeastSquares((x, y, z), f, fe, model, grad=numerical_model_gradient(model)) + assert c.ndata == 4 + + ref = numerical_cost_gradient(c) + assert_allclose(c.grad(1, 2), ref(1, 2)) + assert_equal(c.x, (x, y)) assert_equal(c.y, z) - assert_equal(c.yerror, ze) + assert_equal(c.yerror, fe) assert_allclose(c(1.5, 0.2), 0.0) - assert_allclose(c(2.5, 0.2), np.sum(((z - 2.5 * x - 0.2 * y) / ze) ** 2)) - assert_allclose(c(1.5, 1.2), np.sum(((z - 1.5 * x - 1.2 * y) / ze) ** 2)) + assert_allclose( + c(2.5, 0.2), np.sum(((f - 2.5 * x - 0.2 * y - 2.5 * 0.2 * z) / fe) ** 2) + ) + assert_allclose( + c(1.5, 1.2), np.sum(((f - 1.5 * x - 1.2 * y - 1.5 * 1.2 * z) / fe) ** 2) + ) c.y = 2 * z assert_equal(c.y, 2 * z) diff --git a/tests/test_issue.py b/tests/test_issue.py index 270f7c99..b2c3bccf 100644 --- a/tests/test_issue.py +++ b/tests/test_issue.py @@ -1,4 +1,5 @@ import numpy as np +import warnings def test_issue_424(): @@ -152,7 +153,9 @@ def model(x, sig_n, sig_mu, sig_sigma, bkg_n, bkg_tau): m = Minuit(nll, sig_n=33, sig_mu=ymu, sig_sigma=ysigma, bkg_n=66, bkg_tau=ytau) # with Simplex the fit never yields NaN, which is good but not what we want here - m.migrad(use_simplex=False) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RuntimeWarning) + m.migrad(use_simplex=False) if np.isnan(m.fmin.edm): assert not m.valid From b0ed4ad8ebf7b1d137f2483e33e4443a5c2f960c Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Thu, 1 Aug 2024 12:04:52 +0200 Subject: [PATCH 2/2] fix --- tests/test_cost.py | 53 ++++++++-------------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/tests/test_cost.py b/tests/test_cost.py index 96ac8f1c..78233e3a 100644 --- a/tests/test_cost.py +++ b/tests/test_cost.py @@ -1066,62 +1066,27 @@ def model(x, a, b): def test_LeastSquares_2D(): + x = np.array([1.0, 2.0, 3.0]) + y = np.array([4.0, 5.0, 6.0]) + z = 1.5 * x + 0.2 * y + ze = 1.5 + def model(xy, a, b): x, y = xy return a * x + b * y - x = np.array([1.0, 2.0, 3.0]) - y = np.array([4.0, 5.0, 6.0]) - f = model((x, y), 1.5, 0.2) - fe = 1.5 - - c = LeastSquares((x, y), f, fe, model, grad=numerical_model_gradient(model)) + c = LeastSquares((x, y), z, ze, model, grad=numerical_model_gradient(model)) assert c.ndata == 3 ref = numerical_cost_gradient(c) assert_allclose(c.grad(1, 2), ref(1, 2)) - assert_equal(c.x, (x, y)) - assert_equal(c.y, f) - assert_equal(c.yerror, fe) - assert_allclose(c(1.5, 0.2), 0.0) - assert_allclose(c(2.5, 0.2), np.sum(((f - 2.5 * x - 0.2 * y) / fe) ** 2)) - assert_allclose(c(1.5, 1.2), np.sum(((f - 1.5 * x - 1.2 * y) / fe) ** 2)) - - c.y = 2 * f - assert_equal(c.y, 2 * f) - c.x = (y, x) - assert_equal(c.x, (y, x)) - - -def test_LeastSquares_3D(): - def model(xyz, a, b): - x, y, z = xyz - return a * x + b * y + a * b * z - - x = np.array([1.0, 2.0, 3.0, 4.0]) - y = np.array([4.0, 5.0, 6.0, 7.0]) - z = np.array([7.0, 8.0, 9.0, 10.0]) - - f = model((x, y, z), 1.5, 0.2) - fe = 1.5 - - c = LeastSquares((x, y, z), f, fe, model, grad=numerical_model_gradient(model)) - assert c.ndata == 4 - - ref = numerical_cost_gradient(c) - assert_allclose(c.grad(1, 2), ref(1, 2)) - assert_equal(c.x, (x, y)) assert_equal(c.y, z) - assert_equal(c.yerror, fe) + assert_equal(c.yerror, ze) assert_allclose(c(1.5, 0.2), 0.0) - assert_allclose( - c(2.5, 0.2), np.sum(((f - 2.5 * x - 0.2 * y - 2.5 * 0.2 * z) / fe) ** 2) - ) - assert_allclose( - c(1.5, 1.2), np.sum(((f - 1.5 * x - 1.2 * y - 1.5 * 1.2 * z) / fe) ** 2) - ) + assert_allclose(c(2.5, 0.2), np.sum(((z - 2.5 * x - 0.2 * y) / ze) ** 2)) + assert_allclose(c(1.5, 1.2), np.sum(((z - 1.5 * x - 1.2 * y) / ze) ** 2)) c.y = 2 * z assert_equal(c.y, 2 * z)