Skip to content

Conversation

@psamanoelton
Copy link

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 selecting system/venv/conda Python; wire that interpreter through Bazel
  • Make wheel-build script honor chosen Python and include setuptools

Key changes

  • WORKSPACE: bump @org_tensorflow to 2.16.2, add a tiny @python local_repository shim
  • third_party/python_legacy/defs.bzl: export interpreter as a string (what TF’s local_config_python expects)
  • configure.sh: --python= flag; generate .tf_configure.bazelrc + .bazelrc + the python shim
  • .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.0

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 with
  • Wheel installs and imports with TF 2.16.2 + tf-keras 2.16.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.

@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
Copy link
Member

mhucka commented Nov 20, 2025

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).

I know we discussed this offline, but just to follow up here too for future reference:

The 0.7.4 in main is intended to be the next version. I'm not sure if this convention is different from what TensorFlow does, but the convention for TFQ has been that main on GitHub contains the working (i.e., in-development) version. When a release is made, that's the version that it gets, and immediately after the release, the version number is bumpted up. This indicates the next version being worked on.

For TFQ, since the last release was for 0.7.3, the version was bumped in main to 0.7.4 after the release, and no releases have happened since that one. So the next release is 0.7.4.

Based on the PR the version number was bumped to 0.7.4 after the last release, it looks like the version number was updated to 0.7.4 only in setup.py, and the version number in the file tensorflow_quantum/__init__.py was left at 0.7.2. I guess that must have been an oversight at the time. That would account for the discrepancy.

At some point in the future, I think we should change the numbering scheme to include .dev0 in the version number in main. The other projects like Cirq have adopted that convention. It makes it more clear what the version number in main means.

Options `--cxxopt=-D_GLIBCXX_USE_CXX11_ABI=1` and `--cxxopt=-std=c++17`
are written to the `.bazelrc` file by `configure.sh`. Consequently, they
are always in effect and don't need to be repeated in the various shell
scripts in `scripts/.`
`third_party/python_legacy` is generated by configure.sh and not meant
to be committed to git.
Using `set -e` ends up masking failures in command invocations inside
`$(...)` constructs.
All the files are autogenerated. To make that clear, it's probably best
to put a comment about "# AUTOGENERATED by configure.sh" in all of them
and not only in `defs.bzl`.
I've always the phrasing of that question confusing and misleading. (The
question is _really_ about GPU vs CPU, but it only asks about CPU and
does not say anything about the implications of replying with `n`.) We
may as well take this opportunity to try to make it more clear.
The fact that running `configure.sh` has always been another gotcha for
people. Since the file contents are being changed substantially, we may
as well take this opportunity to add a comment warning users the file
will be overwritten.
Some of the variables referenced in the file lacked the curly braces
that the style guides recommend.
The use of `readlink` led to getting the pyenv shim, which led to
failures during `bazel test` runs. Always asking Python for the path
seems to be a more robust strategy.
Running in an environment where the system Python interpreter is not the
desired one continued to be a problem in my tests. This updates
WORKSPACE to use a slightly newer version of the rules_python library
than what is installed by TensorFlow's various workspace files, and in
addition, to make it read the `requirements.txt` file.
The Python environment that Bazel sets up for `bazel test` lacked all
the dependencies needed. In addition, it's generally considered a good
practice to pin the versions of dependencies in order to get more
reproducible builds. TensorFlow has been using `pip-compile` and
`requirements_lock_X.Y.txt` files for this, where `X.Y` is the Python
version. This commit changes the TensorFlow Quantum scheme to be
similar: a `requirements.in` lists the essential requirements, and this
file is then processed by `pip-compile` to produce the final
`requirements.txt` by following the transitive dependencies.
This is necessary for the changes in WORKSPACE to work.
`.gitignore` should not ignore `.txt` files.
The `.tf_configure.bazelrc` file is another one generated at run time
and needs to be ignored by git.
After testing different combos on a couple of systems, I found that some
of the flags made no difference. (Guess: maybe the Bazel rules don't
propagate them down to external dependencies.) This removes those flags
as a matter of good practices.
Calling `setup.py` is deprecated these days. The simplest replacement is
to use the `build` package.
I must have left a `set -x` in here at some point.
Turns out that `pip show a b c` will return 0 if any of the packages are
found. This is not what we needed to happen.

Switching instead to simply calling `pip install -qq` is probably as
fast as anything else that involves testing and possibly installing a
missing dependency.
Turns out that, while `common` does work for both `build` and `test`, it
can be problematic for other Bazel commands.
The version 2 of wrapt led to a pip error on at least one platform.
Downgrading to 1.x solved it.
Changes:

* Adjust the way it extracts the shared library name to account for
  changes in what's written into the .bazelrc file.

* Avoid using `find / ...` in favor of finding out the location of the
  policy file more directly.

* Adjust quotes around values in the sed command.

* Use `|` as the sed pattern separator to make the command a little bit
  more easily readable, because I had some trouble parsing it due to the
  combination of many forward and backward slashes and quote marks.
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