Skip to content

Commit

Permalink
feat: init tket2-ngrte
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed May 30, 2024
1 parent c77f327 commit 8edcbe3
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 15 deletions.
83 changes: 71 additions & 12 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ lto = "thin"

[workspace]
resolver = "2"
members = ["tket2", "tket2-py", "compile-rewriter", "badger-optimiser"]
default-members = ["tket2"]
members = ["tket2", "tket2-py", "compile-rewriter", "badger-optimiser", "tket2-hseries"]
default-members = ["tket2", "tket2-hseries"]

[workspace.package]
rust-version = "1.75"
Expand All @@ -19,7 +19,8 @@ missing_docs = "warn"
[workspace.dependencies]

tket2 = { path = "./tket2" }
hugr = "0.4.0"
hugr = "0.5.0"
hugr-cli = "0.1.0"
portgraph = "0.12"
pyo3 = "0.21.2"
itertools = "0.13.0"
Expand Down
33 changes: 33 additions & 0 deletions tket2-hseries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "tket2-hseries"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true

license.workspace = true
readme = "README.md"
documentation = "https://docs.rs/tket2-hseries"
homepage.workspace = true
repository.workspace = true
description = "TKET2 tool for preparing and validating `Hugr`s for compilation targeting Quantinuum H-series quantum computers"
keywords = ["Quantum", "Quantinuum"]
categories = ["compilers"]

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

[dependencies]
hugr.workspace = true
hugr-cli = { workspace = true, optional = true }
clap = { workspace = true, optional = true, features = ["derive"] }
tket2.workspace = true
serde_json.workspace = true
lazy_static.workspace = true

[lints]
workspace = true

[[bin]]
name = "tket2-hseries"
required-features = ["cli"]
4 changes: 4 additions & 0 deletions tket2-hseries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# tket2-hseries

A TKET2 tool for preparing and validating `Hugr`s for compilation targeting
Quantinuum H-series quantum computers.
50 changes: 50 additions & 0 deletions tket2-hseries/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Provides a command line interface to tket2-hseries
use clap::Parser;
use hugr::std_extensions::arithmetic::{
conversions::EXTENSION as CONVERSIONS_EXTENSION, float_ops::EXTENSION as FLOAT_OPS_EXTENSION,
float_types::EXTENSION as FLOAT_TYPES_EXTENSION, int_ops::EXTENSION as INT_OPS_EXTENSION,
int_types::EXTENSION as INT_TYPES_EXTENSION,
};
use hugr::std_extensions::logic::EXTENSION as LOGICS_EXTENSION;

use hugr::extension::{ExtensionRegistry, PRELUDE};
use lazy_static::lazy_static;

lazy_static! {
/// A registry suitable for passing to `run`. Use this unless you have a
/// good reason not to do so.
pub static ref REGISTRY: ExtensionRegistry = ExtensionRegistry::try_new([
PRELUDE.to_owned(),
INT_OPS_EXTENSION.to_owned(),
INT_TYPES_EXTENSION.to_owned(),
CONVERSIONS_EXTENSION.to_owned(),
FLOAT_OPS_EXTENSION.to_owned(),
FLOAT_TYPES_EXTENSION.to_owned(),
LOGICS_EXTENSION.to_owned(),
])
.unwrap();
}

/// Arguments for `run`.
#[derive(Parser, Debug)]
#[command(version, about)]
pub struct CmdLineArgs {
#[command(flatten)]
base: hugr_cli::CmdLineArgs,
}

impl CmdLineArgs {
/// Run the ngrte preparation and validation workflow with the given
/// registry.
pub fn run(&self, registry: &ExtensionRegistry) -> Result<(), hugr_cli::CliError> {
let mut hugr = self.base.run(registry)?;
crate::prepare_ngrte(&mut hugr).unwrap();
serde_json::to_writer_pretty(std::io::stdout(), &hugr)?;
Ok(())
}

/// Test whether a `level` message should be output.
pub fn verbosity(&self, level: hugr_cli::Level) -> bool {
self.base.verbosity(level)
}
}
14 changes: 14 additions & 0 deletions tket2-hseries/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Provides a preparation and validation workflow for Hugrs targeting
//! Quantinuum H-series quantum computers.
use hugr::Hugr;

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

/// Modify a [Hugr] into a form that is acceptable for input into ngrte.
///
/// Returns an error if this cannot be done.
pub fn prepare_ngrte(#[allow(unused)] hugr: &mut Hugr) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
16 changes: 16 additions & 0 deletions tket2-hseries/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! A command line interface to tket2-hseries
use tket2_hseries::cli;
use hugr_cli::{Parser as _, Level};

fn main() {
let opts = cli::CmdLineArgs::parse();
let registry = &cli::REGISTRY;

// validate with all std extensions
if let Err(e) = opts.run(registry) {
if opts.verbosity(Level::Error) {
eprintln!("{}", e);
}
std::process::exit(1);
}
}

0 comments on commit 8edcbe3

Please sign in to comment.