Skip to content

Commit 5df3478

Browse files
committed
Enhance cirq_compatibility.yml
This refactors the entire workflow. Improvements: - Caches pip-downloaded Python packages - Uses a Bazel setup action that caches Bazel installations - Adds more debugging output - Adds a workflow_dispatch target to enable manual invocation - Adds options to manual invocation to control caching
1 parent 605d282 commit 5df3478

File tree

2 files changed

+169
-17
lines changed

2 files changed

+169
-17
lines changed
Lines changed: 168 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,176 @@
1-
name: Cirq Compatibility
1+
# Copyright 2024 The TensorFlow Quantum Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
# Summary: GitHub CI workflow for testing TFQ against Cirq releases
17+
#
18+
# This workflow is executed every night on a schedule. By default, this
19+
# workflow will save Bazel build artifacts if an error occurs during a run.
20+
#
21+
# For testing, this workflow can be invoked manually from the GitHub page at
22+
# https://github.com/tensorflow/quantum/actions/workflows/cirq_compatibility.yaml
23+
# Clicking the "Run workflow" button there will present a form interface with
24+
# options for overridding some of the parameters for the run.
25+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26+
27+
name: Cirq compatibility nightly tests
28+
29+
# Default values. These can be overridden when workflow dispatch is used.
30+
env:
31+
# Python version to test against.
32+
py_version: '3.10'
33+
# Bazel version. Note: this needs to match what is used in TF & TFQ.
34+
bazel_version: 6.5.0
35+
# Machine architecture.
36+
arch: x64
37+
# Additional .bazelrc options to use.
38+
bazelrc_additions: |
39+
common --announce_rc
40+
build --verbose_failures
241
342
on:
43+
# Nightly runs.
444
schedule:
5-
- cron: "0 0 * * *"
45+
- cron: 0 0 * * *
46+
# Manual on-demand invocations.
47+
workflow_dispatch:
48+
inputs:
49+
py_version:
50+
description: Version of Python to use
51+
bazel_version:
52+
description: Version of Bazel Python to use
53+
arch:
54+
description: Computer architecture to use
55+
use_bazel_disk_cache:
56+
description: Use Bazel disk_cache between runs?
57+
type: boolean
58+
default: true
59+
cache_bazel_tests:
60+
description: Allow Bazel to cache test results?
61+
type: boolean
62+
default: true
63+
save_artifacts:
64+
description: Make Bazel build outputs downloadable?
65+
type: boolean
66+
default: true
67+
pull_request:
68+
branches:
69+
- master
670

771
jobs:
8-
consistency:
9-
name: Nightly Compatibility
72+
test-compatibility:
73+
name: Run TFQ tests
1074
runs-on: ubuntu-20.04
1175
steps:
12-
- uses: actions/checkout@v1
13-
- uses: actions/setup-python@v1
76+
- name: Check out a copy of the TFQ git repository
77+
uses: actions/checkout@v4
78+
with:
79+
ref: ${{github.event.pull_request.head.ref}}
80+
repository: ${{github.event.pull_request.head.repo.full_name}}
81+
82+
- name: Set up Python
83+
id: python
84+
uses: actions/setup-python@v5
85+
with:
86+
python-version: ${{github.event.inputs.py_version || env.py_version}}
87+
architecture: ${{github.event.inputs.arch || env.arch}}
88+
cache: pip
89+
90+
- name: Install TensorFlow Quantum dependencies
91+
run: |
92+
pip install --upgrade pip setuptools wheel
93+
pip install -r requirements.txt
94+
95+
- name: Install the nightly build version of Cirq
96+
run: |
97+
pip install -U cirq --pre
98+
99+
- name: Configure Bazel options
100+
run: |
101+
# If we didn't get a cache hit on the installed Python environment,
102+
# something's changed, and we want to make sure to re-run all tests.
103+
if [[ "${{steps.python.outputs.cache-hit}}" == "true"
104+
&& "${{github.event.inputs.cache_bazel_tests}}" != "false" ]]; then
105+
echo "cache_bazel_tests=auto" >> "$GITHUB_ENV"
106+
else
107+
echo "cache_bazel_tests=no" >> "$GITHUB_ENV"
108+
fi
109+
# Use the disk cache unless told not to.
110+
if [[ "${{github.event.inputs.use_bazel_disk_cache}}" != "false" ]]; then
111+
echo "use_bazel_disk_cache=true" >> "$GITHUB_ENV"
112+
else
113+
echo "use_bazel_disk_cache=false" >> "$GITHUB_ENV"
114+
fi
115+
116+
- name: Set up Bazel with caching
117+
if: env.use_bazel_disk_cache == 'true'
118+
uses: bazel-contrib/[email protected]
119+
env:
120+
USE_BAZEL_VERSION: ${{github.event.inputs.bazel_version || env.bazel_version}}
121+
with:
122+
disk-cache: ${{github.workflow}}
123+
bazelisk-cache: true
124+
external-cache: true
125+
repository-cache: true
126+
bazelrc: |
127+
${{env.bazelrc_additions}}
128+
test --cache_test_results=${{env.cache_bazel_tests}}
129+
130+
- name: Set up Bazel without caching
131+
if: env.use_bazel_disk_cache == 'false'
132+
uses: bazel-contrib/[email protected]
133+
env:
134+
USE_BAZEL_VERSION: ${{github.event.inputs.bazel_version || env.bazel_version}}
135+
with:
136+
bazelrc: |
137+
${{env.bazelrc_additions}}
138+
test --cache_test_results=${{env.cache_bazel_tests}}
139+
140+
- name: Configure TFQ
141+
run: |
142+
set -x -e
143+
# Save information to the run log, in case it's needed for debugging.
144+
which python
145+
python --version
146+
python -c 'import site; print(site.getsitepackages())'
147+
python -c 'import tensorflow; print(tensorflow.version.VERSION)'
148+
python -c 'import cirq; print(cirq.__version__)'
149+
# Run the TFQ configuration script.
150+
printf "Y\n" | ./configure.sh
151+
152+
- name: Run TFQ unit tests
153+
# TODO: when the msan tests are working again, replace the "touch"
154+
# line with ./scripts/msan_test.sh 2>&1 | tee msan-tests-output.log
155+
run: |
156+
set -x -e
157+
./scripts/test_all.sh 2>&1 | tee unit-tests-output.log
158+
touch msan-tests-output.log
159+
160+
- name: Make Bazel artifacts downloadable (if desired)
161+
if: >-
162+
github.event.inputs.save_artifacts == 'true'
163+
&& (failure() || github.event_name == 'workflow_dispatch')
164+
uses: actions/upload-artifact@v4
14165
with:
15-
python-version: '3.8'
16-
architecture: 'x64'
17-
- name: Install Bazel on CI
18-
run: ./scripts/ci_install.sh
19-
- name: Configure CI TF
20-
run: echo "Y\n" | ./configure.sh
21-
- name: Install Cirq nightly
22-
run: pip install -U cirq --pre
23-
- name: Nightly tests
24-
run: ./scripts/test_all.sh
166+
name: bazel-out
167+
retention-days: 7
168+
include-hidden-files: true
169+
path: |
170+
unit-tests-output.log
171+
msan-tests-output.log
172+
/home/runner/.bazel/execroot/__main__/bazel-out/
173+
!/home/runner/.bazel/execroot/__main__/bazel-out/**/*.so
174+
!/home/runner/.bazel/execroot/__main__/bazel-out/**/*.o
175+
!/home/runner/.bazel/execroot/__main__/bazel-out/**/_objs
176+
!/home/runner/.bazel/execroot/__main__/bazel-out/**/_solib_k8

scripts/test_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616
echo "Testing All Bazel py_test and cc_tests.";
17-
test_outputs=$(bazel test -c opt --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --notest_keep_going --test_output=errors //tensorflow_quantum/...)
17+
test_outputs=$(bazel test --test_timeout=3000 --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" //tensorflow_quantum/...)
1818
exit_code=$?
1919
if [ "$exit_code" == "0" ]; then
2020
echo "Testing Complete!";

0 commit comments

Comments
 (0)