From 962b9fff881c2db1de6001257bb918820b71d847 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 18 Dec 2024 14:30:12 +0000 Subject: [PATCH 1/4] 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; From be5c7cbe4b64ede7ed07d3bbe30b23ee8b77b634 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 18 Dec 2024 14:34:10 +0000 Subject: [PATCH 2/4] review comments --- tket2-hseries/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tket2-hseries/src/lib.rs b/tket2-hseries/src/lib.rs index a7eb3401..6a95198b 100644 --- a/tket2-hseries/src/lib.rs +++ b/tket2-hseries/src/lib.rs @@ -7,7 +7,7 @@ use hugr::{ const_fold::{ConstFoldError, ConstantFoldPass}, force_order, validation::{ValidatePassError, ValidationLevel}, - MonomorphizePass, + MonomorphizeError, MonomorphizePass, }, hugr::HugrError, Hugr, HugrView, @@ -61,8 +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), + /// An error from the component [MonomorphizePass] pass. + MonomorphizeError(MonomorphizeError), } impl QSystemPass { From 1a667eeb72080198e678e84d195e0d5ee413f5b0 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 18 Dec 2024 14:38:29 +0000 Subject: [PATCH 3/4] hugr versions --- Cargo.lock | 25 ++++++++++++------------- Cargo.toml | 16 ++++++++-------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70b35f7d..0d1ee308 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -968,8 +968,9 @@ dependencies = [ [[package]] name = "hugr" -version = "0.14.0" -source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1c8f4a7f778b70a6528fb620f9df31931d9eaad518287d7d25faabba8714f3f" dependencies = [ "hugr-core", "hugr-passes", @@ -977,8 +978,9 @@ dependencies = [ [[package]] name = "hugr-cli" -version = "0.14.0" -source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5906f571c65f74ec9f7aac92d1d52bf1a1837d736d4bd131d3d81b13c057068" dependencies = [ "clap", "clap-verbosity-flag", @@ -990,8 +992,9 @@ dependencies = [ [[package]] name = "hugr-core" -version = "0.14.0" -source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "967ce11e97050617c536d37c5b12d2b0eecb2f9f6da24e4bc5d19faf5cf1fafa" dependencies = [ "bitvec", "bumpalo", @@ -1022,8 +1025,9 @@ dependencies = [ [[package]] name = "hugr-passes" -version = "0.14.0" -source = "git+https://github.com/CQCL/hugr#ab94518ed2812abca615bfbfb5a822f67c115be8" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a12944d441477c4f086c106891fa22e5a29ac2fd011c0caf898e4d28aeb2a05" dependencies = [ "ascent", "hugr-core", @@ -3046,8 +3050,3 @@ 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 286777c5..f967f120 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,18 +26,18 @@ missing_docs = "warn" [patch.crates-io] # Uncomment to use unreleased versions of hugr -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" } +# 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] # Make sure to run `just recompile-eccs` if the hugr serialisation format changes. -hugr = "0.14.0" -hugr-core = "0.14.0" -hugr-cli = "0.14.0" +hugr = "0.14.1" +hugr-core = "0.14.1" +hugr-cli = "0.14.1" portgraph = "0.12" pyo3 = "0.23.3" itertools = "0.13.0" From 2938c30709b2529e0ffc48a4f3c2cd6f22b8d9d1 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 18 Dec 2024 14:53:22 +0000 Subject: [PATCH 4/4] revert polyfunc removal --- tket2-hseries/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tket2-hseries/src/lib.rs b/tket2-hseries/src/lib.rs index 6a95198b..44e1a853 100644 --- a/tket2-hseries/src/lib.rs +++ b/tket2-hseries/src/lib.rs @@ -1,11 +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, + force_order, remove_polyfuncs, validation::{ValidatePassError, ValidationLevel}, MonomorphizeError, MonomorphizePass, }, @@ -71,6 +73,13 @@ impl QSystemPass { pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> { if self.monomorphize { self.monomorphization().run(hugr)?; + self.validation_level.run_validated_pass(hugr, |hugr, _| { + let mut owned_hugr = Hugr::default(); + mem::swap(&mut owned_hugr, hugr); + owned_hugr = remove_polyfuncs(owned_hugr); + mem::swap(&mut owned_hugr, hugr); + Ok::<_, QSystemPassError>(()) + })?; } if self.constant_fold {