Skip to content

Commit ede4124

Browse files
authored
Add manually-triggered debugging workflow (#6918)
* Add manually-triggered debugging workflow This workflow is designed to let you run pytest with various debugging options. It's meant to be executed manually using "Run workflow"on https://github.com/quantumlib/Cirq/actions/workflows/debug.yaml Clicking the "Run workflow" button there will make GitHub present a form interface with various options for the characteristics of the run. Options include: - give it a specific test to run (in the form of a path to a test file) - set the number of repetitions of the test - set the python version to use - set the random seed - turn on verbose logging This workflow was developed as an aid to debugging issue #6906, involving curve fitting that failed on occasion. This workflow is general and I think it will be useful for other debugging needs.
1 parent 84adca9 commit ede4124

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

.github/workflows/pytest-debug.yaml

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
# Summary: GitHub workflow for manually running pytest with debug flags.
3+
#
4+
# This workflow can only be executed manually, e.g., using the "Run workflow"
5+
# button on https://github.com/quantumlib/Cirq/actions/workflows/debug.yaml
6+
# Clicking the "Run workflow" button there will present a form interface with
7+
# various options for the characteristics of the run.
8+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
10+
name: Run pytest with debug options
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
py-version:
16+
description: "Python version:"
17+
type: choice
18+
default: "3.12"
19+
options:
20+
- "3.13"
21+
- "3.12"
22+
- "3.11"
23+
- "3.10"
24+
25+
os:
26+
description: "Runner OS:"
27+
type: choice
28+
default: ubuntu-20.04
29+
options:
30+
- ubuntu-22.04
31+
- ubuntu-20.04
32+
- macos-15
33+
- macos-14
34+
- macos-13
35+
- windows-2025
36+
- windows-2022
37+
- windows-2019
38+
39+
arch:
40+
description: "Hardware architecture:"
41+
type: choice
42+
default: x64
43+
options:
44+
- x64
45+
- arm64
46+
47+
single-test:
48+
description: "Run specific single test:"
49+
type: string
50+
default: ""
51+
52+
repetitions:
53+
description: "Number of repetitions:"
54+
type: number
55+
default: 1
56+
57+
random-seed:
58+
description: "Explicit random seed:"
59+
type: number
60+
61+
multiple-workers:
62+
description: "Use multiple pytest workers"
63+
type: boolean
64+
default: true
65+
66+
verbose:
67+
description: "Turn on verbose tracing"
68+
type: boolean
69+
default: false
70+
71+
exit-first:
72+
description: "Stop at first error"
73+
type: boolean
74+
default: true
75+
76+
include-rigetti:
77+
description: "Include rigetti module"
78+
type: boolean
79+
default: false
80+
81+
run-name: |
82+
Pytest ${{inputs.single-test || '(all tests)' }} on ${{inputs.os}}
83+
${{inputs.arch}} with Python ${{inputs.py-version}}
84+
85+
jobs:
86+
pytest:
87+
name: Run pytest
88+
runs-on: ${{github.event.inputs.os}}
89+
steps:
90+
- name: Do miscellaneous preliminary configuration steps
91+
run: |
92+
mkdir -p ~/.cache/pip
93+
94+
- name: Check out a copy of the Cirq git repository
95+
uses: actions/checkout@v4
96+
97+
- name: Set up Python
98+
uses: actions/setup-python@v5
99+
with:
100+
python-version: ${{github.event.inputs.py-version}}
101+
architecture: ${{github.event.inputs.arch}}
102+
cache: pip
103+
cache-dependency-path: |
104+
dev_tools/requirements/*.txt
105+
dev_tools/requirements/deps/*.txt
106+
107+
- name: Install Python requirements
108+
run: |
109+
set -e
110+
requirements="dev_tools/requirements/dev.env.txt"
111+
pip install --upgrade pip setuptools wheel
112+
pip install --upgrade --upgrade-strategy eager -r "$requirements"
113+
114+
- name: Start Quil dependencies if needed
115+
if: inputs.include-rigetti == true || inputs.include-rigetti == 'true'
116+
run: docker compose -f cirq-rigetti/docker-compose.test.yaml up -d
117+
118+
- name: Run pytest
119+
run: |
120+
# Configure flags for pytest.
121+
flags="--durations=20 --strict-config --ignore=cirq-core/cirq/contrib"
122+
workers="-n auto"
123+
if [[ -n "${{github.event.inputs.random-seed}}" ]]; then
124+
flags=" --randomly-seed=${{github.event.inputs.random-seed}}"
125+
fi
126+
if [[ "${{github.event.inputs.multiple-workers}}" == "false" ]]; then
127+
workers="-n0"
128+
fi
129+
if [[ "${{github.event.inputs.verbose}}" == "true" ]]; then
130+
flags+="-vv --full-trace --setup-show"
131+
# Save Python info to the run log, in case it's useful.
132+
which python
133+
pip list
134+
fi
135+
if [[ "${{github.event.inputs.include-rigetti}}" == true ]]; then
136+
flags+=" --rigetti-integration"
137+
fi
138+
if [[ "${{github.event.inputs.exit-first}}" == "true" ]]; then
139+
flags+=" --exitfirst"
140+
set -e
141+
fi
142+
# Now finally run pytest, as many times as requested.
143+
for i in $(seq 1 ${{github.event.inputs.repetitions}}); do
144+
echo ""
145+
echo -n "︎▞▚▞ Iteration $i ▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚"
146+
echo "▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞"
147+
echo ""
148+
check/pytest $workers $flags ${{github.event.inputs.single-test}}
149+
done
150+
151+
- name: Stop Quil dependencies if needed
152+
if: inputs.include-rigetti == true || inputs.include-rigetti == 'true'
153+
run: docker compose -f cirq-rigetti/docker-compose.test.yaml down

0 commit comments

Comments
 (0)