-
Notifications
You must be signed in to change notification settings - Fork 377
515 lines (440 loc) · 16.7 KB
/
ci_macos.yml
File metadata and controls
515 lines (440 loc) · 16.7 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
507
508
509
510
511
512
513
514
515
on:
workflow_call:
inputs:
cache_base:
required: false
type: string
default: main
cudaq_version:
required: false
type: string
description: 'Override version for wheel/installer (e.g. when called from deployments for a release).'
default: ''
# Daily rebuild on main to ensure devdeps rebuilt as needed
schedule:
- cron: '0 4 * * *' # aim to be ready by 9am CET/CEST
workflow_dispatch:
inputs:
cache_base:
required: false
type: string
description: 'The name of the branch to use as cache base.'
default: main
push:
branches:
- "pull-request/[0-9]+"
merge_group:
types:
- checks_requested
name: CI - macOS # do not change name without updating workflow_run triggers
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# ============================================================================
# Metadata: Retrieve PR info and commit hashes
# ============================================================================
metadata:
name: Retrieve PR info
runs-on: ubuntu-latest
permissions:
pull-requests: read
contents: read
outputs:
pull_request_number: ${{ steps.pr_info.outputs.pr_number }}
pull_request_base: ${{ steps.pr_info.outputs.pr_base }}
cache_base: ${{ steps.pr_info.outputs.pr_base }}
cudaq_version: ${{ steps.version.outputs.cudaq_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- id: pr_info
run: |
# Try event context first, then parse from the ref name
# (handles both pull-request/XXXX and merge queue refs)
pr_number="${{ github.event.pull_request.number }}"
if [ -z "$pr_number" ] && \
[[ "${{ github.ref_name }}" =~ (pull-request/|.*/pr-)([0-9]+) ]]; then
pr_number="${BASH_REMATCH[2]}"
fi
if [ -n "$pr_number" ]; then
pr_base=`gh pr view $pr_number -R ${{ github.repository }} --json baseRefName --jq .baseRefName`
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
echo "pr_base=$pr_base" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}
- id: version
run: |
if [ -n "${{ inputs.cudaq_version }}" ]; then
cudaq_version=$(echo "${{ inputs.cudaq_version }}" | egrep -o "([0-9]{1,}\.)+[0-9]{1,}([A-Za-z0-9_\-\.]*)" || true)
cudaq_version=${cudaq_version:-0.0.0}
else
is_versioned=${{ github.ref_type == 'tag' || startsWith(github.ref_name, 'releases/') || startsWith(github.ref_name, 'staging/') }}
if ${is_versioned}; then
cudaq_version=$(echo ${{ github.ref_name }} | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
else
cudaq_version=0.0.0
fi
fi
echo "cudaq_version=$cudaq_version" >> $GITHUB_OUTPUT
# ============================================================================
# Build prerequisites via GHCR caching
# Uses dev_environment_macos.yml which packages artifacts into an Ubuntu image
# ============================================================================
devdeps:
name: Load macOS dependencies
needs: metadata
uses: ./.github/workflows/dev_environment_macos.yml
with:
platforms: darwin/arm64
registry_cache_from: ${{ inputs.cache_base || needs.metadata.outputs.cache_base }}
checkout_submodules: false
environment: ghcr-ci
# ============================================================================
# Build and test CUDA-Q
# ============================================================================
build_and_test:
name: Build & Test (arm64)
needs: [devdeps, metadata]
runs-on: macos-26
permissions:
contents: read
packages: write
env:
CC: clang
CXX: clang++
MACOSX_DEPLOYMENT_TARGET: '13.0'
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Select latest stable Xcode
uses: ./.github/actions/setup-xcode-stable
- name: Log macOS toolchain
run: |
sw_vers
xcodebuild -version
xcrun --show-sdk-path
xcrun --show-sdk-version
clang --version
- name: Set up ccache and ORAS
uses: ./.github/actions/ccache-setup
- name: Restore prerequisites from GHCR
run: |
set -e # Exit on error
echo "${{ github.token }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
oras pull ${{ needs.devdeps.outputs.image_hash }}
tar -xzf macos-artifacts.tar.gz -C $HOME
rm macos-artifacts.tar.gz
echo "=== Restored prerequisites ==="
du -sh ~/.local || true
du -sh ~/.llvm-project || true
- name: Restore ccache from GHCR
uses: ./.github/actions/ccache-restore
with:
cache-key: arm64-build
output-path: ${{ env.CCACHE_DIR }}
registry-token: ${{ github.token }}
- name: Install Python dependencies
run: CCACHE_DISABLE=1 pip install -r requirements-dev.txt
- name: Build MLIR Python bindings
run: |
source scripts/set_env_defaults.sh
Python3_EXECUTABLE="$(which python3)" \
LLVM_SOURCE="$HOME/.llvm-project" \
bash scripts/build_llvm.sh -c Release -v -j $(sysctl -n hw.ncpu)
- name: Build CUDA-Q
run: bash scripts/build_cudaq.sh -v -- -DCUDAQ_TEST_OMP_SLOTS=2
- name: Push ccache to GHCR
uses: ./.github/actions/ccache-push
with:
cache-key: arm64-build
cache-path: ${{ env.CCACHE_DIR }}
registry-token: ${{ github.token }}
upload-log: 'true'
- name: Run tests
run: bash scripts/run_tests.sh -v
# ============================================================================
# Build Python wheels for all supported Python versions
# Rebuilds MLIR Python bindings for each Python version from cached LLVM
# ============================================================================
wheel:
name: Wheel (arm64, py${{ matrix.python_version }})
needs: [devdeps, metadata]
strategy:
matrix:
python_version: ['3.11', '3.12', '3.13']
fail-fast: false
runs-on: macos-26
permissions:
contents: read
packages: write
env:
CC: clang
CXX: clang++
MACOSX_DEPLOYMENT_TARGET: '13.0'
outputs:
cudaq_version: ${{ needs.metadata.outputs.cudaq_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Select latest stable Xcode
uses: ./.github/actions/setup-xcode-stable
- name: Log macOS toolchain
run: |
sw_vers
xcodebuild -version
xcrun --show-sdk-path
xcrun --show-sdk-version
clang --version
- name: Set up ccache and ORAS
uses: ./.github/actions/ccache-setup
- name: Restore prerequisites from GHCR
run: |
set -e # Exit on error
echo "${{ github.token }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
oras pull ${{ needs.devdeps.outputs.image_hash }}
tar -xzf macos-artifacts.tar.gz -C $HOME
rm macos-artifacts.tar.gz
- name: Restore ccache from GHCR
uses: ./.github/actions/ccache-restore
with:
cache-key: arm64-wheel
output-path: ${{ env.CCACHE_DIR }}
registry-token: ${{ github.token }}
- name: Install Python dependencies
run: CCACHE_DISABLE=1 pip install -r requirements-dev.txt
- name: Build MLIR Python bindings
run: |
source scripts/set_env_defaults.sh
Python3_EXECUTABLE="$(which python3)" \
LLVM_SOURCE="$HOME/.llvm-project" \
bash scripts/build_llvm.sh -c Release -v -j $(sysctl -n hw.ncpu)
- name: Build wheel
run: |
echo "Building wheel version: ${{ needs.metadata.outputs.cudaq_version }}"
# Source env defaults to set ZLIB_INSTALL_PREFIX, LLVM_INSTALL_PREFIX, etc.
# These point to cached prerequisites in ~/.local
source scripts/set_env_defaults.sh
export CUDA_QUANTUM_VERSION=${{ needs.metadata.outputs.cudaq_version }}
bash scripts/build_wheel.sh -v
# Find and report the built wheel
wheel_file=$(ls dist/cuda_quantum*.whl 2>/dev/null | head -1)
echo "Built wheel: $wheel_file"
- name: Push ccache to GHCR
uses: ./.github/actions/ccache-push
with:
cache-key: arm64-wheel
cache-path: ${{ env.CCACHE_DIR }}
registry-token: ${{ github.token }}
upload-log: 'true'
- name: Upload wheel artifact
uses: actions/upload-artifact@v4
with:
# Consistent with Linux: pycudaq-<python_version_dashed>-<platform_info>
name: pycudaq-${{ matrix.python_version }}-darwin-arm64
path: dist/cuda_quantum*.whl
retention-days: 3
if-no-files-found: error
# ============================================================================
# Validate wheels in clean environments
# ============================================================================
validate_wheel:
name: Validate (arm64, py${{ matrix.python_version }})
needs: wheel
strategy:
matrix:
python_version: ['3.11', '3.12', '3.13']
fail-fast: false
runs-on: macos-26
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Select latest stable Xcode
uses: ./.github/actions/setup-xcode-stable
- name: Log macOS toolchain
run: |
sw_vers
xcodebuild -version
xcrun --show-sdk-path
xcrun --show-sdk-version
clang --version
- name: Download wheel artifact
uses: actions/download-artifact@v4
with:
name: pycudaq-${{ matrix.python_version }}-darwin-arm64
path: dist/
- name: Validate wheel
run: |
# Validates wheel: core tests, examples, snippets, backends.
# GPU/remote targets are skipped (no CUDA on macOS runners).
# TODO: When adding macOS to publishing.yml, align the validation
# approach with python_wheels.yml (which uses
# explicit find exclusions for platform/backends/dynamics paths,
# and does not use validate_pycudaq.sh for snippets/examples
# currently used in python_wheels.yml).
bash scripts/validate_pycudaq.sh \
-v ${{ needs.wheel.outputs.cudaq_version }} \
-i dist \
-p ${{ matrix.python_version }}
# ============================================================================
# Build self-extracting installer for C++ SDK
# ============================================================================
installer:
name: Installer (arm64)
needs: [devdeps, metadata]
runs-on: macos-26
permissions:
contents: read
packages: write
env:
CC: clang
CXX: clang++
MACOSX_DEPLOYMENT_TARGET: '13.0'
outputs:
cudaq_version: ${{ needs.metadata.outputs.cudaq_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Select latest stable Xcode
uses: ./.github/actions/setup-xcode-stable
- name: Log macOS toolchain
run: |
sw_vers
xcodebuild -version
xcrun --show-sdk-path
xcrun --show-sdk-version
clang --version
- name: Set up ccache and ORAS
uses: ./.github/actions/ccache-setup
- name: Restore prerequisites from GHCR
run: |
set -e # Exit on error
echo "${{ github.token }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
oras pull ${{ needs.devdeps.outputs.image_hash }}
tar -xzf macos-artifacts.tar.gz -C $HOME
rm macos-artifacts.tar.gz
- name: Restore ccache from GHCR
uses: ./.github/actions/ccache-restore
with:
cache-key: arm64-installer
output-path: ${{ env.CCACHE_DIR }}
registry-token: ${{ github.token }}
- name: Install dependencies
run: |
CCACHE_DISABLE=1 pip install -r requirements-dev.txt
brew install makeself pigz
- name: Build MLIR Python bindings
run: |
source scripts/set_env_defaults.sh
Python3_EXECUTABLE="$(which python3)" \
LLVM_SOURCE="$HOME/.llvm-project" \
bash scripts/build_llvm.sh -c Release -v -j $(sysctl -n hw.ncpu)
- name: Build CUDA-Q
run: bash scripts/build_cudaq.sh -v -- -DCUDAQ_TEST_OMP_SLOTS=2
- name: Push ccache to GHCR
uses: ./.github/actions/ccache-push
with:
cache-key: arm64-installer
cache-path: ${{ env.CCACHE_DIR }}
registry-token: ${{ github.token }}
upload-log: 'true'
- name: Build installer
run: |
echo "Building installer version: ${{ needs.metadata.outputs.cudaq_version }}"
source scripts/set_env_defaults.sh
bash scripts/build_installer.sh -v -V ${{ needs.metadata.outputs.cudaq_version }}
# List output
ls -la out/
- name: Upload installer artifact
uses: actions/upload-artifact@v4
with:
# Consistent with Linux: cudaq-<platform>-<config>-installer-<run_id>
name: cudaq-arm64-darwin-installer-${{ github.run_id }}
path: out/install_cuda_quantum*
retention-days: 3
if-no-files-found: error
# ============================================================================
# Validate installation in clean environment
# Installer provides C++ support; wheel provides Python support
# ============================================================================
validate_installation:
name: Validate Installation (arm64)
needs: [installer, wheel]
runs-on: macos-26
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Select latest stable Xcode
uses: ./.github/actions/setup-xcode-stable
- name: Log macOS toolchain
run: |
sw_vers
xcodebuild -version
xcrun --show-sdk-path
xcrun --show-sdk-version
clang --version
- name: Download installer artifact
uses: actions/download-artifact@v4
with:
name: cudaq-arm64-darwin-installer-${{ github.run_id }}
path: installer/
- name: Download wheel artifact
uses: actions/download-artifact@v4
with:
name: pycudaq-3.12-darwin-arm64
path: wheel/
- name: Create test user
run: |
sudo sysadminctl -addUser cudaqtest -password 'cudaqtest123' -admin
sudo mkdir -p /Users/cudaqtest
sudo chown cudaqtest /Users/cudaqtest
- name: Install CUDA-Q (C++ via installer to neutral path)
run: |
install_path=/opt/cudaq-test
sudo mkdir -p "$install_path"
sudo chown cudaqtest "$install_path"
chmod +x installer/install_cuda_quantum*
sudo -u cudaqtest bash installer/install_cuda_quantum* --accept -- --installpath "$install_path"
- name: Install CUDA-Q (Python via wheel)
run: |
sudo -u cudaqtest -H python3 -m venv /Users/cudaqtest/venv
sudo -u cudaqtest -H /Users/cudaqtest/venv/bin/pip install wheel/*.whl
- name: Validate installation
run: |
install_path=/opt/cudaq-test
workdir=$(sudo -u cudaqtest mktemp -d)
sudo cp -R scripts docs "$workdir/"
sudo chown -R cudaqtest "$workdir"
sudo -u cudaqtest bash -lc "
source /Users/cudaqtest/venv/bin/activate
source ${install_path}/set_env.sh
cd ${workdir}
bash scripts/validate_installation.sh
"