Repository navigation
Conversation
Enable building, testing, and packaging TensorFlow Quantum on macOS
(Apple Silicon / arm64) with TensorFlow 2.19.1:
- configure.sh & third_party/tf/:
- Detect `libtensorflow_framework*.dylib` on Darwin and configure
`@local_config_tf//:libtensorflow_framework` to output
`libtensorflow_framework.dylib` on macOS.
- Guard Linux-only `libstdc++` ABI and GCC warning flags (`-Wno-stringop-overflow`,
`-Wno-maybe-uninitialized`) on macOS.
- Add macOS Bazel flags (`--macos_minimum_os=12.0`, `--host_cxxopt=-std=c++17`,
`-DGRPC_BAZEL_BUILD`, `-Wl,-undefined,dynamic_lookup`, and `@loader_path`
rpaths to `tensorflow`).
- Enforce CPU build (`TF_NEED_CUDA=0`) when configuring on macOS.
- Packaging & custom op loading:
- Update `release/build_pip_package.sh` to dereference Bazel runfiles symlinks
portably on BSD/macOS `cp` (`-LR`), avoid clobbering the macOS `TMPDIR`
environment variable, and normalize relative destination paths.
- Replace removed-in-3.12 `distutils.sysconfig.get_python_lib` with stdlib
`sysconfig.get_path("platlib")` in `tensorflow_quantum/core/ops/load_module.py`.
- Add native macOS build and `delocate-wheel` repair paths to
`release/build_distribution.sh`, `release/clean_distribution.sh`, and
`release/build_release.sh`.
- CI & scripts:
- Update `scripts/ci_install.sh` to install Bazel 6.5.0 on Darwin (`arm64`/`x86_64`).
- Guard x86-only `-msse2`/`-msse3`/`-msse4` flags behind `uname -m == x86_64` in
test and benchmark scripts.
- Add `macos-14` jobs to `.github/workflows/ci.yaml` and
`.github/workflows/ci-nightly-build-test.yaml`.
- Docs & metadata:
- Add macOS and Linux OS classifiers in `release/setup.py` and update
`README.md`, `docs/install.md`, and `release/README.md`.
There was a problem hiding this comment.
Code Review
This pull request introduces support for building and running TensorFlow Quantum on macOS (Apple Silicon / arm64) alongside Linux. Key changes include updating the configuration scripts, Bazel build configurations, and distribution release scripts to support macOS-specific tools like delocate and .dylib shared libraries, as well as making compiler flags conditional on the CPU architecture. Additionally, deprecated distutils usage is replaced with sysconfig, and test tolerances are adjusted. Feedback on the changes suggests adding a trap in the pip package build script to ensure the temporary build directory is cleaned up if the script exits prematurely.
6f6b556 to
918d77f
Compare
|
Hi @mhucka @psamanoelton, this PR is ready for review. All Linux and macOS (macos-14 arm64) CI checks are passing. |
psamanoelton
left a comment
There was a problem hiding this comment.
Hello Vincenzo this looks very good! Thanks a lot!
To be sure help me solving few comments and help me checking also the /benchmarks, hope you can ensure if lines like this doesnt break on Apple Silicon and the scripts in the folder works too.
Note:
I am not too familiar with macOS, on ci you used macos-14, but this line says macOS 12.0+, one of my check on versions macos-14 is scheduled for removal Nov 2... it is great that this works on macOS 12.0+ but not sure if future changes will, and the CI will only check 14-15, checking older versions might get harder and we should say the version we do checks on the CI.
psamanoelton
left a comment
There was a problem hiding this comment.
Looks amazing! I added mhucka to also review it
Summary
Adds official build, wheel packaging, and GitHub Actions CI support for macOS (Apple Silicon /
arm64, macOS 12.0+) with TensorFlow 2.19.1:configure.sh,third_party/tf/tf_configure.bzl,third_party/tf/BUILD.tpl):libtensorflow_framework*.dylibon Darwin and configure@local_config_tf//:libtensorflow_frameworkto outputlibtensorflow_framework.dylibon macOS.libstdc++ABI (_GLIBCXX_USE_CXX11_ABI=1) and GCC-only warning flags (-Wno-stringop-overflow,-Wno-maybe-uninitialized) on macOS.--macos_minimum_os=12.0,--host_cxxopt=-std=c++17,-DGRPC_BAZEL_BUILD,-Wl,-undefined,dynamic_lookup, and@loader_pathrpaths to../tensorflow).TF_NEED_CUDA=0) on macOS.release/,tensorflow_quantum/core/ops/load_module.py):release/build_pip_package.shfor BSD/macOS compatibility (cp -LR, avoid clobbering systemTMPDIR, clean up temporary build directory on exit).distutils.sysconfig.get_python_lib(removed in Python 3.12) with standard librarysysconfig.get_path("platlib")intensorflow_quantum/core/ops/load_module.py.delocate-wheel(excludinglibtensorflow_framework.2.dylib) repair workflows torelease/build_distribution.sh,release/clean_distribution.sh, andrelease/build_release.sh..github/workflows/,scripts/,docs/):scripts/ci_install.shto install Bazel 6.5.0 on Darwin (arm64/x86_64) and guard x86-only-msse*flags behindx86_64checks.spin_system_test.pyfrom1e-6to2e-6to account forarm64FMA rounding differences.macos-14jobs (Python 3.10, 3.11, 3.12) to.github/workflows/ci.yamland.github/workflows/ci-nightly-build-test.yaml.release/setup.pyand documentation inREADME.md,docs/install.md, andrelease/README.md.Testing & Validation
scripts/format_check.sh) and linting (scripts/lint_all.sh).scripts/test_all.sh,scripts/build_pip_package_test.sh) across Linux (ubuntu-latest) and macOS (macos-14arm64, Python 3.10–3.12) in GitHub Actions CI.