Skip to content

Commit

Permalink
Merge pull request #411 from rsokl/fix-nightly
Browse files Browse the repository at this point in the history
Improve test suite and CI
  • Loading branch information
rsokl authored Dec 29, 2022
2 parents 79b55fb + 4134ff3 commit de05821
Show file tree
Hide file tree
Showing 74 changed files with 342 additions and 210 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/docs/"
schedule:
interval: "weekly"
target-branch: "docs"
37 changes: 36 additions & 1 deletion .github/workflows/tox_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,29 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox
- name: Python 3.10
- name: Test with tox
run: tox -e py310

py311:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
fail-fast: false

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test with tox
run: tox -e py311

minimum_numpy:
runs-on: ubuntu-latest
strategy:
Expand All @@ -96,3 +116,18 @@ jobs:
pip install tox
- name: Test vs Minimum Python/Numpy
run: tox -e min_numpy

check-repo-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox -e enforce-format
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Documentation Status](https://readthedocs.org/projects/mygrad/badge/?version=latest)](https://mygrad.readthedocs.io/en/latest/?badge=latest)
[![Automated tests status](https://github.com/rsokl/MyGrad/workflows/Tests/badge.svg)](https://github.com/rsokl/MyGrad/actions?query=workflow%3ATests+branch%3Amaster)
[![PyPi version](https://img.shields.io/pypi/v/mygrad.svg)](https://pypi.python.org/pypi/mygrad)
![Python version support](https://img.shields.io/badge/python-3.7%20‐%203.10-blue.svg)
![Python version support](https://img.shields.io/badge/python-3.7%20‐%203.11-blue.svg)

# [MyGrad's Documentation](https://mygrad.readthedocs.io/en/latest/)

Expand Down
12 changes: 12 additions & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ This is a record of all past mygrad releases and what went into them,
in reverse chronological order. All previous releases should still be available
on pip.

.. _v2.2.0:

--------------------
2.2.0rc - 2022-XX-XX
--------------------

- MyGrad is now tested against Python 3.11. (:pull:`411`)
- `mygrad.bool8` has been removed. Use `mygrad.bool_` instead. (:pull:`411`)
- Adds ufunc support for `resolve_dtypes`. (:pull:`411`)
- Modifies automatic differentiation framework to be simpler and more memory efficient. In the future, MyGrad will be able to expose an API akin to `torch.autograd.grad <https://pytorch.org/docs/stable/generated/torch.autograd.grad.html>_`. (:pull:`407`)
- MyGrad's CI now enforces formatting and spell check requirements on all pull requests. (:pull:`411`)

.. _v2.1.0:

------------------
Expand Down
10 changes: 10 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None

_repo = "https://github.com/rsokl/MyGrad/"
extlinks = {
"commit": (_repo + "commit/%s", "commit %s"),
"gh-file": (_repo + "blob/master/%s", "%s"),
"gh-link": (_repo + "%s", "%s"),
"issue": (_repo + "issues/%s", "issue #%s"),
"pull": (_repo + "pull/%s", "pull request #%s"),
"plymi": ("https://www.pythonlikeyoumeanit.com/%s", "%s"),
"hydra": ("https://hydra.cc/docs/%s", "%s"),
}

# -- Options for HTML output -------------------------------------------------

Expand Down
45 changes: 37 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ line_length = 88
src_paths=src/mygrad,tests

[flake8]
exclude = docs/*, src/mygrad/__init__.py, src/mygrad/numpy_compat/__init__.py

extend-ignore = F811,D1,D205,D209,D213,D400,D401,D999,D202,E203,E501,W503,E721,F403,F405
exclude = .git,__pycache__,docs,old,build,dis,tests/annotations/*, tests/test_py310.py,versioneer.py,docs/*, src/mygrad/__init__.py, src/mygrad/numpy_compat/__init__.py,src/mygrad/nnet/__init__.py

[versioneer]
VCS = git
Expand All @@ -26,22 +26,28 @@ omit = src/mygrad/_version.py
src/mygrad/computational_graph.py


[codespell]
skip = *.po,*.ts,**/_version.py,
ignore-words-list = ND,nd,nin,dout

[tox:tox]
envlist = py37,py38,py39,format,min_numpy
envlist = py37,py38,py39,,format,min_numpy

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311

[testenv]
deps =
pytest
hypothesis
scipy
commands = pytest --hypothesis-profile ci \
pytest-xdist
commands = pytest -n auto --hypothesis-profile ci \
{posargs}
extras = rnn

Expand All @@ -50,15 +56,22 @@ extras = rnn
deps = numpy==1.20
{[testenv]deps}
basepython = python3.7
commands = pytest --hypothesis-profile ci \
commands = pytest -n auto --hypothesis-profile ci \
{posargs}
extras =

[testenv:py310] # exclude numba dependency for now
deps = pytest
pytest-xdist
hypothesis
scipy
commands = pytest --hypothesis-profile ci \
commands = pytest -n auto --hypothesis-profile ci \
{posargs}
extras =

[testenv:py311] # exclude numba dependency for now
deps = {[testenv:py310]deps}
commands = pytest -n auto --hypothesis-profile ci \
{posargs}
extras =

Expand All @@ -70,7 +83,7 @@ basepython = python3.7
deps = {[testenv]deps}
coverage
pytest-cov
commands = pytest --cov-report term-missing --cov-config=setup.cfg --cov-fail-under=100 --cov=mygrad tests
commands = pytest -n auto --cov-report term-missing --cov-config=setup.cfg --cov-fail-under=100 --cov=mygrad tests


[testenv:format]
Expand All @@ -89,7 +102,23 @@ pip_pre = true
deps = pytest
hypothesis
scipy
pytest-xdist
basepython = python3.8
commands = pytest --hypothesis-profile ci \
commands = pytest -n auto --hypothesis-profile ci \
{posargs}
extras =


[testenv:enforce-format]
skip_install=true
basepython=python3.9
deps=black
isort
flake8
pytest
codespell
commands=
black src/ tests/ --diff --check
isort src/ tests/ --diff --check
flake8 src/ tests/
codespell src/ docs/
2 changes: 1 addition & 1 deletion src/mygrad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from mygrad.tensor_manip.tiling.funcs import *
from mygrad.tensor_manip.transpose_like.funcs import *
from mygrad.ufuncs._ufunc_creators import ufunc
from ._io import load, save

from . import random
from ._io import load, save
from ._version import get_versions

__version__ = get_versions()["version"]
Expand Down
5 changes: 3 additions & 2 deletions src/mygrad/_dtype_mirrors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy

__all__ = [
"bool8",
"bool_",
"int8",
"int16",
"int32",
Expand All @@ -21,7 +21,8 @@
"longdouble",
]

bool8 = numpy.bool8

bool_ = numpy.bool_
int8 = numpy.int8
int16 = numpy.int16
int32 = numpy.int32
Expand Down
2 changes: 1 addition & 1 deletion src/mygrad/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if TYPE_CHECKING: # pragma: no cover
from mygrad import Tensor
from mygrad.operation_base import Operation
from mygrad.operation_base import Operation # noqa: F401

__all__ = [
"collect_all_operations_and_clear_grads",
Expand Down
4 changes: 2 additions & 2 deletions src/mygrad/_utils/duplicating_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __iter__(self) -> Iterator[Node]:
yield from self._yield_children(self.base.placeholder)

def get_path_to_base(self, tensor: "Tensor") -> List[Node]:
""" Returns [leaf, (parent), ..., base]"""
"""Returns [leaf, (parent), ..., base]"""
path = []
node = self[tensor]
while node.parent is not None:
Expand All @@ -201,7 +201,7 @@ def get_path_to_base(self, tensor: "Tensor") -> List[Node]:
return path

def restore_old_graph(self):
""" Reroute graph back to original tensors."""
"""Reroute graph back to original tensors."""
# call tuple to ensure iteration is completed
# before information gets deleted / mutated
for node in tuple(self):
Expand Down
2 changes: 1 addition & 1 deletion src/mygrad/_utils/graph_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Provides user interface for suspending computational graph tracking and back-propagation
"""
from functools import wraps
from typing import Callable, TypeVar, Any, cast, Optional
from typing import Any, Callable, TypeVar, cast

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion src/mygrad/computational_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def build_graph(


def _add_node(node, graph, op_id=None, **kwargs):
""" Recursively traces computational graph and adds nodes to Digraph. """
"""Recursively traces computational graph and adds nodes to Digraph."""
node_id = str(id(node))
node_lab = repr(node)
if kwargs["names"] is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/mygrad/linalg/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .funcs import norm
from .funcs import norm # noqa: F401
5 changes: 2 additions & 3 deletions src/mygrad/linalg/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
from numpy.core.einsumfunc import _parse_einsum_input

import mygrad as mg
from mygrad.math.misc.funcs import absolute
from mygrad.math.sequential.funcs import max as mg_max, min as mg_min
from mygrad.tensor_base import Tensor, implements_numpy_override
Expand Down Expand Up @@ -105,7 +104,7 @@ def norm(
References
----------
.. [1] Retrived from: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html
.. [1] Retrieved from: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html
.. [2] G. H. Golub and C. F. Van Loan, *Matrix Computations*,
Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15
Expand All @@ -118,7 +117,7 @@ def norm(
>>> l2_norms
Tensor([3.74165739, 1. ])
The presence of the elementwise absolute values in the norm operation means that zero-valued entries in any of
The presence of the elementwise absolute values in the norm operation means that zero-valued entries in any of
input vectors have an undefined derivative. When `nan_to_num=False` is specified these derivatives will be reported
as `nan`, otherwise they will be made to be 0.0.
Expand Down
2 changes: 1 addition & 1 deletion src/mygrad/linalg/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def backward_var(self, grad: np.ndarray, index: int, **kwargs) -> np.ndarray:
if out.size:
# if out.size is 0, then this produces div-by-zero
_norm = self._norm / np.sum(
out ** self.ord, axis=self.axis, keepdims=True
out**self.ord, axis=self.axis, keepdims=True
)
else:
_norm = +self._norm
Expand Down
8 changes: 4 additions & 4 deletions src/mygrad/math/arithmetic/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def backward_var(self, grad, index, **kwargs):
if index == 0: # backprop through a
return grad / b.data
else: # broadcast through b
return -grad * a.data / (b.data ** 2)
return -grad * a.data / (b.data**2)


class Power(BinaryUfunc):
Expand All @@ -73,7 +73,7 @@ def backward_var(self, grad, index, **kwargs):
if index == 0:
return grad * y * (x ** np.where(y, (y - 1), 1))
else:
return grad * (x ** y) * np.log(np.where(x, x, 1))
return grad * (x**y) * np.log(np.where(x, x, 1))


# Unary Ops
Expand All @@ -84,7 +84,7 @@ class Reciprocal(UnaryUfunc):

def backward_var(self, grad, index, **kwargs):
(a,) = self.variables
return -grad * np.reciprocal(a.data ** 2)
return -grad * np.reciprocal(a.data**2)


class Square(UnaryUfunc):
Expand Down Expand Up @@ -124,7 +124,7 @@ def backward_var(self, grad, index, **kwargs):


class MultiplySequence(Operation):
""" Performs f(a, b, ..., z) = a * b * ... * z"""
"""Performs f(a, b, ..., z) = a * b * ... * z"""

def __call__(self, *input_vars: "Tensor") -> np.ndarray:
self.variables = input_vars
Expand Down
Loading

0 comments on commit de05821

Please sign in to comment.