Skip to content

Commit 0d750bc

Browse files
authored
Add support for TensorFlow 2.17 (#974)
Summary - Update TensorFlow Quantum build to support TensorFlow 2.17.1. - Align Eigen with TensorFlow 2.17.1’s pinned revision to fix Tensor/Tensor.h build incompatibility. - Define essential requirements in `requirements.in` and use `pip-compile` to produce `requirements.txt` Key changes - WORKSPACE: - bump `@org_tensorflow` to 2.17.1 - add lightweight alias repo (pypi_setuptools) to satisfy TF’s @pypi_setuptools reference when rules_python generates @pypi__setuptools. - `requirements.in`: - set of requirements needed for building TFQ and running test scripts - `requirements.txt` is produced by running `pip-compile --upgrade --generate-hashes -o requirements.txt requirements.in` Testing - Linux/Ubuntu 22.04 (Docker), Python 3.11, Bazelisk → Bazel 6.5.0 - `bazel build ... release:build_pip_package` succeeds - Unit tests (`scripts/test_all.sh` & `./scripts/ci_validate_tutorials.sh`) pass - Wheel installs and imports with TF 2.17.1 + tf-keras 2.17.0, Cirq 1.3.0, NumPy 1.26.4 Notes - This keeps TFQ on Keras 2 path; Keras 3 migration can be handled in a a future PR. - This changes will help on the incoming upgrades to 2.20.
1 parent 49d7294 commit 0d750bc

6 files changed

Lines changed: 1711 additions & 127 deletions

File tree

WORKSPACE

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
55

6+
local_repository(
7+
name = "pypi_setuptools",
8+
path = "third_party/pypi_setuptools",
9+
)
10+
611
# TensorFlow's .bzl files, loaded later in this file, also load rules_python
712
# but we need a slightly newer version that is still compatible with TF's.
813
http_archive(
@@ -39,11 +44,14 @@ load("@pypi//:requirements.bzl", "install_deps")
3944

4045
install_deps()
4146

42-
EIGEN_COMMIT = "aa6964bf3a34fd607837dd8123bc42465185c4f8"
47+
# Eigen commit used by TensorFlow / TFQ.
48+
# This commit corresponds to Eigen version 3.4.90
49+
# (verified via Eigen/src/Core/util/Macros.h).
50+
EIGEN_COMMIT = "c1d637433e3b3f9012b226c2c9125c494b470ae6"
4351

4452
http_archive(
4553
name = "eigen",
46-
sha256 = "35ba771e30c735a4215ed784d7e032086cf89fe6622dce4d793c45dd74373362",
54+
sha256 = "0992b93a590c39e196a9efdb5b4919fbf3fb485e7e656c6a87b21ddadb7f6ad2",
4755
build_file_content = """
4856
cc_library(
4957
name = "eigen3",
@@ -71,10 +79,10 @@ http_archive(
7179

7280
http_archive(
7381
name = "org_tensorflow",
74-
patches = ["//third_party/tf:tf.patch"],
75-
sha256 = "c8c8936e7b6156e669e08b3c388452bb973c1f41538149fce7ed4a4849c7a012",
76-
strip_prefix = "tensorflow-2.16.2",
77-
urls = ["https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.16.2.zip"],
82+
# patches = ["//third_party/tf:tf.patch"],
83+
sha256 = "75d63eab5c4b41a831e39e2e3795e1f9dcc247e8fcca11bf3f3e1a6ac35e55d0",
84+
strip_prefix = "tensorflow-2.17.1",
85+
urls = ["https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.17.1.zip"],
7886
)
7987

8088

release/setup.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,29 @@ def finalize_options(self):
4848
REQUIRED_PACKAGES = [
4949
"cirq-core==1.3.0",
5050
"cirq-google==1.3.0",
51-
"numpy<2.0",
52-
"protobuf==4.25.8",
53-
"scipy<=1.12.0",
5451
"sympy==1.14",
55-
"tf-keras~=2.16.0",
56-
52+
"tf-keras~=2.17.0",
5753
# The following are transitive dependencies that need to be constrained to
5854
# avoid incompatible versions or because some (e.g., contourpy 1.3.3)
5955
# require Python 3.11+ and we want to maintain Python 3.9 compatibility.
6056
# TODO: revisit after we reach compatibility with TensorFlow 2.19+.
61-
"contourpy<=1.3.0",
57+
"contourpy<=1.3.2",
6258
"h5py==3.10.0",
6359
"importlib_metadata<5",
64-
"jax<0.4.24",
65-
"jaxlib<0.4.24",
60+
"jax<=0.5",
6661
"matplotlib<3.10",
67-
"networkx<3.3",
68-
"pillow<=11.0",
62+
"numpy<2.0",
63+
"scipy<=1.12.0",
64+
# The following makes it easier to get the right version on Colab. Once
65+
# TFQ works with the latest version of TF, this may become unnecessary.
66+
"protobuf==4.25.8",
6967
]
7068

7169
# TF requirement is placed as an extras to avoid overwriting existing nightly TF
7270
# installations. Users can run "pip install tensorflow-quantum[and-tensorflow]"
7371
# to get everything in one go (or "pip install tensorflow tensorflow-quantum").
7472
EXTRA_PACKAGES = {}
75-
EXTRA_PACKAGES["and-tensorflow"] = ["tensorflow>=2.16,<2.17"]
73+
EXTRA_PACKAGES["and-tensorflow"] = ["tensorflow>=2.17,<2.18"]
7674
# "extras" was used before 0.7.4. Prefer "and-tensorflow" in 0.7.4+.
7775
EXTRA_PACKAGES["extras"] = EXTRA_PACKAGES["and-tensorflow"]
7876
# Add an alias in case people type an underscore instead of a dash.
@@ -119,10 +117,10 @@ def has_ext_modules(self):
119117
"Intended Audience :: Education",
120118
"Intended Audience :: Science/Research",
121119
"Programming Language :: Python :: 3",
122-
"Programming Language :: Python :: 3.9",
123120
"Programming Language :: Python :: 3.10",
124121
"Programming Language :: Python :: 3.11",
125122
"Programming Language :: Python :: 3.12",
123+
"Programming Language :: Python :: 3.13",
126124
"Topic :: Scientific/Engineering",
127125
"Topic :: Scientific/Engineering :: Artificial Intelligence",
128126
"Topic :: Scientific/Engineering :: Mathematics",

requirements.in

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
# scripts/generate_requirements.sh.
1919
cirq-core~=1.3.0
2020
cirq-google~=1.3.0
21-
tensorflow>=2.16,<2.17
22-
tf-keras~=2.16.0
21+
tensorflow>=2.17,<2.18
22+
keras==3.12.0
23+
tf-keras~=2.17.0
24+
setuptools==75.0.0
25+
wheel==0.44.0
26+
contourpy<=1.3.2
27+
networkx<=3.4.2
28+
scipy==1.15.3
2329

2430
# TODO: the next ones are not truly core requirements. A better place should be
2531
# found for them (long with others needed by scripts/*). They're here as a

0 commit comments

Comments
 (0)