From d854cf7a4c5a9e41eed8794fd033f585c86859cd Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Tue, 4 Feb 2025 15:01:29 +0000 Subject: [PATCH 1/9] fix: Fix nondeterminism in lazify-measure --- devenv.lock | 49 +++++++++++++++-------------- devenv.nix | 2 ++ tket2-hseries/src/lazify_measure.rs | 6 ++-- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/devenv.lock b/devenv.lock index 7b0123a1..216137da 100644 --- a/devenv.lock +++ b/devenv.lock @@ -51,10 +51,31 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737465171, + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ - "pre-commit-hooks", + "git-hooks", "nixpkgs" ] }, @@ -101,34 +122,16 @@ "type": "github" } }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1735882644, - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, "root": { "inputs": { "devenv": "devenv", "fenix": "fenix", + "git-hooks": "git-hooks", "nixpkgs": "nixpkgs", "nixpkgs-2305": "nixpkgs-2305", - "pre-commit-hooks": "pre-commit-hooks" + "pre-commit-hooks": [ + "git-hooks" + ] } }, "rust-analyzer-src": { diff --git a/devenv.nix b/devenv.nix index 22057761..edae8939 100644 --- a/devenv.nix +++ b/devenv.nix @@ -53,7 +53,9 @@ in enable = true; uv = { enable = true; + sync.enable = true; }; + venv.enable = true; }; } diff --git a/tket2-hseries/src/lazify_measure.rs b/tket2-hseries/src/lazify_measure.rs index e1e0c2f5..d4b899f0 100644 --- a/tket2-hseries/src/lazify_measure.rs +++ b/tket2-hseries/src/lazify_measure.rs @@ -125,7 +125,8 @@ impl LazifyMeasureRewrite { Self::check_signature(node, QSystemOp::LazyMeasure, hugr.get_optype(node))?; let subgraph = SiblingSubgraph::from_node(node, &hugr); - let uses = hugr.linked_inputs(node, 0).collect_vec(); + let mut uses = hugr.linked_inputs(node, 0).collect_vec(); + uses.sort(); let (lazy_measure_node, replacement) = { let bool_uses = uses.len(); let mut builder = @@ -165,7 +166,8 @@ impl LazifyMeasureRewrite { Self::check_signature(node, QSystemOp::LazyMeasureReset, hugr.get_optype(node))?; let subgraph = SiblingSubgraph::from_node(node, &hugr); - let uses = hugr.linked_inputs(node, 1).collect_vec(); + let mut uses = hugr.linked_inputs(node, 1).collect_vec(); + uses.sort(); let (lazy_measure_reset_node, replacement) = { let bool_uses = uses.len(); let mut builder = { From c28a4820620c24ba675aa281e9e2a1ad0b0a78ef Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Thu, 6 Feb 2025 10:30:24 +0000 Subject: [PATCH 2/9] revert devnix changes --- devenv.lock | 49 +++++++++++++++++++++++-------------------------- devenv.nix | 2 -- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/devenv.lock b/devenv.lock index 216137da..7b0123a1 100644 --- a/devenv.lock +++ b/devenv.lock @@ -51,31 +51,10 @@ "type": "github" } }, - "git-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1737465171, - "owner": "cachix", - "repo": "git-hooks.nix", - "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "git-hooks.nix", - "type": "github" - } - }, "gitignore": { "inputs": { "nixpkgs": [ - "git-hooks", + "pre-commit-hooks", "nixpkgs" ] }, @@ -122,16 +101,34 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1735882644, + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "devenv": "devenv", "fenix": "fenix", - "git-hooks": "git-hooks", "nixpkgs": "nixpkgs", "nixpkgs-2305": "nixpkgs-2305", - "pre-commit-hooks": [ - "git-hooks" - ] + "pre-commit-hooks": "pre-commit-hooks" } }, "rust-analyzer-src": { diff --git a/devenv.nix b/devenv.nix index edae8939..22057761 100644 --- a/devenv.nix +++ b/devenv.nix @@ -53,9 +53,7 @@ in enable = true; uv = { enable = true; - sync.enable = true; }; - venv.enable = true; }; } From 470f3de64db27acbca50d1eb24773c8d311fc507 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Thu, 6 Feb 2025 10:34:37 +0000 Subject: [PATCH 3/9] comments --- tket2-hseries/src/lazify_measure.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tket2-hseries/src/lazify_measure.rs b/tket2-hseries/src/lazify_measure.rs index d4b899f0..52f0251f 100644 --- a/tket2-hseries/src/lazify_measure.rs +++ b/tket2-hseries/src/lazify_measure.rs @@ -125,8 +125,14 @@ impl LazifyMeasureRewrite { Self::check_signature(node, QSystemOp::LazyMeasure, hugr.get_optype(node))?; let subgraph = SiblingSubgraph::from_node(node, &hugr); - let mut uses = hugr.linked_inputs(node, 0).collect_vec(); - uses.sort(); + let uses = { + // SimpleReplacement adds edges in a nondeterministic order. This + // results in linked_inputs returning items in a nondeterministic + // order. We sort them here to restore determinism. + let mut v = hugr.linked_inputs(node, 1).collect_vec(); + v.sort(); + v + }; let (lazy_measure_node, replacement) = { let bool_uses = uses.len(); let mut builder = @@ -166,8 +172,12 @@ impl LazifyMeasureRewrite { Self::check_signature(node, QSystemOp::LazyMeasureReset, hugr.get_optype(node))?; let subgraph = SiblingSubgraph::from_node(node, &hugr); - let mut uses = hugr.linked_inputs(node, 1).collect_vec(); - uses.sort(); + let uses = { + // See comment in try_new_measure + let mut v = hugr.linked_inputs(node, 1).collect_vec(); + v.sort(); + v + }; let (lazy_measure_reset_node, replacement) = { let bool_uses = uses.len(); let mut builder = { From 29ce1e3c434a831bf844c8ce811ebad2eb42c9e8 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Thu, 6 Feb 2025 11:16:00 +0000 Subject: [PATCH 4/9] fixup --- tket2-hseries/src/lazify_measure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tket2-hseries/src/lazify_measure.rs b/tket2-hseries/src/lazify_measure.rs index 52f0251f..35d38086 100644 --- a/tket2-hseries/src/lazify_measure.rs +++ b/tket2-hseries/src/lazify_measure.rs @@ -129,7 +129,7 @@ impl LazifyMeasureRewrite { // SimpleReplacement adds edges in a nondeterministic order. This // results in linked_inputs returning items in a nondeterministic // order. We sort them here to restore determinism. - let mut v = hugr.linked_inputs(node, 1).collect_vec(); + let mut v = hugr.linked_inputs(node, 0).collect_vec(); v.sort(); v }; From d5f0d2cfc40ec3c1476b049f2ccb18cce4bba531 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Thu, 6 Feb 2025 14:48:31 +0000 Subject: [PATCH 5/9] add unnonlocalpass --- Cargo.lock | 9 +------- Cargo.toml | 8 +++---- devenv.lock | 49 +++++++++++++++++++++------------------- tket2-hseries/src/lib.rs | 27 ++++++++++++++++++---- 4 files changed, 54 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa561b0c..d208fc4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -917,8 +917,6 @@ dependencies = [ [[package]] name = "hugr" version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e8fb919d87dd5b9c1ba077a289c765b6e184c832768fb4a5dc9e1e05793564" dependencies = [ "hugr-core", "hugr-passes", @@ -927,8 +925,6 @@ dependencies = [ [[package]] name = "hugr-cli" version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "207ce216fc76a3f2e56bb27483502468d6b8758e6c7a8a777cdf8d64459043cf" dependencies = [ "clap", "clap-verbosity-flag", @@ -941,8 +937,6 @@ dependencies = [ [[package]] name = "hugr-core" version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79da6020b18a6c63bd81acb9b86370820ba63062519b9d10ed75a0561f3143d1" dependencies = [ "bitvec", "bumpalo", @@ -974,10 +968,9 @@ dependencies = [ [[package]] name = "hugr-passes" version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86dff9354c0133cddd4f9060af2f4ec531dc479c1a65ed5474785f5b39478422" dependencies = [ "ascent", + "derive_more 1.0.0", "hugr-core", "itertools 0.14.0", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 120505f2..a0bea57d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,10 @@ missing_docs = "warn" [patch.crates-io] # Uncomment to use unreleased versions of hugr -# hugr = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } -# hugr-core = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } -# hugr-passes = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } -# hugr-cli = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } +hugr.path = "../hugr/hugr" +hugr-core.path = "../hugr/hugr-core" +hugr-passes.path = "../hugr/hugr-passes" +hugr-cli.path = "../hugr/hugr-cli" # hugr-model = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } # portgraph = { git = "https://github.com/CQCL/portgraph", rev = "68b96ac737e0c285d8c543b2d74a7aa80a18202c" } diff --git a/devenv.lock b/devenv.lock index 7b0123a1..216137da 100644 --- a/devenv.lock +++ b/devenv.lock @@ -51,10 +51,31 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737465171, + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ - "pre-commit-hooks", + "git-hooks", "nixpkgs" ] }, @@ -101,34 +122,16 @@ "type": "github" } }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1735882644, - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, "root": { "inputs": { "devenv": "devenv", "fenix": "fenix", + "git-hooks": "git-hooks", "nixpkgs": "nixpkgs", "nixpkgs-2305": "nixpkgs-2305", - "pre-commit-hooks": "pre-commit-hooks" + "pre-commit-hooks": [ + "git-hooks" + ] } }, "rust-analyzer-src": { diff --git a/tket2-hseries/src/lib.rs b/tket2-hseries/src/lib.rs index c378f888..4df394b5 100644 --- a/tket2-hseries/src/lib.rs +++ b/tket2-hseries/src/lib.rs @@ -4,10 +4,7 @@ use derive_more::{Display, Error, From}; use hugr::{ algorithms::{ - const_fold::{ConstFoldError, ConstantFoldPass}, - force_order, - validation::{ValidatePassError, ValidationLevel}, - MonomorphizeError, MonomorphizePass, RemoveDeadFuncsError, RemoveDeadFuncsPass, + const_fold::{ConstFoldError, ConstantFoldPass}, force_order, non_local::{NonLocalEdgesError, UnNonLocalPass}, validation::{ValidatePassError, ValidationLevel}, MonomorphizeError, MonomorphizePass, RemoveDeadFuncsError, RemoveDeadFuncsPass }, hugr::HugrError, Hugr, HugrView, @@ -37,6 +34,7 @@ pub struct QSystemPass { monomorphize: bool, force_order: bool, lazify: bool, + unnonlocal: bool, } impl Default for QSystemPass { @@ -47,6 +45,7 @@ impl Default for QSystemPass { monomorphize: true, force_order: true, lazify: true, + unnonlocal: true, } } } @@ -72,6 +71,8 @@ pub enum QSystemPassError { /// /// [RemoveDeadFuncsPass]: hugr::algorithms::RemoveDeadFuncsError DCEError(RemoveDeadFuncsError), + /// TODO docs + UnNonLocalError(NonLocalEdgesError), /// No [FuncDefn] named "main" in [Module]. /// /// [FuncDefn]: hugr::ops::FuncDefn @@ -84,6 +85,10 @@ impl QSystemPass { /// Run `QSystemPass` on the given [Hugr]. `registry` is used for /// validation, if enabled. pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> { + if self.unnonlocal { + self.unnonlocal().run(hugr)?; + } + if self.monomorphize { self.monomorphization().run(hugr)?; @@ -172,6 +177,12 @@ impl QSystemPass { MonomorphizePass::default().validation_level(self.validation_level) } + fn unnonlocal(&self) -> UnNonLocalPass { + UnNonLocalPass::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; @@ -218,6 +229,14 @@ impl QSystemPass { self.lazify = lazify; self } + + /// TODO docs + pub fn with_unnonlocal(self, unnonlocal: bool) -> Self { + Self { + unnonlocal, + ..self + } + } } #[cfg(test)] From f056ae4ec1ac4b815d3bdee7d36c6ba2ad470a5c Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Thu, 6 Feb 2025 14:56:39 +0000 Subject: [PATCH 6/9] pin to git not local path --- Cargo.lock | 4 ++++ Cargo.toml | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d208fc4f..9a3061ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -917,6 +917,7 @@ dependencies = [ [[package]] name = "hugr" version = "0.14.3" +source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" dependencies = [ "hugr-core", "hugr-passes", @@ -925,6 +926,7 @@ dependencies = [ [[package]] name = "hugr-cli" version = "0.14.3" +source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" dependencies = [ "clap", "clap-verbosity-flag", @@ -937,6 +939,7 @@ dependencies = [ [[package]] name = "hugr-core" version = "0.14.3" +source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" dependencies = [ "bitvec", "bumpalo", @@ -968,6 +971,7 @@ dependencies = [ [[package]] name = "hugr-passes" version = "0.14.3" +source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" dependencies = [ "ascent", "derive_more 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index a0bea57d..8e347c1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,10 @@ missing_docs = "warn" [patch.crates-io] # Uncomment to use unreleased versions of hugr -hugr.path = "../hugr/hugr" -hugr-core.path = "../hugr/hugr-core" -hugr-passes.path = "../hugr/hugr-passes" -hugr-cli.path = "../hugr/hugr-cli" +hugr = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} +hugr-core = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} +hugr-passes = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} +hugr-cli = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} # hugr-model = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } # portgraph = { git = "https://github.com/CQCL/portgraph", rev = "68b96ac737e0c285d8c543b2d74a7aa80a18202c" } From 1ebb2c014f30d0518a9d789649184bd62d26a10a Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Wed, 12 Feb 2025 13:07:00 +0000 Subject: [PATCH 7/9] Revert "add unnonlocalpass" This reverts commit 970ebb4c0667da87c80cbbc8caf7c10fa90b50ca. --- Cargo.lock | 13 +++++++---- Cargo.toml | 8 +++---- devenv.lock | 49 +++++++++++++++++++--------------------- tket2-hseries/src/lib.rs | 27 ++++------------------ 4 files changed, 39 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a3061ad..aa561b0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -917,7 +917,8 @@ dependencies = [ [[package]] name = "hugr" version = "0.14.3" -source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e8fb919d87dd5b9c1ba077a289c765b6e184c832768fb4a5dc9e1e05793564" dependencies = [ "hugr-core", "hugr-passes", @@ -926,7 +927,8 @@ dependencies = [ [[package]] name = "hugr-cli" version = "0.14.3" -source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "207ce216fc76a3f2e56bb27483502468d6b8758e6c7a8a777cdf8d64459043cf" dependencies = [ "clap", "clap-verbosity-flag", @@ -939,7 +941,8 @@ dependencies = [ [[package]] name = "hugr-core" version = "0.14.3" -source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79da6020b18a6c63bd81acb9b86370820ba63062519b9d10ed75a0561f3143d1" dependencies = [ "bitvec", "bumpalo", @@ -971,10 +974,10 @@ dependencies = [ [[package]] name = "hugr-passes" version = "0.14.3" -source = "git+https://github.com/CQCL/hugr?branch=doug/un-non-local#cd2348d576a7d45ff576677a3a7d262273f100d3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86dff9354c0133cddd4f9060af2f4ec531dc479c1a65ed5474785f5b39478422" dependencies = [ "ascent", - "derive_more 1.0.0", "hugr-core", "itertools 0.14.0", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 8e347c1b..120505f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,10 @@ missing_docs = "warn" [patch.crates-io] # Uncomment to use unreleased versions of hugr -hugr = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} -hugr-core = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} -hugr-passes = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} -hugr-cli = { git = "https://github.com/CQCL/hugr", branch = "doug/un-non-local"} +# hugr = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } +# hugr-core = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } +# hugr-passes = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } +# hugr-cli = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } # hugr-model = { git = "https://github.com/CQCL/hugr", rev = "09bd748398ce5afb39f5628d838756ccc03fc775" } # portgraph = { git = "https://github.com/CQCL/portgraph", rev = "68b96ac737e0c285d8c543b2d74a7aa80a18202c" } diff --git a/devenv.lock b/devenv.lock index 216137da..7b0123a1 100644 --- a/devenv.lock +++ b/devenv.lock @@ -51,31 +51,10 @@ "type": "github" } }, - "git-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1737465171, - "owner": "cachix", - "repo": "git-hooks.nix", - "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "git-hooks.nix", - "type": "github" - } - }, "gitignore": { "inputs": { "nixpkgs": [ - "git-hooks", + "pre-commit-hooks", "nixpkgs" ] }, @@ -122,16 +101,34 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1735882644, + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "devenv": "devenv", "fenix": "fenix", - "git-hooks": "git-hooks", "nixpkgs": "nixpkgs", "nixpkgs-2305": "nixpkgs-2305", - "pre-commit-hooks": [ - "git-hooks" - ] + "pre-commit-hooks": "pre-commit-hooks" } }, "rust-analyzer-src": { diff --git a/tket2-hseries/src/lib.rs b/tket2-hseries/src/lib.rs index 4df394b5..c378f888 100644 --- a/tket2-hseries/src/lib.rs +++ b/tket2-hseries/src/lib.rs @@ -4,7 +4,10 @@ use derive_more::{Display, Error, From}; use hugr::{ algorithms::{ - const_fold::{ConstFoldError, ConstantFoldPass}, force_order, non_local::{NonLocalEdgesError, UnNonLocalPass}, validation::{ValidatePassError, ValidationLevel}, MonomorphizeError, MonomorphizePass, RemoveDeadFuncsError, RemoveDeadFuncsPass + const_fold::{ConstFoldError, ConstantFoldPass}, + force_order, + validation::{ValidatePassError, ValidationLevel}, + MonomorphizeError, MonomorphizePass, RemoveDeadFuncsError, RemoveDeadFuncsPass, }, hugr::HugrError, Hugr, HugrView, @@ -34,7 +37,6 @@ pub struct QSystemPass { monomorphize: bool, force_order: bool, lazify: bool, - unnonlocal: bool, } impl Default for QSystemPass { @@ -45,7 +47,6 @@ impl Default for QSystemPass { monomorphize: true, force_order: true, lazify: true, - unnonlocal: true, } } } @@ -71,8 +72,6 @@ pub enum QSystemPassError { /// /// [RemoveDeadFuncsPass]: hugr::algorithms::RemoveDeadFuncsError DCEError(RemoveDeadFuncsError), - /// TODO docs - UnNonLocalError(NonLocalEdgesError), /// No [FuncDefn] named "main" in [Module]. /// /// [FuncDefn]: hugr::ops::FuncDefn @@ -85,10 +84,6 @@ impl QSystemPass { /// Run `QSystemPass` on the given [Hugr]. `registry` is used for /// validation, if enabled. pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> { - if self.unnonlocal { - self.unnonlocal().run(hugr)?; - } - if self.monomorphize { self.monomorphization().run(hugr)?; @@ -177,12 +172,6 @@ impl QSystemPass { MonomorphizePass::default().validation_level(self.validation_level) } - fn unnonlocal(&self) -> UnNonLocalPass { - UnNonLocalPass::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; @@ -229,14 +218,6 @@ impl QSystemPass { self.lazify = lazify; self } - - /// TODO docs - pub fn with_unnonlocal(self, unnonlocal: bool) -> Self { - Self { - unnonlocal, - ..self - } - } } #[cfg(test)] From 8505d4ee60738ea06b6c6776c198d6aafb099f57 Mon Sep 17 00:00:00 2001 From: Douglas Wilson <141026920+doug-q@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:35:10 +0000 Subject: [PATCH 8/9] Update tket2-hseries/src/lazify_measure.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Agustín Borgna --- tket2-hseries/src/lazify_measure.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tket2-hseries/src/lazify_measure.rs b/tket2-hseries/src/lazify_measure.rs index 35d38086..7d2d277d 100644 --- a/tket2-hseries/src/lazify_measure.rs +++ b/tket2-hseries/src/lazify_measure.rs @@ -172,12 +172,8 @@ impl LazifyMeasureRewrite { Self::check_signature(node, QSystemOp::LazyMeasureReset, hugr.get_optype(node))?; let subgraph = SiblingSubgraph::from_node(node, &hugr); - let uses = { - // See comment in try_new_measure - let mut v = hugr.linked_inputs(node, 1).collect_vec(); - v.sort(); - v - }; + // See comment in try_new_measure + let uses = hugr.linked_inputs(node, 1).sorted().collect_vec(); let (lazy_measure_reset_node, replacement) = { let bool_uses = uses.len(); let mut builder = { From 510715fef843c6dab7abbb4d7ac105670b682ba9 Mon Sep 17 00:00:00 2001 From: Douglas Wilson <141026920+doug-q@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:35:25 +0000 Subject: [PATCH 9/9] Update tket2-hseries/src/lazify_measure.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Agustín Borgna --- tket2-hseries/src/lazify_measure.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tket2-hseries/src/lazify_measure.rs b/tket2-hseries/src/lazify_measure.rs index 7d2d277d..7a233ced 100644 --- a/tket2-hseries/src/lazify_measure.rs +++ b/tket2-hseries/src/lazify_measure.rs @@ -125,14 +125,10 @@ impl LazifyMeasureRewrite { Self::check_signature(node, QSystemOp::LazyMeasure, hugr.get_optype(node))?; let subgraph = SiblingSubgraph::from_node(node, &hugr); - let uses = { - // SimpleReplacement adds edges in a nondeterministic order. This - // results in linked_inputs returning items in a nondeterministic - // order. We sort them here to restore determinism. - let mut v = hugr.linked_inputs(node, 0).collect_vec(); - v.sort(); - v - }; + // SimpleReplacement adds edges in a nondeterministic order. This + // results in linked_inputs returning items in a nondeterministic + // order. We sort them here to restore determinism. + let uses = hugr.linked_inputs(node, 0).sorted().collect_vec(); let (lazy_measure_node, replacement) = { let bool_uses = uses.len(); let mut builder =