Skip to content

Commit 47ed46a

Browse files
uri-grantast--Uri Granta
authored
Support TF 2.12 and numpy>=1.22 (#99)
Co-authored-by: ST John <st--@users.noreply.github.com> Co-authored-by: Uri Granta <uri.granta@secondmind.ai>
1 parent 3eeec8a commit 47ed46a

8 files changed

Lines changed: 55 additions & 10 deletions

File tree

.github/workflows/quality-check.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
python-version: ["3.7", "3.8", "3.9", "3.10"]
25-
tensorflow: ["~=2.5.0", "~=2.6.0", "~=2.7.0", "~=2.8.0", "~=2.9.0", "~=2.10.0", "~=2.11.0"]
25+
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"]
2626
include:
2727
- tensorflow: "~=2.5.0"
2828
keras: "~=2.6.0"
@@ -45,6 +45,9 @@ jobs:
4545
- tensorflow: "~=2.11.0"
4646
keras: "~=2.11.0"
4747
tensorflow-probability: "~=0.19.0"
48+
- tensorflow: "~=2.12.0"
49+
keras: "~=2.12.0"
50+
tensorflow-probability: "~=0.19.0" # sic! no new tfp release
4851
exclude:
4952
# These older versions of TensorFlow don't work with Python 3.10:
5053
- python-version: "3.10"
@@ -53,12 +56,16 @@ jobs:
5356
tensorflow: "~=2.6.0"
5457
- python-version: "3.10"
5558
tensorflow: "~=2.7.0"
59+
# These newer versions of TensorFlow don't work with Python 3.7:
60+
- python-version: "3.7"
61+
tensorflow: "~=2.12.0"
5662

5763
name: Python-${{ matrix.python-version }} tensorflow${{ matrix.tensorflow }}
5864
env:
5965
VERSION_TF: ${{ matrix.tensorflow }}
6066
VERSION_KERAS: ${{ matrix.keras }}
6167
VERSION_TFP: ${{ matrix.tensorflow-probability }}
68+
VERSION_PYTHON: ${{ matrix.python-version }}
6269
steps:
6370
- uses: actions/checkout@v3
6471
- uses: actions/setup-python@v4

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ LINT_FILE_IGNORES = "$(LIB_NAME)/__init__.py:F401,F403 \
2525
$(LIB_NAME)/sampling/__init__.py:F401 \
2626
$(LIB_NAME)/utils/__init__.py:F401"
2727

28+
# Python 3.7 uses a separate test requirements file
29+
ifeq ("$(VERSION_PYTHON)", "3.7")
30+
TEST_REQUIREMENTS = "tests_requirements_37.txt"
31+
else
32+
TEST_REQUIREMENTS = "tests_requirements.txt"
33+
endif
34+
2835

2936
help: ## Shows this help message
3037
# $(MAKEFILE_LIST) is set by make itself; the following parses the `target: ## help line` format and adds color highlighting
@@ -35,7 +42,7 @@ install: ## Install repo for developement
3542
@echo "\n=== pip install package with dev requirements =============="
3643
pip install --upgrade --upgrade-strategy eager \
3744
-r notebook_requirements.txt \
38-
-r tests_requirements.txt \
45+
-r $(TEST_REQUIREMENTS) \
3946
tensorflow${VERSION_TF} \
4047
keras${VERSION_KERAS} \
4148
tensorflow-probability${VERSION_TFP} \

gpflux/helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import inspect
2323
import warnings
2424
from dataclasses import fields
25-
from typing import List, Optional, Type, TypeVar, Union
25+
from typing import List, Optional, Type, TypeVar, Union, Any
2626

2727
import numpy as np
2828

@@ -261,7 +261,10 @@ def construct_gp_layer(
261261
T = TypeVar("T")
262262

263263

264-
def make_dataclass_from_class(dataclass: Type[T], instance: object, **updates: object) -> T:
264+
# HACK to get mypy to pass, should be (dataclass: Type[T], ...) -> T:
265+
# mypy said: gpflux/helpers.py:271: error: Argument 1 to "fields" has incompatible type "Type[T]";
266+
# expected "Union[DataclassInstance, Type[DataclassInstance]]" [arg-type]
267+
def make_dataclass_from_class(dataclass: Any, instance: object, **updates: object) -> Any:
265268
"""
266269
Take a regular object ``instance`` with a superset of fields for a
267270
:class:`dataclasses.dataclass` (``@dataclass``-decorated class), and return an

gpflux/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
#
1616
"""Adds __version__"""
1717

18-
__version__ = "0.4.1"
18+
__version__ = "0.4.2"

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"gpflow>=2.6.3",
1010
"numpy",
1111
"scipy",
12-
"tensorflow>=2.5.0,<2.12.0; platform_system!='Darwin' or platform_machine!='arm64'",
12+
"tensorflow>=2.5.0,<2.13.0; platform_system!='Darwin' or platform_machine!='arm64'",
1313
# NOTE: Support of Apple Silicon MacOS platforms is in an experimental mode
14-
"tensorflow-macos>=2.5.0,<2.12.0; platform_system=='Darwin' and platform_machine=='arm64'",
14+
"tensorflow-macos>=2.5.0,<2.13.0; platform_system=='Darwin' and platform_machine=='arm64'",
1515
# NOTE: once we require tensorflow-probability>=0.12, we can remove our custom deepcopy handling
1616
"tensorflow-probability>=0.13.0,<0.20.0",
1717
]

tests/gpflux/test_callbacks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def test_tensorboard_callback(tmp_path, model_and_loss, data, update_freq):
136136
"self_tracked_trackables[3].likelihood.variance",
137137
}
138138

139-
if Version(tf.__version__) < Version("2.8"):
139+
tf_version = Version(tf.__version__)
140+
if tf_version < Version("2.8") or tf_version >= Version("2.12"):
140141
if update_freq == "batch":
141142
expected_tags |= {
142143
"batch_loss",

tests_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ codecov
44
click==8.0.4
55
flake8==4.0.1
66
isort==5.10.1
7-
mypy==0.921
7+
mypy
88
pytest
99
pytest-cov
1010
pytest-random-order
1111
pytest-mock
1212

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

1717
tqdm
1818

tests_requirements_37.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Test requirements specific to Python 3.7
2+
3+
# Code quality tools:
4+
black==21.7b0
5+
codecov
6+
click==8.0.4
7+
flake8==4.0.1
8+
isort==5.10.1
9+
mypy
10+
pytest
11+
pytest-cov
12+
pytest-random-order
13+
pytest-mock
14+
15+
# For mypy stubs:
16+
types-Deprecated
17+
numpy<1.22.0 # Newer versions of numpy are not compatible with Python 3.7.
18+
19+
tqdm
20+
21+
# Notebook tests:
22+
jupytext
23+
nbformat
24+
nbconvert
25+
jupyter_client
26+
ipykernel
27+
tornado

0 commit comments

Comments
 (0)