Skip to content

Commit

Permalink
Support TF 2.12 and numpy>=1.22 (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: ST John <[email protected]>
Co-authored-by: Uri Granta <[email protected]>
  • Loading branch information
3 people authored May 31, 2023
1 parent 3eeec8a commit 47ed46a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/quality-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
tensorflow: ["~=2.5.0", "~=2.6.0", "~=2.7.0", "~=2.8.0", "~=2.9.0", "~=2.10.0", "~=2.11.0"]
tensorflow: ["~=2.5.0", "~=2.6.0", "~=2.7.0", "~=2.8.0", "~=2.9.0", "~=2.10.0", "~=2.11.0", "~=2.12.0"]
include:
- tensorflow: "~=2.5.0"
keras: "~=2.6.0"
Expand All @@ -45,6 +45,9 @@ jobs:
- tensorflow: "~=2.11.0"
keras: "~=2.11.0"
tensorflow-probability: "~=0.19.0"
- tensorflow: "~=2.12.0"
keras: "~=2.12.0"
tensorflow-probability: "~=0.19.0" # sic! no new tfp release
exclude:
# These older versions of TensorFlow don't work with Python 3.10:
- python-version: "3.10"
Expand All @@ -53,12 +56,16 @@ jobs:
tensorflow: "~=2.6.0"
- python-version: "3.10"
tensorflow: "~=2.7.0"
# These newer versions of TensorFlow don't work with Python 3.7:
- python-version: "3.7"
tensorflow: "~=2.12.0"

name: Python-${{ matrix.python-version }} tensorflow${{ matrix.tensorflow }}
env:
VERSION_TF: ${{ matrix.tensorflow }}
VERSION_KERAS: ${{ matrix.keras }}
VERSION_TFP: ${{ matrix.tensorflow-probability }}
VERSION_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ LINT_FILE_IGNORES = "$(LIB_NAME)/__init__.py:F401,F403 \
$(LIB_NAME)/sampling/__init__.py:F401 \
$(LIB_NAME)/utils/__init__.py:F401"

# Python 3.7 uses a separate test requirements file
ifeq ("$(VERSION_PYTHON)", "3.7")
TEST_REQUIREMENTS = "tests_requirements_37.txt"
else
TEST_REQUIREMENTS = "tests_requirements.txt"
endif


help: ## Shows this help message
# $(MAKEFILE_LIST) is set by make itself; the following parses the `target: ## help line` format and adds color highlighting
Expand All @@ -35,7 +42,7 @@ install: ## Install repo for developement
@echo "\n=== pip install package with dev requirements =============="
pip install --upgrade --upgrade-strategy eager \
-r notebook_requirements.txt \
-r tests_requirements.txt \
-r $(TEST_REQUIREMENTS) \
tensorflow${VERSION_TF} \
keras${VERSION_KERAS} \
tensorflow-probability${VERSION_TFP} \
Expand Down
7 changes: 5 additions & 2 deletions gpflux/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import inspect
import warnings
from dataclasses import fields
from typing import List, Optional, Type, TypeVar, Union
from typing import List, Optional, Type, TypeVar, Union, Any

import numpy as np

Expand Down Expand Up @@ -261,7 +261,10 @@ def construct_gp_layer(
T = TypeVar("T")


def make_dataclass_from_class(dataclass: Type[T], instance: object, **updates: object) -> T:
# HACK to get mypy to pass, should be (dataclass: Type[T], ...) -> T:
# mypy said: gpflux/helpers.py:271: error: Argument 1 to "fields" has incompatible type "Type[T]";
# expected "Union[DataclassInstance, Type[DataclassInstance]]" [arg-type]
def make_dataclass_from_class(dataclass: Any, instance: object, **updates: object) -> Any:
"""
Take a regular object ``instance`` with a superset of fields for a
:class:`dataclasses.dataclass` (``@dataclass``-decorated class), and return an
Expand Down
2 changes: 1 addition & 1 deletion gpflux/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#
"""Adds __version__"""

__version__ = "0.4.1"
__version__ = "0.4.2"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"gpflow>=2.6.3",
"numpy",
"scipy",
"tensorflow>=2.5.0,<2.12.0; platform_system!='Darwin' or platform_machine!='arm64'",
"tensorflow>=2.5.0,<2.13.0; platform_system!='Darwin' or platform_machine!='arm64'",
# NOTE: Support of Apple Silicon MacOS platforms is in an experimental mode
"tensorflow-macos>=2.5.0,<2.12.0; platform_system=='Darwin' and platform_machine=='arm64'",
"tensorflow-macos>=2.5.0,<2.13.0; platform_system=='Darwin' and platform_machine=='arm64'",
# NOTE: once we require tensorflow-probability>=0.12, we can remove our custom deepcopy handling
"tensorflow-probability>=0.13.0,<0.20.0",
]
Expand Down
3 changes: 2 additions & 1 deletion tests/gpflux/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def test_tensorboard_callback(tmp_path, model_and_loss, data, update_freq):
"self_tracked_trackables[3].likelihood.variance",
}

if Version(tf.__version__) < Version("2.8"):
tf_version = Version(tf.__version__)
if tf_version < Version("2.8") or tf_version >= Version("2.12"):
if update_freq == "batch":
expected_tags |= {
"batch_loss",
Expand Down
4 changes: 2 additions & 2 deletions tests_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ codecov
click==8.0.4
flake8==4.0.1
isort==5.10.1
mypy==0.921
mypy
pytest
pytest-cov
pytest-random-order
pytest-mock

# For mypy stubs:
types-Deprecated
numpy<1.22.0 # Newer versions of numpy are not compatible with Python 3.7.
numpy

tqdm

Expand Down
27 changes: 27 additions & 0 deletions tests_requirements_37.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Test requirements specific to Python 3.7

# Code quality tools:
black==21.7b0
codecov
click==8.0.4
flake8==4.0.1
isort==5.10.1
mypy
pytest
pytest-cov
pytest-random-order
pytest-mock

# For mypy stubs:
types-Deprecated
numpy<1.22.0 # Newer versions of numpy are not compatible with Python 3.7.

tqdm

# Notebook tests:
jupytext
nbformat
nbconvert
jupyter_client
ipykernel
tornado

0 comments on commit 47ed46a

Please sign in to comment.