Skip to content

Commit

Permalink
feat!: init tket2-hseries (#368)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: require `hugr-0.5.0`
  • Loading branch information
doug-q authored Jun 14, 2024
1 parent b0b8aff commit 61e7535
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 5 deletions.
80 changes: 78 additions & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 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 @@ -20,6 +20,7 @@ missing_docs = "warn"

tket2 = { path = "./tket2" }
hugr = "0.5.1"
hugr-cli = "0.1.1"
portgraph = "0.12"
pyo3 = "0.21.2"
itertools = "0.13.0"
Expand Down
9 changes: 9 additions & 0 deletions release-plz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ commit_parsers = [
[[package]]
name = "tket2"
release = true

[[package]]
name = "tket2-hseries"
release = true

# Disabled until the first version is manually published
publish = false
git_tag_enable = false
git_release_enable = false
Empty file added tket2-hseries/CHANGELOG.md
Empty file.
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-alpha.1"
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 = { path = "../tket2", version = "0.1.0-alpha.1" }
serde_json.workspace = true
lazy_static.workspace = true

[lints]
workspace = true

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

![msrv][]

A TKET2 tool for preparing and validating `Hugr`s for compilation targeting
Quantinuum H-series quantum computers.

## Usage

Install using `cargo`:

```bash
cargo install tket2-hseries
```

This will install the `tket2-hseries` binary.

## Recent Changes

See [CHANGELOG][] for a list of changes. The minimum supported rust
version will only change on major releases.

## Development

See [DEVELOPMENT.md][] for instructions on setting up the development environment.

## License

This project is licensed under Apache License, Version 2.0 ([LICENSE][] or http://www.apache.org/licenses/LICENSE-2.0).

[msrv]: https://img.shields.io/badge/rust-1.75.0%2B-blue.svg
[LICENSE]: https://github.com/CQCL/tket2/blob/main/LICENCE
[CHANGELOG]: https://github.com/CQCL/tket2/blob/main/tket2-hseries/CHANGELOG.mdd
[DEVELOPMENT.md]: https://github.com/CQCL/tket2/blob/main/DEVELOPMENT.md
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 ingress into an H-series.
///
/// 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 hugr_cli::{Level, Parser as _};
use tket2_hseries::cli;

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);
}
}
2 changes: 1 addition & 1 deletion tket2-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test = false
bench = false

[dependencies]
tket2 = { workspace = true, features = ["portmatching"] }
tket2 = { path = "../tket2", version = "0.1.0-alpha.1", features = ["portmatching"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tket-json-rs = { workspace = true, features = ["pyo3"] }
Expand Down

0 comments on commit 61e7535

Please sign in to comment.