Skip to content

Commit

Permalink
Updated CI workflows to avoid race conditions on PRs with concurrency…
Browse files Browse the repository at this point in the history
… label (#778)

**Context:**
Currently there exists a race condition within the CI due to
misconfiguration of the concurrency label.

This PR updates the affected workflows to fix the concurrency labels.


**Description of the Change:**
`${{ github.event }}` is not a string, but rather an object, when you
have that in the concurrency label you get:

```yaml
# Label
group: my-workflow-${{ github.event }}-${{ github.ref }}

# Renders as
group: my-workflow-[object Object]-refs/heads/my-branch
```

This was causing workflows that had `pull_request` and `workflow_call`
triggers to overstep on each other's runtime as they both rendered with
the same concurrency label.

This PR changes the attribute to use the correct string name
`event_name`.

```yaml
# Label
group: my-workflow-${{ github.event_name }}-${{ github.ref }}

# Renders as
group: my-workflow-pull_request-refs/heads/my-branch
```

**Benefits:**
Race conditions averted. No random job cancellations especially when PR
needs wheels built.

**Possible Drawbacks:**
None.

**Related GitHub Issues:**
None.
[sc-66955](https://app.shortcut.com/xanaduai/story/66955/fix-bug-in-lightning-ci-causing-race-conditions-of-parallel-job-runs)

---------

Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: AmintorDusko <[email protected]>
Co-authored-by: Ali Asadi <[email protected]>
  • Loading branch information
4 people authored Jul 3, 2024
1 parent 3d6db7a commit 45bc864
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

### Improvements

* Updated concurrency labels for tests ensuring different workflows do not run under the same concurrency group label
[(#778)](https://github.com/PennyLaneAI/pennylane-lightning/pull/778)

* Release candidate branches are automatically switched over to using the new large GitHub runner pool.
[(#769)](https://github.com/PennyLaneAI/pennylane-lightning/pull/769)

Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/tests_lgpu_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ env:
TORCH_VERSION: 1.11.0+cpu

concurrency:
group: tests_lgpu_cpp-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lgpu_cpp-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -108,6 +108,11 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
# Adding venv site-packages to output for subsequent step to referecen if needed
echo "site_packages_dir=$(${{ env.VENV_NAME }}/bin/python -c 'import sysconfig; print(sysconfig.get_path("platlib"))')" >> $GITHUB_OUTPUT
- name: Display Python-Path
id: python_path
Expand All @@ -116,14 +121,14 @@ jobs:
echo "Python Interpreter Path => $py_path"
echo "python=$py_path" >> $GITHUB_OUTPUT
pip_path=$(which python)
pip_path=$(which pip)
echo "PIP Path => $pip_path"
echo "pip=$pip_path" >> $GITHUB_OUTPUT
- name: Install required packages
run: |
python -m pip install ninja cmake custatevec-cu${{ matrix.cuda_version }}
sudo apt-get -y -q install liblapack-dev
python -m pip install ninja cmake custatevec-cu${{ matrix.cuda_version }} scipy
sudo apt-get -y -q install liblapack-dev black
- name: Build and run unit tests
run: |
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/tests_lgpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ env:
TORCH_VERSION: 1.11.0+cpu

concurrency:
group: tests_lgpu_python-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lgpu_python-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -128,6 +128,13 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
source ${{ env.VENV_NAME }}/bin/activate
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
# Adding venv site-packages to output for subsequent step to referecen if needed
echo "site_packages_dir=$(${{ env.VENV_NAME }}/bin/python -c 'import sysconfig; print(sysconfig.get_path("platlib"))')" >> $GITHUB_OUTPUT
- name: Display Python-Path
id: python_path
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests_lgpumpi_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env:
CI_CUDA_ARCH: 86

concurrency:
group: tests_lgpumpi_cpp-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lgpumpi_cpp-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -85,6 +85,8 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
- name: Display Python-Path
id: python_path
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests_lgpumpi_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ env:
CI_CUDA_ARCH: 86

concurrency:
group: tests_lgpumpi_python-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lgpumpi_python-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -90,6 +90,8 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
source ${{ env.VENV_NAME }}/bin/activate
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
- name: Display Python-Path
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_linux_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ env:
OMP_PROC_BIND: "false"

concurrency:
group: tests_linux_cpp-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_linux_cpp-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_lkcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ env:
OMP_PROC_BIND: "false"

concurrency:
group: tests_lkcpu_python-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lkcpu_python-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/tests_lkcuda_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env:
TORCH_VERSION: 1.11.0+cpu

concurrency:
group: tests_lkcuda_cpp-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lkcuda_cpp-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -153,6 +153,33 @@ jobs:
with:
python-version: '3.9'

# Since the self-hosted runner can be re-used. It is best to set up all package
# installations in a virtual environment that gets cleaned at the end of each workflow run
- name: Setup Python virtual environment
id: setup_venv
env:
VENV_NAME: ${{ github.workspace }}/venv_${{ steps.setup_python.outputs.python-version }}_${{ github.sha }}
run: |
# Clear any pre-existing venvs
rm -rf venv_*
# Create new venv for this workflow_run
python --version
python -m venv ${{ env.VENV_NAME }}
# Add the venv to PATH for subsequent steps
echo ${{ env.VENV_NAME }}/bin >> $GITHUB_PATH
# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
# Adding venv site-packages to output for subsequent step to referecen if needed
echo "site_packages_dir=$(${{ env.VENV_NAME }}/bin/python -c 'import sysconfig; print(sysconfig.get_path("platlib"))')" >> $GITHUB_OUTPUT
- name: Install dependencies
run: sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION ninja-build gcovr lcov

Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/tests_lkcuda_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:
TORCH_VERSION: 1.11.0+cpu

concurrency:
group: tests_lkcuda_python-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lkcuda_python-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -173,6 +173,33 @@ jobs:
with:
python-version: '3.9'

# Since the self-hosted runner can be re-used. It is best to set up all package
# installations in a virtual environment that gets cleaned at the end of each workflow run
- name: Setup Python virtual environment
id: setup_venv
env:
VENV_NAME: ${{ github.workspace }}/venv_${{ steps.setup_python.outputs.python-version }}_${{ github.sha }}
run: |
# Clear any pre-existing venvs
rm -rf venv_*
# Create new venv for this workflow_run
python --version
python -m venv ${{ env.VENV_NAME }}
# Add the venv to PATH for subsequent steps
echo ${{ env.VENV_NAME }}/bin >> $GITHUB_PATH
# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
# Adding venv site-packages to output for subsequent step to referecen if needed
echo "site_packages_dir=$(${{ env.VENV_NAME }}/bin/python -c 'import sysconfig; print(sysconfig.get_path("platlib"))')" >> $GITHUB_OUTPUT
- name: Install dependencies
run: sudo apt-get update && sudo apt-get -y -q install cmake gcc-$GCC_VERSION g++-$GCC_VERSION

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/tests_lmps_tncuda_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ env:
GCC_VERSION: 11

concurrency:
group: tests_lmps_tncuda_cpp-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
# TODO: Revert back to using event_name
group: tests_lmps_tncuda_cpp-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -115,6 +116,13 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
# Adding venv site-packages to output for subsequent step to referecen if needed
echo "site_packages_dir=$(${{ env.VENV_NAME }}/bin/python -c 'import sysconfig; print(sysconfig.get_path("platlib"))')" >> $GITHUB_OUTPUT
- name: Display Python-Path
id: python_path
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/tests_lmps_tncuda_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ env:
GCC_VERSION: 11

concurrency:
group: tests_lmps_tncuda_python-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lmps_tncuda_python-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -121,6 +121,12 @@ jobs:
# Adding venv name as an output for subsequent steps to reference if needed
source ${{ env.VENV_NAME }}/bin/activate
echo "venv_name=${{ env.VENV_NAME }}" >> $GITHUB_OUTPUT
echo "Python_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ env.VENV_NAME }}" >> $GITHUB_ENV
# Adding venv site-packages to output for subsequent step to referecen if needed
echo "site_packages_dir=$(${{ env.VENV_NAME }}/bin/python -c 'import sysconfig; print(sysconfig.get_path("platlib"))')" >> $GITHUB_OUTPUT
- name: Display Python-Path
id: python_path
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_lqcpu_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:
OMP_PROC_BIND: "false"

concurrency:
group: tests_lqcpu_python-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_lqcpu_python-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_windows_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
- '!pennylane_lightning/core/src/simulators/lightning_gpu/**'

concurrency:
group: tests_windows_cpp-${{ github.ref }}-${{ github.event }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_windows_cpp-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_without_binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
COVERAGE_FLAGS: "--cov=pennylane_lightning --cov-report=term-missing --cov-report=xml:./coverage.xml --no-flaky-report -p no:warnings --tb=native"

concurrency:
group: tests_without_binary-${{ github.ref }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
group: tests_without_binary-${{ github.ref }}-${{ github.event_name }}-${{ inputs.lightning-version }}-${{ inputs.pennylane-version }}
cancel-in-progress: true

jobs:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/update_dev_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true


jobs:
update-dev-version:
name: Update version for development branches
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.37.0-dev50"
__version__ = "0.37.0-dev51"

0 comments on commit 45bc864

Please sign in to comment.