-
Notifications
You must be signed in to change notification settings - Fork 199
506 lines (440 loc) · 15.8 KB
/
ci.yaml
File metadata and controls
506 lines (440 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# yamllint disable rule:line-length
name: CI
run-name: >-
Run continuous integration checks for ${{github.event_name}} on
${{github.ref_name}} by @${{github.actor}}
on:
push:
branches:
- main
pull_request:
branches:
- main
merge_group:
types:
- checks_requested
workflow_dispatch:
inputs:
debug:
description: 'Run with debugging options'
type: boolean
default: true
soft-linting:
description: 'Do not quit for linting errors'
type: boolean
default: true
env:
# Python version to use for actions/setup-python.
python-version: '3.13'
SHELLOPTS: ${{inputs.debug && 'xtrace'}}
PIP_PROGRESS_BAR: 'off'
concurrency:
cancel-in-progress: true
group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
permissions: read-all
jobs:
python-checks:
name: 'Python format & lint checks'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5
with:
python-version: ${{env.python-version}}
cache: pip
cache-dependency-path: |
requirements.txt
pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt --group dev
- name: Check format
continue-on-error: ${{inputs.soft-linting == 'true'}}
run: |
echo '::add-matcher::.github/problem-matchers/black.json'
check/format-incremental
- name: Check lint
continue-on-error: ${{inputs.soft-linting == 'true'}}
run: |
echo '::add-matcher::.github/problem-matchers/pylint.json'
pylint ${{inputs.soft-linting && '--exit-zero'}} -j 0 .
docker-lint:
name: Dockerfile lint checks
if: github.repository_owner == 'quantumlib'
# ubuntu-slim runners don't have docker installed.
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Run hadolint on Dockerfiles
continue-on-error: ${{inputs.soft-linting == 'true'}}
env:
hadolint_version: 'sha256:e9dbf5113239ef2bf696d20c8f28d3019a47c26a38c98b89344d3e2846c4d5f8'
run: |
echo '::add-matcher::.github/problem-matchers/hadolint.json'
find . -name Dockerfile -print0 | \
xargs -0 -r docker run --rm -i -v "${PWD}:/app" -w /app \
--entrypoint /bin/hadolint \
ghcr.io/hadolint/hadolint@${{env.hadolint_version}}
shell-lint:
name: Shell script lint checks
if: github.repository_owner == 'quantumlib'
runs-on: ubuntu-slim
timeout-minutes: 15
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Install problem matcher
run: echo '::add-matcher::.github/problem-matchers/shellcheck.json'
- name: Run ShellCheck
continue-on-error: ${{inputs.soft-linting == 'true'}}
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38
with:
severity: error
check_together: 'yes'
additional_files: >-
check/format-incremental
yaml-lint:
name: YAML lint checks
if: github.repository_owner == 'quantumlib'
runs-on: ubuntu-slim
timeout-minutes: 15
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Install yamllint
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y yamllint
- name: Lint the YAML files
continue-on-error: ${{inputs.soft-linting == 'true'}}
run: |
echo "::add-matcher::.github/problem-matchers/yamllint.json"
# shellcheck disable=SC2038
find . -not -path '*.github/workflows/*' \
'(' -name '*.yaml' -o -name '*.yml' ')' | \
xargs yamllint -f github
bazel-lint:
name: Bazel build lint checks
if: github.repository_owner == 'quantumlib'
runs-on: ubuntu-slim
timeout-minutes: 15
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Install Buildifier
uses: jbajic/setup-buildifier@c558ee05c6f74ab5753ff794516750b4aadac296 # v1
with:
buildifier-version: '8.2.1'
- name: Run Buildifier in lint mode
continue-on-error: ${{inputs.soft-linting == 'true'}}
run: |
echo '::add-matcher::.github/problem-matchers/buildifier.json'
# shellcheck disable=SC2038
find . -name 'BUILD' -o -name '*.bzl' -o -name 'WORKSPACE' | \
xargs buildifier -mode=diff -lint=warn
action-lint:
name: GitHub Actions lint checks
if: github.repository_owner == 'quantumlib'
runs-on: ubuntu-slim
timeout-minutes: 15
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Run actionlint
continue-on-error: ${{inputs.soft-linting == 'true'}}
uses: raven-actions/actionlint@e01d1ea33dd6a5ed517d95b4c0c357560ac6f518 # v2
with:
flags: ${{inputs.debug && '-verbose'}}
files: '.github/workflows/*.{yaml,yml}'
pyflakes: false
library-tests:
name: Library tests
if: github.repository_owner == 'quantumlib'
needs:
- action-lint
- bazel-lint
- python-checks
- shell-lint
- yaml-lint
runs-on: ${{matrix.os}}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
# It's not worth testing every possible combination here, so this only
# tests the endpoints of the supported range. The wheel build process
# (in a separate workflow) *does* use all the versions.
os:
- ubuntu-24.04-x64-8-core
- macos-14
- macos-15
- windows-2025-x64-8-core
python_version:
- '3.10'
- '3.13'
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5
id: setup
with:
python-version: ${{matrix.python_version}}
cache: pip
cache-dependency-path: |
requirements.txt
pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt --group dev
- name: Set up Bazel
uses: './.github/actions/set-up-bazel'
with:
debug: ${{inputs.debug}}
- if: ${{! startsWith(matrix.os, 'windows-')}}
name: Build the qsim C++ library and run tests (non-Windows case)
run: |
alias bazel=bazelisk
dev_tools/test_libs.sh ${{inputs.debug && '--config=verbose'}}
- if: ${{startsWith(matrix.os, 'windows-')}}
name: Build the qsim C++ library and run tests (Windows case)
# On GitHub Windows runners, Bazel ends up finding a different "python3"
# binary than what's installed by setup-python unless we tell Bazel what
# to use. Here we do that by setting PYTHON_BIN_PATH.
env:
root: 'C:\\hostedtoolcache\\windows\\Python'
exe: '${{steps.setup.outputs.python-version}}\\x64\\python3.exe'
shell: cmd
run: bash -x dev_tools/test_libs.sh ${{inputs.debug && '--config=verbose'}} --action_env PYTHON_BIN_PATH=${{env.root}}\\${{env.exe}}
- name: Install LLVM and OpenMP on macOS
if: startsWith(matrix.os, 'macos')
env:
HOMEBREW_NO_AUTO_UPDATE: 1
run: |
brew install -q libomp llvm@19
brew unlink libomp
brew unlink llvm@19
brew link --force libomp
brew link --force llvm@19
brew_prefix="$(brew --prefix)"
xcode_prefix="$(xcrun --sdk macosx --show-sdk-path)"
export PATH="${brew_prefix}/bin:$PATH"
echo "PATH=${PATH}" >> "$GITHUB_ENV"
export LDFLAGS="-L${brew_prefix}/lib -Wl,-rpath,${brew_prefix}/lib"
echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV"
export CXXFLAGS="-I${xcode_prefix}/usr/include -I${brew_prefix}/include -O3 -std=c++17 -flto=auto -Xpreprocessor -fopenmp"
echo "CXXFLAGS=${CXXFLAGS}" >> "$GITHUB_ENV"
- name: Build the Python bindings
shell: bash
run: |
mkdir build
cd build
cmake ${{inputs.debug && '--debug-output' || ''}} ..
cmake --build . -j ${{inputs.debug && '--verbose' || ''}}
options-tests:
name: Options tests
if: github.repository_owner == 'quantumlib'
needs:
- action-lint
- bazel-lint
- python-checks
- shell-lint
- yaml-lint
runs-on: ubuntu-24.04-x64-16-core
timeout-minutes: 60
strategy:
matrix:
# Hardware optimizers.
hardware_opt: [avx, sse, basic]
# Optimizers for parallelism.
parallel_opt: [openmp, nopenmp]
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5
with:
python-version: ${{env.python-version}}
cache: pip
cache-dependency-path: |
requirements.txt
pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt --group dev
- name: Set up Bazel
uses: './.github/actions/set-up-bazel'
with:
debug: ${{inputs.debug}}
- name: Run C++ tests
run: |
bazel test \
--config=${{matrix.hardware_opt}} \
--config=${{matrix.parallel_opt}} \
${{inputs.debug && '--config=verbose'}} \
tests:all
- name: Run sample simulation
run: |
bazel run \
--config=${{matrix.hardware_opt}} \
--config=${{matrix.parallel_opt}} \
${{inputs.debug && '--config=verbose'}} \
apps:qsim_base -- -c circuits/circuit_q24
memory-tests:
name: Malloc/asan/msan tests
if: github.repository_owner == 'quantumlib'
needs:
- action-lint
- bazel-lint
- python-checks
- shell-lint
- yaml-lint
runs-on: ubuntu-24.04-x64-16-core
timeout-minutes: 60
env:
common_args: >-
--config=avx
--config=openmp
${{inputs.debug && '--config=verbose'}}
tests:all
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5
with:
python-version: ${{env.python-version}}
cache: pip
cache-dependency-path: |
requirements.txt
pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -r requirements.txt --group dev
- name: Set up Bazel
uses: './.github/actions/set-up-bazel'
with:
debug: ${{inputs.debug}}
- name: Install google-perftools for tcmalloc
run: |
sudo apt-get update
sudo apt-get install -y libgoogle-perftools-dev
- name: Run TCMalloc tests
env:
PERFTOOLS_VERBOSE: ${{inputs.debug && 1}}
run: bazel test --config=tcmalloc ${{env.common_args}}
- name: Run memory sanitizer tests
run: bazel test --config=msan ${{env.common_args}}
- name: Run address sanitizer tests
run: bazel test --config=asan ${{env.common_args}}
docker-tests:
name: Docker build tests
if: github.repository_owner == 'quantumlib'
needs:
- action-lint
- docker-lint
- python-checks
- shell-lint
- yaml-lint
runs-on: ubuntu-24.04-x64-16-core
timeout-minutes: 60
env:
# The next environment variable is used by Docker.
BUILDKIT_PROGRESS: ${{inputs.debug && 'plain'}}
steps:
- name: Check out a copy of the git repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
- name: Build Docker images
run: |
# Running locally, a plain "docker compose build" works as expected.
# On GitHub, buildx tries to build all 3 images in parallel even if
# you set COMPOSE_PARALLEL_LIMIT or use --parallel 1. That fails b/c
# the qsim-base image is not available to the other two build jobs.
docker compose build qsim-base-image
docker compose build --parallel qsim-cxx-tests-image qsim-py-tests-image
- name: Run C++ tests
run: docker run --rm qsim-cxx-tests:latest
- name: Run Python tests
run: docker run --rm qsim-py-tests:latest
- name: Run a sample simulation
run: docker run --rm qsim-base:latest -c /qsim/circuits/circuit_q24
- name: Test installation process
working-directory: install/tests
run: docker compose build
report-results:
name: CI
if: always() && github.repository_owner == 'quantumlib'
needs:
- action-lint
- bazel-lint
- docker-lint
- docker-tests
- library-tests
- memory-tests
- options-tests
- python-checks
- shell-lint
- yaml-lint
runs-on: ubuntu-slim
timeout-minutes: 5
steps:
- name: Report failure
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: |
{
echo ":x: CI checks failed"
echo "One or more CI jobs failed. Please check the logs for details."
} >> "$GITHUB_STEP_SUMMARY"
- name: Point out if soft-linting is in effect
if: inputs.soft-linting
run: |
{
echo "> [!CAUTION]:"
echo "> **Soft linting is in effect**."
echo "> Format and lint errors have been ignored."
} >> "$GITHUB_STEP_SUMMARY"
- name: Exit with error (if appropriate)
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1