Skip to content

Commit

Permalink
feat(tket2-hseries): cli extension dumping (#584)
Browse files Browse the repository at this point in the history
Closes #556

---------

Co-authored-by: Douglas Wilson <douglas.wilson@quantinuum.com>
  • Loading branch information
ss2165 and doug-q committed Sep 9, 2024
1 parent d9deacb commit abf292f
Show file tree
Hide file tree
Showing 13 changed files with 2,053 additions and 3 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,34 @@ jobs:
flags: python
token: ${{ secrets.CODECOV_TOKEN }}

# Ensure that serialized extensions match rust implementation
tket2-extensions:
needs: [changes, tests-rs-stable-all-features]
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }}
name: Check standard extensions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mozilla-actions/sccache-action@v0.0.5
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: extractions/setup-just@v2
- name: Generate the updated definitions
run: just gen-extensions
- name: Check if the declarations are up to date
run: |
git diff --exit-code --name-only tket2-py/tket2/extensions/_json_defs
if [ $? -ne 0 ]; then
echo "The serialized standard extensions are not up to date"
echo "Please run 'just gen-extensions' and commit the changes"
exit 1
fi
# This is a meta job to mark successful completion of the required checks,
# even if they are skipped due to no changes in the relevant files.
required-checks:
name: Required checks 🦀+🐍
needs: [changes, check-rs, check-py, tests-rs-stable-no-features, tests-rs-stable-all-features, tests-py]
needs: [changes, check-rs, check-py, tests-rs-stable-no-features, tests-rs-stable-all-features, tests-py, tket2-extensions]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
Expand Down
118 changes: 116 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ missing_docs = "warn"
# Make sure to run `just recompile-eccs` if the hugr serialisation format changes.
hugr = "0.12.1"
hugr-core = "0.9.1"
hugr-cli = "0.6.0"
portgraph = "0.12"
pyo3 = "0.21.2"
itertools = "0.13.0"
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ coverage language="[rust|python]": (_run_lang language \
recompile-eccs:
scripts/compile-test-eccs.sh

# Generate serialized declarations for the tket2 extensions
gen-extensions:
cargo run -p tket2-hseries gen-extensions -o tket2-py/tket2/extensions/_json_defs

# Runs a rust and a python command, depending on the `language` variable.
#
Expand Down
10 changes: 10 additions & 0 deletions tket2-hseries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ description = "TKET2 tool for preparing and validating `Hugr`s for compilation t
keywords = ["Quantum", "Quantinuum"]
categories = ["compilers"]

[features]
default = ["cli"]
cli = ["dep:clap", "dep:hugr-cli"]

[[bin]]
name = "tket2-hseries"
required-features = ["cli"]

[dependencies]
hugr.workspace = true
tket2 = { path = "../tket2", version = "0.2.0" }
Expand All @@ -24,6 +32,8 @@ strum.workspace = true
strum_macros.workspace = true
thiserror.workspace = true
itertools.workspace = true
clap = { workspace = true, optional = true}
hugr-cli = { workspace = true, optional = true }

[dev-dependencies]
cool_asserts.workspace = true
Expand Down
26 changes: 26 additions & 0 deletions tket2-hseries/src/bin/tket2-hseries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! CLI for tket2-hseries

use clap::Parser as _;
use hugr::extension::ExtensionRegistry;
use tket2_hseries::cli::CliArgs;

fn main() {
match CliArgs::parse() {
CliArgs::GenExtensions(args) => {
let reg = ExtensionRegistry::try_new([
tket2::extension::TKET2_EXTENSION.to_owned(),
tket2::extension::angle::ANGLE_EXTENSION.to_owned(),
tket2_hseries::extension::hseries::EXTENSION.to_owned(),
tket2_hseries::extension::futures::EXTENSION.to_owned(),
tket2_hseries::extension::result::EXTENSION.to_owned(),
])
.unwrap();

args.run_dump(&reg);
}
_ => {
eprintln!("Unknown command");
std::process::exit(1);
}
};
}
14 changes: 14 additions & 0 deletions tket2-hseries/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! CLI tools for tket2-hseries.

use clap::Parser;

/// CLI arguments.
#[derive(Parser, Debug)]
#[clap(version = "1.0", long_about = None)]
#[clap(about = "tket2-hseries CLI tools.")]
#[group(id = "tket2-hseries")]
#[non_exhaustive]
pub enum CliArgs {
/// Generate serialized extensions.
GenExtensions(hugr_cli::extensions::ExtArgs),
}
2 changes: 2 additions & 0 deletions tket2-hseries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use thiserror::Error;
use extension::{futures::FutureOpDef, hseries::HSeriesOp};
use lazify_measure::{LazifyMeasurePass, LazifyMeasurePassError};

#[cfg(feature = "cli")]
pub mod cli;
pub mod extension;

pub mod lazify_measure;
Expand Down
Loading

0 comments on commit abf292f

Please sign in to comment.