From 962b9fff881c2db1de6001257bb918820b71d847 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 18 Dec 2024 14:30:12 +0000 Subject: [PATCH] chore: use MonomorphizationPass --- Cargo.lock | 19 +++++++++---------- Cargo.toml | 10 +++++----- tket2-hseries/src/lib.rs | 19 +++++++++---------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b2ecdff..70b35f7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -969,8 +969,7 @@ dependencies = [ [[package]] name = "hugr" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f209c7cd671de29be8bdf0725e09b2e9d386387f439b13975e158f095e5a0fe" +source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" dependencies = [ "hugr-core", "hugr-passes", @@ -979,24 +978,20 @@ dependencies = [ [[package]] name = "hugr-cli" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab6a94a980d47788908d7f93165846164f8b623b7f382cd3813bd0c0d1188e65" +source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" dependencies = [ "clap", "clap-verbosity-flag", "clio", "derive_more 1.0.0", "hugr", - "serde", "serde_json", - "thiserror 2.0.6", ] [[package]] name = "hugr-core" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60c3d5422f76dbec1d6948e68544b134562ec9ec087e8e6a599555b716f555dc" +source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" dependencies = [ "bitvec", "bumpalo", @@ -1028,8 +1023,7 @@ dependencies = [ [[package]] name = "hugr-passes" version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2591767b6fe03074d38de7c4e61d52b37cb2e73b7340bf4ff957ad4554022a" +source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" dependencies = [ "ascent", "hugr-core", @@ -3052,3 +3046,8 @@ dependencies = [ "cc", "pkg-config", ] + +[[patch.unused]] +name = "hugr-model" +version = "0.15.0" +source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" diff --git a/Cargo.toml b/Cargo.toml index d3b32cf9..286777c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,11 +26,11 @@ missing_docs = "warn" [patch.crates-io] # Uncomment to use unreleased versions of hugr -#hugr = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" } -#hugr-core = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" } -#hugr-passes = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" } -#hugr-cli = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" } -#hugr-model = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" } +hugr = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" } +hugr-core = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" } +hugr-passes = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" } +hugr-cli = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" } +hugr-model = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" } [workspace.dependencies] diff --git a/tket2-hseries/src/lib.rs b/tket2-hseries/src/lib.rs index 5808afde..a7eb3401 100644 --- a/tket2-hseries/src/lib.rs +++ b/tket2-hseries/src/lib.rs @@ -1,13 +1,13 @@ //! Provides a preparation and validation workflow for Hugrs targeting //! Quantinuum H-series quantum computers. -use std::mem; use derive_more::{Display, Error, From}; use hugr::{ algorithms::{ const_fold::{ConstFoldError, ConstantFoldPass}, - force_order, monomorphize, remove_polyfuncs, + force_order, validation::{ValidatePassError, ValidationLevel}, + MonomorphizePass, }, hugr::HugrError, Hugr, HugrView, @@ -61,6 +61,8 @@ pub enum QSystemPassError { LowerTk2Error(LowerTk2Error), /// An error from the component [ConstantFoldPass] pass. ConstantFoldError(ConstFoldError), + /// An error from the component [MoomorphizePass] pass. + MonomorphizeError(hugr::algorithms::MonomorphizeError), } impl QSystemPass { @@ -68,14 +70,7 @@ impl QSystemPass { /// validation, if enabled. pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> { if self.monomorphize { - self.validation_level.run_validated_pass(hugr, |hugr, _| { - let mut owned_hugr = Hugr::default(); - mem::swap(&mut owned_hugr, hugr); - owned_hugr = remove_polyfuncs(monomorphize(owned_hugr)); - mem::swap(&mut owned_hugr, hugr); - - Ok::<_, QSystemPassError>(()) - })?; + self.monomorphization().run(hugr)?; } if self.constant_fold { @@ -113,6 +108,10 @@ impl QSystemPass { ConstantFoldPass::default().validation_level(self.validation_level) } + fn monomorphization(&self) -> MonomorphizePass { + MonomorphizePass::default().validation_level(self.validation_level) + } + /// Returns a new `QSystemPass` with the given [ValidationLevel]. pub fn with_validation_level(mut self, level: ValidationLevel) -> Self { self.validation_level = level;