Skip to content

Commit ce93e84

Browse files
authored
Merge pull request #817 from mhucka/mhucka-improve-cirq-ci
Improve cirq_compatibility.yaml
2 parents 605d282 + 0df6595 commit ce93e84

File tree

2 files changed

+164
-17
lines changed

2 files changed

+164
-17
lines changed

Diff for: .github/workflows/cirq_compatibility.yaml

+163-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,171 @@
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 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
41+
test --test_timeout=3000
242
343
on:
44+
# Nightly runs.
445
schedule:
5-
- cron: "0 0 * * *"
46+
- cron: 0 0 * * *
47+
# Manual on-demand invocations.
48+
workflow_dispatch:
49+
inputs:
50+
py_version:
51+
description: Version of Python to use
52+
bazel_version:
53+
description: Version of Bazel Python to use
54+
arch:
55+
description: Computer architecture to use
56+
use_bazel_disk_cache:
57+
description: Use Bazel disk_cache between runs?
58+
type: boolean
59+
default: true
60+
cache_bazel_tests:
61+
description: Allow Bazel to cache test results?
62+
type: boolean
63+
default: true
64+
save_artifacts:
65+
description: Make Bazel build outputs downloadable?
66+
type: boolean
67+
default: true
668

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

Diff for: scripts/test_all.sh

+1-1
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 -c opt --experimental_repo_remote_exec --test_output=errors --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --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)