Skip to content

Commit 77677ee

Browse files
lmondadaaborgna-qcqc-alec
authored
feat: Add tket1-passes subcrate (#939)
This introduces a way to call into TKET1's C++ library from here (tket2). In writing this, it was my priority to 1. not complicate the build process for anyone that is not interested in this functionality, and 2. not slow down CI too much. By not including `tket1-passes` in Cargo's `default-members`, this will not be compiled unless required explicitly. One way to simplify the compilation process further would be to provide pre-compiled libraries for the main platforms. This requires a certain maintenance burden on us, however, which is why I haven't gone down this route (yet). On CI speed: this uses a pre-compiled version of tket1, so that the compilation times for the library are low (~30s). The library is uploaded as artifact and re-used for every job. I've also amended the CI job `rust-stable-no-features` to not compile `tket1-passes` (as well as the other CLI tools that have no tests) for further speed up. A way to speed up the CI further would be to cache the compiled library across workflow runs. I'll create an issue for this. Finally, a note on platform support: the current build scripts will probably not work on Windows. I am not familliar with Windows tooling and had no way of testing it. Is this something that must be tackled before merging @aborgna-q ? Closes #940 --------- Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com> Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
1 parent c3efd1d commit 77677ee

File tree

19 files changed

+1022
-14
lines changed

19 files changed

+1022
-14
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Build/cache tket1-passes C++ library"
2+
description: "Retrieve cached tket1-passes C++ library or build if needed"
3+
4+
inputs:
5+
lib-path:
6+
description: "Path to the tket1-passes C++ library"
7+
required: false
8+
default: "tket1-passes/lib"
9+
10+
runs:
11+
using: composite
12+
steps:
13+
# Attempt to retrieve from cache
14+
- name: Retrieve cached tket1-passes C++ library
15+
uses: actions/cache/restore@v4
16+
id: cache
17+
with:
18+
path: ${{ inputs.lib-path }}
19+
key: ${{ runner.os }}-${{ hashFiles('tket1-passes/cpp/**') }}
20+
21+
# Build tket1-passes
22+
- name: Install conan
23+
if: steps.cache.outputs.cache-hit != 'true'
24+
uses: turtlebrowser/get-conan@v1.2
25+
- name: Set up conan
26+
if: steps.cache.outputs.cache-hit != 'true'
27+
shell: bash
28+
run: |
29+
conan profile detect
30+
conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0
31+
- name: Build tket1-passes C++ library
32+
if: steps.cache.outputs.cache-hit != 'true'
33+
shell: bash
34+
env:
35+
TKET_LIB_PATH: "${{ inputs.lib-path }}"
36+
run: |
37+
cd tket1-passes/cpp
38+
./build.sh
39+
40+
# Upload cache
41+
- name: Update tket1-passes C++ library cache
42+
if: steps.cache.outputs.cache-hit != 'true'
43+
uses: actions/cache/save@v4
44+
with:
45+
path: ${{ inputs.lib-path }}
46+
key: ${{ steps.cache.outputs.cache-primary-key }}

.github/change-filters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rust:
1111
- "tket2-hseries/**"
1212
- "badger-optimiser/**"
1313
- "compile-rewriter/**"
14+
- "tket1-passes/**"
1415

1516
python:
1617
- *rust-core

.github/workflows/ci.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565

6666
check-rs:
6767
name: Check Rust code 🦀
68-
needs: changes
68+
needs: [changes]
6969
if: ${{ needs.changes.outputs.rust == 'true' }}
7070
runs-on: ubuntu-latest
7171
steps:
@@ -75,6 +75,8 @@ jobs:
7575
uses: dtolnay/rust-toolchain@stable
7676
with:
7777
components: rustfmt, clippy
78+
- name: Retrieve tket1-passes library
79+
uses: ./.github/actions/tket1-passes
7880
- name: Check formatting
7981
run: cargo fmt -- --check
8082
- name: Install LLVM and Clang
@@ -153,13 +155,13 @@ jobs:
153155
- name: Configure default rust toolchain
154156
run: rustup override set ${{steps.toolchain.outputs.name}}
155157
- name: Build with no features
156-
run: cargo test --verbose --workspace --no-default-features --no-run
158+
run: cargo test --verbose -p tket2 -p tket2-py -p tket2-hseries --no-default-features --no-run
157159
- name: Tests with no features
158-
run: cargo test --verbose --workspace --no-default-features
160+
run: cargo test --verbose -p tket2 -p tket2-py -p tket2-hseries --no-default-features
159161

160162
# Run tests on Rust stable
161163
tests-rs-stable-all-features:
162-
needs: changes
164+
needs: [changes]
163165
if: ${{ needs.changes.outputs.rust == 'true' }}
164166
runs-on: ubuntu-latest
165167
name: tests (Rust stable, all features)
@@ -169,21 +171,23 @@ jobs:
169171
- id: toolchain
170172
uses: dtolnay/rust-toolchain@master
171173
with:
172-
toolchain: 'stable'
174+
toolchain: "stable"
173175
- name: Configure default rust toolchain
174176
run: rustup override set ${{steps.toolchain.outputs.name}}
175177
- name: Install LLVM and Clang
176178
uses: KyleMayes/install-llvm-action@v2
177179
with:
178180
version: ${{ env.LLVM_VERSION }}
181+
- name: Retrieve tket1-passes library
182+
uses: ./.github/actions/tket1-passes
179183
- name: Build with all features
180184
run: cargo test --verbose --workspace --all-features --no-run
181185
- name: Tests with all features
182186
run: cargo test --verbose --workspace --all-features
183187

184188
# Run tests on other toolchains
185189
tests-rs-other:
186-
needs: changes
190+
needs: [changes]
187191
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
188192
runs-on: ubuntu-latest
189193
strategy:
@@ -204,6 +208,8 @@ jobs:
204208
uses: KyleMayes/install-llvm-action@v2
205209
with:
206210
version: ${{ env.LLVM_VERSION }}
211+
- name: Retrieve tket1-passes library
212+
uses: ./.github/actions/tket1-passes
207213
- name: Configure default rust toolchain
208214
run: rustup override set ${{steps.toolchain.outputs.name}}
209215
- name: Build with no features
@@ -216,7 +222,7 @@ jobs:
216222
run: cargo test --verbose --workspace --all-features
217223

218224
tests-nightly-coverage:
219-
needs: changes
225+
needs: [changes]
220226
# Run only if there are changes in the relevant files
221227
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
222228
runs-on: ubuntu-latest
@@ -234,6 +240,8 @@ jobs:
234240
uses: KyleMayes/install-llvm-action@v2
235241
with:
236242
version: ${{ env.LLVM_VERSION }}
243+
- name: Retrieve tket1-passes library
244+
uses: ./.github/actions/tket1-passes
237245
- name: Install cargo-llvm-cov
238246
uses: taiki-e/install-action@cargo-llvm-cov
239247
- name: Run tests with coverage instrumentation

.github/workflows/semver-checks.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,20 @@ jobs:
4242
rs-semver-checks:
4343
needs: [changes]
4444
if: ${{ needs.changes.outputs.rust == 'true' }}
45-
uses: CQCL/hugrverse-actions/.github/workflows/rs-semver-checks.yml@main
46-
with:
47-
apt-dependencies: llvm-14
48-
secrets:
49-
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout tket2
48+
uses: actions/checkout@v4
49+
- name: Retrieve tket1-passes library
50+
uses: ./.github/actions/tket1-passes
51+
with:
52+
lib-path: ${{ github.workspace }}/tket1-lib
53+
- name: Install LLVM from apt
54+
run: |
55+
echo "Installing apt dependencies: llvm-14"
56+
sudo apt-get install -y llvm-14
57+
- uses: CQCL/hugrverse-actions/rs-semver-checks@main
58+
env:
59+
TKET_LIB_PATH: ${{ github.workspace }}/tket1-lib
60+
with:
61+
token: ${{ secrets.HUGRBOT_PAT }}

0 commit comments

Comments
 (0)