Skip to content

Conversation

@psamanoelton
Copy link

@psamanoelton psamanoelton commented Nov 7, 2025

Summary

  • Enable building TFQ against TensorFlow 2.16.2 with Bazel 6.5.x
  • Keep Keras 2 (tf-keras) path via TF_USE_LEGACY_KERAS=1 to avoid Keras 3 breakages
  • Allow choosing Python interpreter, whether from system, venv, or conda
  • Make wheel-build script honor chosen Python and include setuptools
  • Define essential requirements in requirements.in and use pip-compile to produce `requirements.txt

Key changes

  • WORKSPACE:
    • bump @org_tensorflow to 2.16.2
    • use newer rules_python Bazel rule set
    • use pip_parse and install_deps from rules_python to read requirements.txt and install dependencies
    • add tiny @python local_repository shim to set Python interpreter path
  • third_party/python_legacy/defs.bzl:
    • export interpreter as a string (what TF’s local_config_python expects)
  • configure.sh:
    • new --python= flag
    • write .tf_configure.bazelrc + .bazelrc + the Python shim
    • make .bazelrc also import .bazelrc.user if it exists
  • .bazelrc:
    • ensure TF_USE_LEGACY_KERAS=1 for build/test
    • keep existing warnings/rpath tweaks
  • release/build_pip_package.sh:
    • invoke ${PYTHON_BIN_PATH:-python3} and ensure setuptools present
  • setup.py:
    • (optionally) relax deps to run on TF 2.16 (sympy==1.14)
    • extras pin tensorflow>=2.16,<2.17
  • requirements.in:
    • set of requirements needed for building TFQ and running test scripts
    • requirements.txt is produced by running pip-compile --allow-unsafe
  • scripts/:
    • remove the following flags from bazel invocations because they are already set in .bazelrc
      • --cxxopt=-std=c++17
      • --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=1
      • --experimental_repo_remote_exec

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) pass
  • Wheel installs and imports with TF 2.16.2 + tf-keras 2.16.0, Cirq 1.3.0, NumPy 1.26.4

Miscellaneous

  • Run changed Python files through formatter

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.

@mhucka mhucka self-assigned this Nov 11, 2025
@mhucka mhucka added area/dependencies Involves libraries or other software that TFQ depends on area/health Involves general matters of project configuration, health, maintenance, and similar concerns area/installation Involves installation of TFQ area/tensorflow Involves TensorFlow labels Nov 11, 2025
Copy link
Member

@mhucka mhucka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work, and I'm sorry about the number of changes requested here …

psamanoelton and others added 9 commits November 18, 2025 11:07
Co-authored-by: Michael Hucka <mhucka@google.com>
Co-authored-by: Michael Hucka <mhucka@google.com>
Co-authored-by: Michael Hucka <mhucka@google.com>
Co-authored-by: Michael Hucka <mhucka@google.com>
Co-authored-by: Michael Hucka <mhucka@google.com>
Co-authored-by: Michael Hucka <mhucka@google.com>
Co-authored-by: Michael Hucka <mhucka@google.com>
@samanoelton
Copy link

About the version used here (0.7.5):

I put 0.7.5 because in the master branch in releases/setup.py:

CUR_VERSION = '0.7.4'

It was 0.7.4

As you mentioned the current version on PyPi is 0.7.3... I could patch releases/setup.py and tensorflow_quantum/init.py to match 0.7.4

(init has 0.7.2):

__version__ = '0.7.2'

And maybe this new version could be the tag 0.7.4 right?

Or maybe the current version that is in master is the unofficial version 0.7.4 and I should update it to 0.7.5? (to avoid losing 0.7.4 that is in master).

mhucka added 12 commits December 6, 2025 19:38
When `set -e` is used, the `|| exit` parts are unnecessary.
Inside Docker, the user is frequently root. Pip then complains that it's
a bad idea to run pip as root. This is irrelevant inside a Docker container.
This adds a dry run option so that unit tests can be written for these
scripts.

Also, I realized belately that I've been using the wrong indentation
settings for shell scripts for this project. TFQ and TF follow the
Google style convention of indent = 2, not 4.
These tests can be executed by running

```shell
bazel test //release:build_distribution_test
bazel test //release:clean_distribution_test
```

for individual tests, or just

```shell
bazel test //release:all
```

as part of testing everything.

These tests were written with the help of Gemini CLI.
Changes:

1. Add the ability to use `and-tensorflow` as the name of the extra to
   install TensorFlow. This follows a similar TF's `and-cuda` option,
   and lets users do `pip install tensorflow-quantum[and-tensorflow]` to
   get everything. My hope is that this is more intuitive and clear.
   (Conversely, the previous `pip install tensorflow-quantum[extras]`
   left me wondering what all the extras were.) The value `extras` still
   exists and can still be used, to avoid breaking existing workflows.

2. Add tf-keras version 2.16 to the required packages list. TensorFlow
   2.16 installs Keras 3 by default, and the user wasn't getting
   tf-keras unless they did it themselves. This way, installing TFQ will
   specify Keras 2.

3. Added a `python_requires` for version 3.10 or above, since that's our
   current cut-off due to constraints from the many dependencies needed.
mhucka added 13 commits December 8, 2025 23:01
Moving these scripts to a separate PR in order to avoid putting too many
things into the current PR.
These flags are redundant but also not something that necessarily has to
removed as part of this PR.
For things run manually, it should be okay to assume Bash and not limit
ourselves to POSIX shell features.
This also should be done in a separate PR
Delay removing the `.bazelrc` files until configure.sh is actually ready
to start writing a new one. That way, if the user ^C's in the middle of
configure.sh running, it's less likely to overwrite what they currently
have. (It happened to me: I realized I wanted to stop and check
something at the point when it asked for cpu vs gpu, but by then it was
too late: the .bazelrc file was gone.)
When output is redirected to logs and this script is invoked as part of
a larger script, printing an initial welcome message helps reading and
searchign the log.
Per Google guidance, executable scripts should use `/bin/bash`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dependencies Involves libraries or other software that TFQ depends on area/health Involves general matters of project configuration, health, maintenance, and similar concerns area/installation Involves installation of TFQ area/tensorflow Involves TensorFlow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants