Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tket2-hseries): cli extension dumping #584

Merged
merged 19 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]
- 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
120 changes: 118 additions & 2 deletions Cargo.lock

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

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
12 changes: 12 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", "dep:clap-verbosity-flag", "dep:clio"]

[[bin]]
name = "tket2-hseries"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To extend the hugr cli this should be called something prefixed with hugr-

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this naturally extends the hugr cli, I think its fine stand alone for now. It's main use is within the repo anyway (using the justfile)

required-features = ["cli"]

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these versions need to be fixed

clap-verbosity-flag = { version = "*", optional = true }
clio = { version = "*", features = ["clap-parse"], 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 = "HUGR CLI tools.")]
#[group(id = "hugr")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right? also I don't think version is right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#[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
Loading