-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
192 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |