From d064060850fe89c45f9f49a280b23a9abc40166b Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Fri, 3 Jan 2025 08:51:33 -0800 Subject: [PATCH 1/3] 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. --- .github/workflows/debugging.yaml | 150 +++++++++++++++++++++++++++ .github/workflows/pytest-debug.yaml | 153 ++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 .github/workflows/debugging.yaml create mode 100644 .github/workflows/pytest-debug.yaml diff --git a/.github/workflows/debugging.yaml b/.github/workflows/debugging.yaml new file mode 100644 index 00000000000..8357c67833b --- /dev/null +++ b/.github/workflows/debugging.yaml @@ -0,0 +1,150 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Summary: GitHub workflow for manually running pytest with debug flags. +# +# This workflow can only be executed manually, e.g., using the "Run workflow" +# button on https://github.com/quantumlib/Cirq/actions/workflows/debug.yaml +# Clicking the "Run workflow" button there will present a form interface with +# various options for the characteristics of the run. +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +name: Debug pytest + +on: + workflow_dispatch: + inputs: + py-version: + description: "Python version:" + type: choice + default: "3.12" + options: + - "3.13" + - "3.12" + - "3.11" + - "3.10" + + os: + description: "Runner OS:" + type: choice + default: ubuntu-20.04 + options: + - ubuntu-22.04 + - ubuntu-20.04 + - macos-15 + - macos-14 + - macos-13 + - windows-2025 + - windows-2022 + - windows-2019 + + arch: + description: "Hardware architecture:" + type: choice + default: x64 + options: + - x64 + - arm64 + + single-test: + description: "Run specific single test:" + type: string + default: "" + + repetitions: + description: "Number of repetitions:" + type: number + default: 1 + + random-seed: + description: "Explicit random seed:" + type: number + + multiple-workers: + description: "Use multiple pytest workers" + type: boolean + default: true + + verbose: + description: "Turn on verbose tracing" + type: boolean + default: false + + exit-first: + description: "Stop at first error" + type: boolean + default: true + + include-rigetti: + description: "Include rigetti module" + type: boolean + default: false + +run-name: | + Pytest ${{inputs.single-test || '(all tests)' }} on ${{inputs.os}} + ${{inputs.arch}} with Python ${{inputs.py-version}} + +jobs: + pytest: + name: Run pytest + runs-on: ${{github.event.inputs.os}} + steps: + - name: Do miscellaneous preliminary configuration steps + run: | + mkdir -p ~/.cache/pip + + - name: Check out a copy of the Cirq git repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{github.event.inputs.py-version}} + architecture: ${{github.event.inputs.arch}} + cache: pip + cache-dependency-path: | + dev_tools/requirements/*.txt + dev_tools/requirements/deps/*.txt + + - name: Install Python requirements + run: | + set -e + requirements="dev_tools/requirements/dev.env.txt" + pip install --upgrade pip setuptools wheel + pip install --upgrade --upgrade-strategy eager -r "$requirements" + + - name: Start Quil dependencies if needed + if: inputs.include-rigetti == true || inputs.include-rigetti == 'true' + run: docker compose -f cirq-rigetti/docker-compose.test.yaml up -d + + - name: Run pytest + run: | + # Common flags that used for all cases. + flags="--durations=20 --ignore=cirq-core/cirq/contrib" + workers="-n auto" + if [[ -n "${{github.event.inputs.random-seed}}" ]]; then + flags=" --randomly-seed=${{github.event.inputs.random-seed}}" + fi + if [[ "${{github.event.inputs.multiple-workers}}" == "false" ]]; then + workers="-n0" + fi + if [[ "${{github.event.inputs.verbose}}" == "true" ]]; then + flags+="-vv --trace-config --full-trace --setup-show" + # Save Python info to the run log, in case it's useful. + which python + pip list + fi + if [[ "${{github.event.inputs.include-rigetti}}" == true ]]; then + flags+=" --rigetti-integration" + fi + if [[ "${{github.event.inputs.exit-first}}" == "true" ]]; then + flags+=" --exitfirst" + set -e + fi + for i in $(seq 1 ${{github.event.inputs.repetitions}}); do + echo -n "︎▞▚▞ Iteration $i ▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚" + echo "▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞" + check/pytest $workers $flags ${{github.event.inputs.single-test}} + done + + - name: Stop Quil dependencies if needed + if: inputs.include-rigetti == true || inputs.include-rigetti == 'true' + run: docker compose -f cirq-rigetti/docker-compose.test.yaml down diff --git a/.github/workflows/pytest-debug.yaml b/.github/workflows/pytest-debug.yaml new file mode 100644 index 00000000000..96b73d78d3c --- /dev/null +++ b/.github/workflows/pytest-debug.yaml @@ -0,0 +1,153 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# Summary: GitHub workflow for manually running pytest with debug flags. +# +# This workflow can only be executed manually, e.g., using the "Run workflow" +# button on https://github.com/quantumlib/Cirq/actions/workflows/debug.yaml +# Clicking the "Run workflow" button there will present a form interface with +# various options for the characteristics of the run. +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +name: Run pytest with debug options + +on: + workflow_dispatch: + inputs: + py-version: + description: "Python version:" + type: choice + default: "3.12" + options: + - "3.13" + - "3.12" + - "3.11" + - "3.10" + + os: + description: "Runner OS:" + type: choice + default: ubuntu-20.04 + options: + - ubuntu-22.04 + - ubuntu-20.04 + - macos-15 + - macos-14 + - macos-13 + - windows-2025 + - windows-2022 + - windows-2019 + + arch: + description: "Hardware architecture:" + type: choice + default: x64 + options: + - x64 + - arm64 + + single-test: + description: "Run specific single test:" + type: string + default: "" + + repetitions: + description: "Number of repetitions:" + type: number + default: 1 + + random-seed: + description: "Explicit random seed:" + type: number + + multiple-workers: + description: "Use multiple pytest workers" + type: boolean + default: true + + verbose: + description: "Turn on verbose tracing" + type: boolean + default: false + + exit-first: + description: "Stop at first error" + type: boolean + default: true + + include-rigetti: + description: "Include rigetti module" + type: boolean + default: false + +run-name: | + Pytest ${{inputs.single-test || '(all tests)' }} on ${{inputs.os}} + ${{inputs.arch}} with Python ${{inputs.py-version}} + +jobs: + pytest: + name: Run pytest + runs-on: ${{github.event.inputs.os}} + steps: + - name: Do miscellaneous preliminary configuration steps + run: | + mkdir -p ~/.cache/pip + + - name: Check out a copy of the Cirq git repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{github.event.inputs.py-version}} + architecture: ${{github.event.inputs.arch}} + cache: pip + cache-dependency-path: | + dev_tools/requirements/*.txt + dev_tools/requirements/deps/*.txt + + - name: Install Python requirements + run: | + set -e + requirements="dev_tools/requirements/dev.env.txt" + pip install --upgrade pip setuptools wheel + pip install --upgrade --upgrade-strategy eager -r "$requirements" + + - name: Start Quil dependencies if needed + if: inputs.include-rigetti == true || inputs.include-rigetti == 'true' + run: docker compose -f cirq-rigetti/docker-compose.test.yaml up -d + + - name: Run pytest + run: | + # Configure flags for pytest. + flags="--durations=20 --ignore=cirq-core/cirq/contrib" + workers="-n auto" + if [[ -n "${{github.event.inputs.random-seed}}" ]]; then + flags=" --randomly-seed=${{github.event.inputs.random-seed}}" + fi + if [[ "${{github.event.inputs.multiple-workers}}" == "false" ]]; then + workers="-n0" + fi + if [[ "${{github.event.inputs.verbose}}" == "true" ]]; then + flags+="-vv --trace-config --full-trace --setup-show" + # Save Python info to the run log, in case it's useful. + which python + pip list + fi + if [[ "${{github.event.inputs.include-rigetti}}" == true ]]; then + flags+=" --rigetti-integration" + fi + if [[ "${{github.event.inputs.exit-first}}" == "true" ]]; then + flags+=" --exitfirst" + set -e + fi + # Now finally run pytest, as many times as requested. + for i in $(seq 1 ${{github.event.inputs.repetitions}}); do + echo "" + echo -n "︎▞▚▞ Iteration $i ▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚" + echo "▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞" + echo "" + check/pytest $workers $flags ${{github.event.inputs.single-test}} + done + + - name: Stop Quil dependencies if needed + if: inputs.include-rigetti == true || inputs.include-rigetti == 'true' + run: docker compose -f cirq-rigetti/docker-compose.test.yaml down From adb9fd417bfed35473e5cd9af8e0110b02476abb Mon Sep 17 00:00:00 2001 From: mhucka Date: Fri, 3 Jan 2025 18:16:40 -0800 Subject: [PATCH 2/3] Rename file --- .github/workflows/debugging.yaml | 150 ------------------------------- 1 file changed, 150 deletions(-) delete mode 100644 .github/workflows/debugging.yaml diff --git a/.github/workflows/debugging.yaml b/.github/workflows/debugging.yaml deleted file mode 100644 index 8357c67833b..00000000000 --- a/.github/workflows/debugging.yaml +++ /dev/null @@ -1,150 +0,0 @@ -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Summary: GitHub workflow for manually running pytest with debug flags. -# -# This workflow can only be executed manually, e.g., using the "Run workflow" -# button on https://github.com/quantumlib/Cirq/actions/workflows/debug.yaml -# Clicking the "Run workflow" button there will present a form interface with -# various options for the characteristics of the run. -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -name: Debug pytest - -on: - workflow_dispatch: - inputs: - py-version: - description: "Python version:" - type: choice - default: "3.12" - options: - - "3.13" - - "3.12" - - "3.11" - - "3.10" - - os: - description: "Runner OS:" - type: choice - default: ubuntu-20.04 - options: - - ubuntu-22.04 - - ubuntu-20.04 - - macos-15 - - macos-14 - - macos-13 - - windows-2025 - - windows-2022 - - windows-2019 - - arch: - description: "Hardware architecture:" - type: choice - default: x64 - options: - - x64 - - arm64 - - single-test: - description: "Run specific single test:" - type: string - default: "" - - repetitions: - description: "Number of repetitions:" - type: number - default: 1 - - random-seed: - description: "Explicit random seed:" - type: number - - multiple-workers: - description: "Use multiple pytest workers" - type: boolean - default: true - - verbose: - description: "Turn on verbose tracing" - type: boolean - default: false - - exit-first: - description: "Stop at first error" - type: boolean - default: true - - include-rigetti: - description: "Include rigetti module" - type: boolean - default: false - -run-name: | - Pytest ${{inputs.single-test || '(all tests)' }} on ${{inputs.os}} - ${{inputs.arch}} with Python ${{inputs.py-version}} - -jobs: - pytest: - name: Run pytest - runs-on: ${{github.event.inputs.os}} - steps: - - name: Do miscellaneous preliminary configuration steps - run: | - mkdir -p ~/.cache/pip - - - name: Check out a copy of the Cirq git repository - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: ${{github.event.inputs.py-version}} - architecture: ${{github.event.inputs.arch}} - cache: pip - cache-dependency-path: | - dev_tools/requirements/*.txt - dev_tools/requirements/deps/*.txt - - - name: Install Python requirements - run: | - set -e - requirements="dev_tools/requirements/dev.env.txt" - pip install --upgrade pip setuptools wheel - pip install --upgrade --upgrade-strategy eager -r "$requirements" - - - name: Start Quil dependencies if needed - if: inputs.include-rigetti == true || inputs.include-rigetti == 'true' - run: docker compose -f cirq-rigetti/docker-compose.test.yaml up -d - - - name: Run pytest - run: | - # Common flags that used for all cases. - flags="--durations=20 --ignore=cirq-core/cirq/contrib" - workers="-n auto" - if [[ -n "${{github.event.inputs.random-seed}}" ]]; then - flags=" --randomly-seed=${{github.event.inputs.random-seed}}" - fi - if [[ "${{github.event.inputs.multiple-workers}}" == "false" ]]; then - workers="-n0" - fi - if [[ "${{github.event.inputs.verbose}}" == "true" ]]; then - flags+="-vv --trace-config --full-trace --setup-show" - # Save Python info to the run log, in case it's useful. - which python - pip list - fi - if [[ "${{github.event.inputs.include-rigetti}}" == true ]]; then - flags+=" --rigetti-integration" - fi - if [[ "${{github.event.inputs.exit-first}}" == "true" ]]; then - flags+=" --exitfirst" - set -e - fi - for i in $(seq 1 ${{github.event.inputs.repetitions}}); do - echo -n "︎▞▚▞ Iteration $i ▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚" - echo "▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞▚▞" - check/pytest $workers $flags ${{github.event.inputs.single-test}} - done - - - name: Stop Quil dependencies if needed - if: inputs.include-rigetti == true || inputs.include-rigetti == 'true' - run: docker compose -f cirq-rigetti/docker-compose.test.yaml down From c817d111fdcaa06f8c85e70f53bf7ba5155bdd02 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Fri, 3 Jan 2025 20:28:58 -0800 Subject: [PATCH 3/3] Adjust pytest flags 1) Turns out `--trace-config` is not that useful. 2) Using `--strict-config` seems like a good idea. --- .github/workflows/pytest-debug.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest-debug.yaml b/.github/workflows/pytest-debug.yaml index 96b73d78d3c..649b40fc5ab 100644 --- a/.github/workflows/pytest-debug.yaml +++ b/.github/workflows/pytest-debug.yaml @@ -118,7 +118,7 @@ jobs: - name: Run pytest run: | # Configure flags for pytest. - flags="--durations=20 --ignore=cirq-core/cirq/contrib" + flags="--durations=20 --strict-config --ignore=cirq-core/cirq/contrib" workers="-n auto" if [[ -n "${{github.event.inputs.random-seed}}" ]]; then flags=" --randomly-seed=${{github.event.inputs.random-seed}}" @@ -127,7 +127,7 @@ jobs: workers="-n0" fi if [[ "${{github.event.inputs.verbose}}" == "true" ]]; then - flags+="-vv --trace-config --full-trace --setup-show" + flags+="-vv --full-trace --setup-show" # Save Python info to the run log, in case it's useful. which python pip list