Skip to content

Commit fb8c673

Browse files
rashidnhmmudit2812
andcommitted
Added ability to run linux workflows on large runners (#6273)
**Context:** Currently the CI gets congested when large amounts of pull requests are being updated simultaneously. This pull request gives PRs an escape hatch and use large runners and use different queue to have CI jobs be picked up. **Description of the Change:** This pull request adds two new features: - Ability to add the `urgent` label to any pull request and switch it over to large runners - Automatic swap of rc branch to large runner - This assumes the rc branch is of the format `vX.Y.Z-rcN` Large runners, albeit slightly more powerful than standard runners, can be spawned at a much higher volume than standard runners ... this is because we pay per minute for these runners vs being included on our GitHub Plan. If a PR needs CI run without waiting for a runner, **add the `urgent` label to the pull request**. Important Note: - This only affect jobs that run on `pull_request` and use `ubuntu` runners. - This change is already in-place in lightning and catalyst. - PennyLaneAI/pennylane-lightning#774 - PennyLaneAI/catalyst#846 **Benefits:** Ability to leverage large runner to have quick time for a runner to pick up a job. **Possible Drawbacks:** Though we dictate the pool size of large runners, it is possible to still saturate it. **Related GitHub Issues:** None. [sc-73711](https://app.shortcut.com/xanaduai/story/73711/update-pennylane-ci-to-use-large-runner-group) --------- Co-authored-by: Mudit Pandey <[email protected]>
1 parent 21074e6 commit fb8c673

6 files changed

+148
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Determine Workflow Runner group
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
default_runner:
7+
description: The runner type that is used by the calling workflow by default
8+
required: true
9+
type: string
10+
large_runner_group_name:
11+
description: The name of the runner group that should be used for large jobs
12+
required: false
13+
type: string
14+
default: 'pl-4-core-large-runner'
15+
force_large_runner:
16+
description: Whether to force the use of a large runner
17+
required: false
18+
type: boolean
19+
default: false
20+
outputs:
21+
runner_group:
22+
description: The runner all subsequent jobs within the calling workflow should run on
23+
value: >-
24+
${{
25+
jobs.determine_workflow_runner.outputs.runner_group ||
26+
(
27+
inputs.force_large_runner &&
28+
inputs.large_runner_group_name ||
29+
inputs.default_runner
30+
)
31+
}}
32+
33+
jobs:
34+
determine_workflow_runner:
35+
runs-on: >-
36+
${{
37+
(
38+
github.event_name == 'pull_request'
39+
&& contains(github.event.pull_request.labels.*.name, 'urgent')
40+
) && inputs.large_runner_group_name || 'ubuntu-latest'
41+
}}
42+
43+
outputs:
44+
runner_group: ${{ steps.runner_group.outputs.runner_group }}
45+
46+
steps:
47+
- name: Output Runner Group name
48+
if: >-
49+
${{
50+
github.event_name == 'pull_request'
51+
&& startsWith(inputs.default_runner, 'ubuntu')
52+
}}
53+
id: runner_group
54+
env:
55+
# We are not able to use \d to check numeric values as bash does not allow them (not POSIX compliant)
56+
RC_BRANCH_FORMAT_REGEX: v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]?
57+
REPO_FULL_NAME: PennyLaneAI/pennylane
58+
LARGE_RUNNER_GROUP_NAME: ${{ inputs.large_runner_group_name }}
59+
run: |
60+
if [[ '${{ contains(github.event.pull_request.labels.*.name, 'urgent') }}' == 'true' || ('${{ github.event.pull_request.head.repo.full_name }}' == "$REPO_FULL_NAME" && '${{ github.event.pull_request.base.ref }}' =~ $RC_BRANCH_FORMAT_REGEX) ]]; then
61+
echo "This job requires usage of the large runner group '$LARGE_RUNNER_GROUP_NAME'";
62+
echo "runner_group=$LARGE_RUNNER_GROUP_NAME" >> $GITHUB_OUTPUT
63+
else
64+
echo "This job does not require usage of large runners ...";
65+
fi

.github/workflows/docs.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ on:
2424
- ready_for_review
2525

2626
jobs:
27+
determine_runner:
28+
if: github.event.pull_request.draft == false
29+
name: Determine runner type to use
30+
uses: ./.github/workflows/determine-workflow-runner.yml
31+
with:
32+
default_runner: ubuntu-latest
33+
2734
sphinx:
2835
if: github.event.pull_request.draft == false
2936
env:
3037
DEPS_BRANCH: bot/stable-deps-update
31-
runs-on: ubuntu-latest
38+
needs: [determine_runner]
39+
runs-on: ${{ needs.determine_runner.outputs.runner_group }}
3240
steps:
3341
- uses: actions/checkout@v4
3442
- uses: PennyLaneAI/sphinx-action@master

.github/workflows/format.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15+
determine_runner:
16+
if: github.event.pull_request.draft == false
17+
name: Determine runner type to use
18+
uses: ./.github/workflows/determine-workflow-runner.yml
19+
with:
20+
default_runner: ubuntu-latest
21+
1522
black-pylint:
1623
if: github.event.pull_request.draft == false
17-
runs-on: ubuntu-latest
24+
needs: [determine_runner]
25+
runs-on: ${{ needs.determine_runner.outputs.runner_group }}
1826

1927
steps:
2028
- name: Set up Python

.github/workflows/interface-unit-tests.yml

+47-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,28 @@ on:
6969
required: false
7070
type: boolean
7171
default: true
72+
use_large_runner:
73+
description: |
74+
Indicate if the large runner should be used for the job.
75+
If this is true, large runner is used for the build regardless of the context.
76+
required: false
77+
type: boolean
78+
default: false
7279

7380
jobs:
81+
determine_runner:
82+
if: github.event.pull_request.draft == false
83+
name: Determine runner type to use
84+
uses: ./.github/workflows/determine-workflow-runner.yml
85+
with:
86+
default_runner: ubuntu-latest
87+
force_large_runner: ${{ inputs.use_large_runner }}
88+
7489
setup-ci-load:
75-
runs-on: ubuntu-latest
90+
needs:
91+
- determine_runner
92+
93+
runs-on: ${{ needs.determine_runner.outputs.runner_group }}
7694

7795
steps:
7896
- name: Setup Python Versions
@@ -162,7 +180,10 @@ jobs:
162180
# This job is the source of truth for the default versions of PyTorch, TensorFlow, and JAX.
163181
# Individual jobs can use these values or override at a per job level.
164182
default-dependency-versions:
165-
runs-on: ubuntu-latest
183+
needs:
184+
- determine_runner
185+
186+
runs-on: ${{ needs.determine_runner.outputs.runner_group }}
166187

167188
steps:
168189
- name: Default JAX Version
@@ -196,6 +217,7 @@ jobs:
196217
torch-tests:
197218
needs:
198219
- setup-ci-load
220+
- determine_runner
199221
- default-dependency-versions
200222
strategy:
201223
max-parallel: >-
@@ -212,6 +234,7 @@ jobs:
212234
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'torch-tests') }}
213235
uses: ./.github/workflows/unit-test.yml
214236
with:
237+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
215238
job_name: ${{ inputs.job_name_prefix }}torch-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
216239
branch: ${{ inputs.branch }}
217240
coverage_artifact_name: core-interfaces-coverage-torch-${{ matrix.python-version }}
@@ -229,6 +252,7 @@ jobs:
229252
autograd-tests:
230253
needs:
231254
- setup-ci-load
255+
- determine_runner
232256
- default-dependency-versions
233257
strategy:
234258
max-parallel: >-
@@ -245,6 +269,7 @@ jobs:
245269
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'autograd-tests') }}
246270
uses: ./.github/workflows/unit-test.yml
247271
with:
272+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
248273
job_name: ${{ inputs.job_name_prefix }}autograd-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
249274
branch: ${{ inputs.branch }}
250275
coverage_artifact_name: core-interfaces-coverage-autograd-${{ matrix.python-version }}
@@ -259,6 +284,7 @@ jobs:
259284
tf-tests:
260285
needs:
261286
- setup-ci-load
287+
- determine_runner
262288
- default-dependency-versions
263289
strategy:
264290
max-parallel: >-
@@ -276,6 +302,7 @@ jobs:
276302
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'tf-tests') }}
277303
uses: ./.github/workflows/unit-test.yml
278304
with:
305+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
279306
job_name: ${{ inputs.job_name_prefix }}tf-tests (${{ matrix.group }}, ${{ matrix.python-version }})${{ inputs.job_name_suffix }}
280307
branch: ${{ inputs.branch }}
281308
coverage_artifact_name: core-interfaces-coverage-tf-${{ matrix.python-version }}-${{ matrix.group }}
@@ -295,6 +322,7 @@ jobs:
295322
jax-tests:
296323
needs:
297324
- setup-ci-load
325+
- determine_runner
298326
- default-dependency-versions
299327
strategy:
300328
max-parallel: >-
@@ -312,6 +340,7 @@ jobs:
312340
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'jax-tests') }}
313341
uses: ./.github/workflows/unit-test.yml
314342
with:
343+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
315344
job_name: ${{ inputs.job_name_prefix }}jax-tests (${{ matrix.group }}, ${{ matrix.python-version }})${{ inputs.job_name_suffix }}
316345
branch: ${{ inputs.branch }}
317346
coverage_artifact_name: core-interfaces-coverage-jax-${{ matrix.python-version }}-${{ matrix.group }}
@@ -331,6 +360,7 @@ jobs:
331360
core-tests:
332361
needs:
333362
- setup-ci-load
363+
- determine_runner
334364
- default-dependency-versions
335365
strategy:
336366
max-parallel: >-
@@ -348,6 +378,7 @@ jobs:
348378
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'core-tests') }}
349379
uses: ./.github/workflows/unit-test.yml
350380
with:
381+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
351382
job_name: ${{ inputs.job_name_prefix }}core-tests (${{ matrix.group }}, ${{ matrix.python-version }})${{ inputs.job_name_suffix }}
352383
branch: ${{ inputs.branch }}
353384
coverage_artifact_name: core-interfaces-coverage-core-${{ matrix.python-version }}-${{ matrix.group }}
@@ -365,6 +396,7 @@ jobs:
365396
all-interfaces-tests:
366397
needs:
367398
- setup-ci-load
399+
- determine_runner
368400
- default-dependency-versions
369401
strategy:
370402
max-parallel: >-
@@ -381,6 +413,7 @@ jobs:
381413
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'all-interfaces-tests') }}
382414
uses: ./.github/workflows/unit-test.yml
383415
with:
416+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
384417
job_name: ${{ inputs.job_name_prefix }}all-interfaces-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
385418
branch: ${{ inputs.branch }}
386419
coverage_artifact_name: all-interfaces-coverage
@@ -400,6 +433,7 @@ jobs:
400433
external-libraries-tests:
401434
needs:
402435
- setup-ci-load
436+
- determine_runner
403437
- default-dependency-versions
404438
strategy:
405439
max-parallel: >-
@@ -416,6 +450,7 @@ jobs:
416450
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'external-libraries-tests') }}
417451
uses: ./.github/workflows/unit-test.yml
418452
with:
453+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
419454
job_name: ${{ inputs.job_name_prefix }}external-libraries-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
420455
branch: ${{ inputs.branch }}
421456
coverage_artifact_name: external-libraries-tests-coverage
@@ -442,6 +477,7 @@ jobs:
442477
qcut-tests:
443478
needs:
444479
- setup-ci-load
480+
- determine_runner
445481
- default-dependency-versions
446482
strategy:
447483
max-parallel: >-
@@ -458,6 +494,7 @@ jobs:
458494
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'qcut-tests') }}
459495
uses: ./.github/workflows/unit-test.yml
460496
with:
497+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
461498
job_name: ${{ inputs.job_name_prefix }}qcut-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
462499
branch: ${{ inputs.branch }}
463500
coverage_artifact_name: qcut-coverage
@@ -478,6 +515,7 @@ jobs:
478515
qchem-tests:
479516
needs:
480517
- setup-ci-load
518+
- determine_runner
481519
- default-dependency-versions
482520
strategy:
483521
max-parallel: >-
@@ -494,6 +532,7 @@ jobs:
494532
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'qchem-tests') }}
495533
uses: ./.github/workflows/unit-test.yml
496534
with:
535+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
497536
job_name: ${{ inputs.job_name_prefix }}qchem-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
498537
branch: ${{ inputs.branch }}
499538
coverage_artifact_name: qchem-coverage
@@ -510,6 +549,7 @@ jobs:
510549
gradients-tests:
511550
needs:
512551
- setup-ci-load
552+
- determine_runner
513553
- default-dependency-versions
514554
strategy:
515555
max-parallel: >-
@@ -529,6 +569,7 @@ jobs:
529569
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'gradients-tests') }}
530570
uses: ./.github/workflows/unit-test.yml
531571
with:
572+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
532573
job_name: ${{ inputs.job_name_prefix }}gradients-tests (${{ matrix.config.suite }}, ${{ matrix.python-version }})${{ inputs.job_name_suffix }}
533574
branch: ${{ inputs.branch }}
534575
coverage_artifact_name: gradients-${{ matrix.config.suite }}-coverage
@@ -547,6 +588,7 @@ jobs:
547588
data-tests:
548589
needs:
549590
- setup-ci-load
591+
- determine_runner
550592
- default-dependency-versions
551593
strategy:
552594
max-parallel: >-
@@ -563,6 +605,7 @@ jobs:
563605
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'data-tests') }}
564606
uses: ./.github/workflows/unit-test.yml
565607
with:
608+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
566609
job_name: ${{ inputs.job_name_prefix }}data-tests (${{ matrix.python-version }})${{ inputs.job_name_suffix }}
567610
branch: ${{ inputs.branch }}
568611
coverage_artifact_name: data-coverage-${{ matrix.python-version }}
@@ -579,6 +622,7 @@ jobs:
579622
device-tests:
580623
needs:
581624
- setup-ci-load
625+
- determine_runner
582626
- default-dependency-versions
583627
strategy:
584628
max-parallel: >-
@@ -602,6 +646,7 @@ jobs:
602646
if: ${{ !contains(fromJSON(needs.setup-ci-load.outputs.jobs-to-skip), 'device-tests') }}
603647
uses: ./.github/workflows/unit-test.yml
604648
with:
649+
job_runner_name: ${{ needs.determine_runner.outputs.runner_group }}
605650
job_name: ${{ inputs.job_name_prefix }}device-tests (${{ matrix.config.device }}, ${{ matrix.config.shots }}, ${{ matrix.python-version }})${{ inputs.job_name_suffix }}
606651
branch: ${{ inputs.branch }}
607652
coverage_artifact_name: devices-coverage-${{ matrix.config.device }}-${{ matrix.config.shots }}

.github/workflows/unit-test.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ on:
2222
description: Name of the artifact file that will contain the coverage file for codevoc
2323
required: true
2424
type: string
25+
job_runner_name:
26+
description: The name of the runner to use for the job
27+
required: false
28+
type: string
29+
default: 'ubuntu-latest'
2530
checkout_fetch_depth:
2631
description: How many commits to checkout from HEAD of branch passed
2732
required: false
@@ -81,7 +86,7 @@ on:
8186
jobs:
8287
test:
8388
name: ${{ inputs.job_name }}
84-
runs-on: ubuntu-latest
89+
runs-on: ${{ inputs.job_runner_name }}
8590

8691
steps:
8792
- name: Checkout

.github/workflows/upload.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,34 @@ on:
44
types: [published]
55

66
jobs:
7+
determine_runner:
8+
name: Change to Large Runner
9+
uses: ./.github/workflows/determine-workflow-runner.yml
10+
with:
11+
default_runner: ubuntu-latest
12+
force_large_runner: true
13+
714
tests:
815
uses: ./.github/workflows/interface-unit-tests.yml
916
secrets:
1017
codecov_token: ${{ secrets.CODECOV_TOKEN }}
1118
with:
1219
branch: ${{ github.ref }}
20+
use_large_runner: true
1321

1422
upload:
15-
runs-on: ubuntu-latest
23+
runs-on: ${{ needs.determine_runner.outputs.runner_group }}
1624
# Make sure that the PennyLane is not released unless the tests are passing.
1725
needs:
1826
- tests
27+
- determine_runner
1928
steps:
20-
- uses: actions/checkout@v2
29+
- uses: actions/checkout@v4
2130
with:
2231
fetch-depth: 1
2332

2433
- name: Set up Python
25-
uses: actions/setup-python@v2
34+
uses: actions/setup-python@v5
2635
with:
2736
python-version: "3.10"
2837

0 commit comments

Comments
 (0)