From 2c788f13f9ef7b5308e9337bb752b59af9a1c5df Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:02:04 +0530 Subject: [PATCH 01/12] Mark some TODOs; reword Ruff env description --- tox.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 848921c2..b2043666 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,8 @@ # Tox (https://tox.wiki/) - run tests in isolation using virtualenv. # Also contains config settings for tools that don't look into pyproject.toml. +# TODO: Migrate to tool.hatch.run or noxfile.py + [tox] envlist = ruff @@ -33,10 +35,10 @@ deps = pyclean commands = pyclean {posargs:. --debris --erase junit-report.xml --yes} [testenv:ruff] -description = Lightening-fast linting for Python +description = Lightning-fast linting for Python skip_install = true deps = ruff -commands = ruff {posargs:.} +commands = ruff check {posargs:.} # TODO: Fix style failures [testenv:package] description = Build package and check metadata (or upload package) From d782e83b7c76a8c0e57600afe953562338313292 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:02:38 +0530 Subject: [PATCH 02/12] Hatchling as build backend, add missing metadata --- pyproject.toml | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9bf24861..f1a6f2be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,11 @@ [build-system] -requires = ["setuptools>=44"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "autograd" version = "1.6.3" -description = "Efficiently computes derivatives of numpy code." +description = "Efficiently computes derivatives of NumPy code." readme = "README.md" license = {file = "license.txt"} authors = [ @@ -16,22 +16,20 @@ authors = [ ] maintainers = [ {name = "Jamie Townsend", email = "j.h.n.townsend@uva.nl"}, + {name = "Fabian Joswig", email = "fabian.joswig@uni-muenster.de"}, + {name = "Agriya Khetarpal", email = "agriyakhetarpal@outlook.com"}, ] classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering", ] keywords = [ "Automatic differentiation", @@ -41,14 +39,16 @@ keywords = [ "optimization", "neural networks", "Python", - "Numpy", - "Scipy", + "NumPy", + "SciPy", ] dependencies = [ "numpy>=1.12", - "six", - "future>=0.15.2; python_version < '3'", ] +# dynamic = ["version"] + +[project.urls] +Source = "https://github.com/HIPS/autograd" [project.optional-dependencies] scipy = [ @@ -69,12 +69,3 @@ extend-exclude = [] extend-ignore = ["E731"] extend-select = ["I", "W"] line-length = 109 - -[tool.setuptools] -packages=[ - "autograd", - "autograd.numpy", - "autograd.scipy", - "autograd.scipy.stats", - "autograd.misc", -] From f6fb8388d5634367e11aba4fa5ad6676a4bbde6a Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:03:20 +0530 Subject: [PATCH 03/12] Mark wheel as py3 and above, support Python 3.8+ --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index f1a6f2be..511c15e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ build-backend = "hatchling.build" [project] name = "autograd" version = "1.6.3" +requires-python = ">=3.8" description = "Efficiently computes derivatives of NumPy code." readme = "README.md" license = {file = "license.txt"} From 9eae62b0c85c2f2159df0278e30ecb4ea03f1b8d Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:10:37 +0530 Subject: [PATCH 04/12] Remove `setuptools`-specific files --- MANIFEST.in | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index a3e17ed3..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include autograd *.c *.h *.pyx -prune tests From 982788774ab4f2500c447775d4a418b9a2456370 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:12:22 +0530 Subject: [PATCH 05/12] Add hatch and friends, modernise build command --- conda_recipe/conda.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conda_recipe/conda.yaml b/conda_recipe/conda.yaml index b08a3565..a59acd1b 100644 --- a/conda_recipe/conda.yaml +++ b/conda_recipe/conda.yaml @@ -14,7 +14,8 @@ source: requirements: build: - python - - setuptools + - hatch + - hatchling - future - numpy >=1.9 @@ -24,7 +25,7 @@ requirements: - numpy >=1.9 build: - script: python setup.py build && python setup.py install + script: pip install . --no-deps test: # Python imports From 90013a134703bc8a3de288260bf8287f54ee1f73 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:34:55 +0530 Subject: [PATCH 06/12] Drop dependence on `six` --- autograd/builtins.py | 12 ++++++------ autograd/numpy/numpy_vjps.py | 3 +-- autograd/scipy/signal.py | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/autograd/builtins.py b/autograd/builtins.py index 39880fd5..bdc76327 100644 --- a/autograd/builtins.py +++ b/autograd/builtins.py @@ -1,4 +1,3 @@ -from six import with_metaclass from .util import subvals from .extend import (Box, primitive, notrace_primitive, VSpace, vspace, SparseObject, defvjp, defvjp_argnum, defjvp, defjvp_argnum) @@ -86,24 +85,25 @@ def fwd_grad_make_sequence(argnum, g, ans, seq_type, *args, **kwargs): defjvp_argnum(make_sequence, fwd_grad_make_sequence) -class TupleMeta(type_): +class TupleMeta(type(tuple_)): def __instancecheck__(self, instance): return isinstance(instance, tuple_) -class tuple(with_metaclass(TupleMeta, tuple_)): + +class tuple(tuple_, metaclass=TupleMeta): def __new__(cls, xs): return make_sequence(tuple_, *xs) class ListMeta(type_): def __instancecheck__(self, instance): return isinstance(instance, list_) -class list(with_metaclass(ListMeta, list_)): +class list(list_, metaclass=ListMeta): def __new__(cls, xs): - return make_sequence(list_, *xs) + return make_sequence(list_, *xs) class DictMeta(type_): def __instancecheck__(self, instance): return isinstance(instance, dict_) -class dict(with_metaclass(DictMeta, dict_)): +class dict(dict_, metaclass=DictMeta): def __new__(cls, *args, **kwargs): result = dict_(*args, **kwargs) if result: diff --git a/autograd/numpy/numpy_vjps.py b/autograd/numpy/numpy_vjps.py index 774afa92..ec7c040a 100644 --- a/autograd/numpy/numpy_vjps.py +++ b/autograd/numpy/numpy_vjps.py @@ -1,5 +1,4 @@ from __future__ import absolute_import -from six import string_types from functools import partial import numpy as onp from ..util import func @@ -588,7 +587,7 @@ def grad_einsum(argnum, ans, operands_, kwargs): result_meta = anp.metadata(operands_[argnum]) def vjp(g): operands = operands_ - if isinstance(operands[0], string_types): # using "ijk" convention. + if isinstance(operands[0], str): # using "ijk" convention. in_subs, out_subs, _ = anp.parse_einsum_input(*operands) string, operands = operands[0], operands[1:] diff --git a/autograd/scipy/signal.py b/autograd/scipy/signal.py index e1f0d650..bba53d84 100644 --- a/autograd/scipy/signal.py +++ b/autograd/scipy/signal.py @@ -6,7 +6,7 @@ from autograd.extend import primitive, defvjp from numpy.lib.stride_tricks import as_strided -from six import iteritems + @primitive def convolve(A, B, axes=None, dot_axes=[(),()], mode='full'): @@ -79,8 +79,8 @@ def parse_axes(A_shape, B_shape, conv_axes, dot_axes, mode): 'conv' : tuple(range(i2, i3))} conv_shape = (compute_conv_size(A_shape[i], B_shape[j], mode) for i, j in zip(axes['A']['conv'], axes['B']['conv'])) - shapes = {'A' : {s : (A_shape[i] for i in ax) for s, ax in iteritems(axes['A'])}, - 'B' : {s : (B_shape[i] for i in ax) for s, ax in iteritems(axes['B'])}} + shapes = {'A': {s: tuple(A_shape[i] for i in ax) for s, ax in axes['A'].items()}, + 'B': {s: tuple(B_shape[i] for i in ax) for s, ax in axes['B'].items()}} shapes['out'] = {'ignore_A' : shapes['A']['ignore'], 'ignore_B' : shapes['B']['ignore'], 'conv' : conv_shape} From da4f50fd4e7da2ef998faa953f7fd5cd046df388 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:35:05 +0530 Subject: [PATCH 07/12] Drop dependence on `future` --- examples/data_mnist.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/data_mnist.py b/examples/data_mnist.py index 21df35d8..375d72b5 100644 --- a/examples/data_mnist.py +++ b/examples/data_mnist.py @@ -1,9 +1,6 @@ from __future__ import absolute_import from __future__ import print_function import sys -if sys.version < "3": - from future.standard_library import install_aliases - install_aliases() import os import gzip From f47400c4fe06992428b1b6029ab6075e03701dca Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:36:03 +0530 Subject: [PATCH 08/12] Pin NumPy <2 to allow the tests to pass See #618 where this will be rebased to --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 511c15e7..8745ed35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ keywords = [ "SciPy", ] dependencies = [ - "numpy>=1.12", + "numpy<2", ] # dynamic = ["version"] From 198ab4209e940c0f9c0ebfee57fc40e252b7dc9a Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:04:38 +0530 Subject: [PATCH 09/12] Bump some GHA tools versions --- .github/workflows/check.yml | 4 ++-- .github/workflows/publish.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c39ae240..bd16a8f6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -22,8 +22,8 @@ jobs: #- ruff - package steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' - name: Install build tools diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9dd37a93..e9d8907c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,8 +13,8 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' - name: Install build tools diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8bc12439..512a9c63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,8 +30,8 @@ jobs: - pypy-3.9 - pypy-3.10 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install Python build tools From 8b53377e1793e6ad5f2162fac734390cf16848aa Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:09:15 +0530 Subject: [PATCH 10/12] Bump to `setup-python` v5.1.1 --- .github/workflows/check.yml | 2 +- .github/workflows/publish.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index bd16a8f6..84dd16f5 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -23,7 +23,7 @@ jobs: - package steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.1.1 with: python-version: '3.10' - name: Install build tools diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e9d8907c..2eb32fcb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.1.1 with: python-version: '3.10' - name: Install build tools diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 512a9c63..e819d69d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: - pypy-3.10 steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.1.1 with: python-version: ${{ matrix.python-version }} - name: Install Python build tools From db937a40264ef2ea6ac5220cdc9fdd2275c50075 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 30 Jul 2024 21:07:23 +0530 Subject: [PATCH 11/12] Preface command-line `tox` invocation with `python -m` --- .github/workflows/check.yml | 2 +- .github/workflows/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 84dd16f5..bdb5aa1c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -30,4 +30,4 @@ jobs: run: | python -m pip install tox wheel - name: Run ${{ matrix.env }} - run: tox -e ${{ matrix.env }} + run: python -m tox -e ${{ matrix.env }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e819d69d..7806412c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,10 +37,10 @@ jobs: - name: Install Python build tools run: python -m pip install tox wheel - name: Run tests - run: tox run -e py + run: python -m tox run -e py - name: Install Scipy prerequisites for Ubuntu if: startsWith(matrix.platform, 'ubuntu') run: sudo apt-get install libopenblas-dev - name: Run tests with scipy if: startsWith(matrix.platform, 'ubuntu') || startsWith(matrix.python-version, 'pypy') != true - run: tox run -e py-scipy + run: python -m tox run -e py-scipy From b8569e66ea16c650bfe53fda7d279138f92f1256 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 31 Jul 2024 00:31:38 +0530 Subject: [PATCH 12/12] Temporarily exclude PyPy3.10-Windows --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7806412c..3627af87 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,10 @@ jobs: - '3.12' - pypy-3.9 - pypy-3.10 + # TODO: bring this back later + exclude: + - platform: windows-latest + python-version: 'pypy-3.10' steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5.1.1