From 88e90103b8e2d3c1d5f0369c33dd80aef2c49bb8 Mon Sep 17 00:00:00 2001 From: Douglas Wilson <141026920+doug-q@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:43:39 +0100 Subject: [PATCH] chore: Bump to hugr-0.7.0 (#469) --- Cargo.lock | 21 +++++++++++---------- Cargo.toml | 7 +++---- badger-optimiser/Cargo.toml | 2 +- compile-rewriter/Cargo.toml | 2 +- tket2/src/circuit.rs | 9 +-------- tket2/src/circuit/extract_dfg.rs | 13 +++++++------ tket2/src/ops.rs | 11 ++++++----- 7 files changed, 30 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b89c3e87..e22426d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -259,9 +259,9 @@ dependencies = [ [[package]] name = "clap-stdin" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc126d12a0930c94c3548581294d5f19360ac02e408600b4d7619d7234e8b505" +checksum = "26aebacacd89c47b46d417017046e359921a2914e56b3abdb9caefac048405b1" dependencies = [ "thiserror", ] @@ -735,9 +735,9 @@ dependencies = [ [[package]] name = "hugr" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e9896b1c2f2760f71e05e8e56492e98f828e4abb17055055f851752c54720a" +checksum = "93a66a8749a4713a4421aaf479e9db1f281abbd7eaf2f03ae16e772c1b248f7c" dependencies = [ "hugr-core", "hugr-passes", @@ -745,9 +745,9 @@ dependencies = [ [[package]] name = "hugr-cli" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce7564fd98a98a3e6576b627f18294319e02664aa4765924defdc789062e5f6" +checksum = "b0cab2e45d6198f3a00eb8fe8951bb2cf6ecde81f562e021079a65b3aa0ee81f" dependencies = [ "clap", "clap-stdin", @@ -759,9 +759,9 @@ dependencies = [ [[package]] name = "hugr-core" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86da0c1e47982cb16d20911c33af448cae7b4aa36f1f5ff44753c38dbb152aae" +checksum = "fd3a6cde9950d93a466b63e43777651ecd8becccf2d9bffa857d77301a280541" dependencies = [ "bitvec", "cgmath", @@ -790,14 +790,15 @@ dependencies = [ [[package]] name = "hugr-passes" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ae0241e13fc66d944faaa7c25b4062336274e6d533a0da05b55fa9b8b601df" +checksum = "a034c5f270b5827418acee2e867423f57c030bb13685d715df12281865b78bda" dependencies = [ "hugr-core", "itertools 0.13.0", "lazy_static", "paste", + "petgraph", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index e80ea55f..84ca2f78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,9 @@ missing_docs = "warn" [workspace.dependencies] -tket2 = { path = "./tket2" } -hugr = "0.6.1" -hugr-cli = "0.1.2" -hugr-core = "0.3.1" +hugr = "0.7.0" +hugr-cli = "0.1.3" +hugr-core = "0.4.0" portgraph = "0.12" pyo3 = "0.21.2" itertools = "0.13.0" diff --git a/badger-optimiser/Cargo.toml b/badger-optimiser/Cargo.toml index 3f64a035..5ce0958d 100644 --- a/badger-optimiser/Cargo.toml +++ b/badger-optimiser/Cargo.toml @@ -12,7 +12,7 @@ publish = false [dependencies] clap = { workspace = true, features = ["derive"] } serde_json = { workspace = true } -tket2 = { workspace = true, features = ["portmatching", "rewrite-tracing"] } +tket2 = { path = "../tket2", features = ["portmatching", "rewrite-tracing"] } hugr = { workspace = true } itertools = { workspace = true } tket-json-rs = { workspace = true } diff --git a/compile-rewriter/Cargo.toml b/compile-rewriter/Cargo.toml index 1fe86945..b4811bea 100644 --- a/compile-rewriter/Cargo.toml +++ b/compile-rewriter/Cargo.toml @@ -9,6 +9,6 @@ publish = false [dependencies] clap = { workspace = true, features = ["derive"] } -tket2 = { workspace = true, features = ["portmatching"] } +tket2 = { path = "../tket2", features = ["portmatching"] } hugr = { workspace = true } itertools = { workspace = true } diff --git a/tket2/src/circuit.rs b/tket2/src/circuit.rs index f6cb2682..e03d84e8 100644 --- a/tket2/src/circuit.rs +++ b/tket2/src/circuit.rs @@ -11,7 +11,6 @@ use std::iter::Sum; pub use command::{Command, CommandIterator}; pub use hash::CircuitHash; use hugr::hugr::views::{DescendantsGraph, ExtractHugr, HierarchyView}; -use hugr_core::hugr::internal::HugrMutInternals; use itertools::Either::{Left, Right}; use hugr::hugr::hugrmut::HugrMut; @@ -123,8 +122,6 @@ impl Circuit { } /// Returns the function type of the circuit. - /// - /// Equivalent to [`HugrView::get_function_type`]. #[inline] pub fn circuit_signature(&self) -> FunctionType { let op = self.hugr.get_optype(self.parent); @@ -317,11 +314,7 @@ impl Circuit { } else { let view: DescendantsGraph = DescendantsGraph::try_new(&self.hugr, self.parent) .expect("Circuit parent was not a dataflow container."); - let mut hugr = view.extract_hugr(); - // TODO: Remove this once hugr 0.6.0 gets released. - // https://github.com/CQCL/hugr/pull/1239 - hugr.set_num_ports(hugr.root(), 0, 0); - hugr.into() + view.extract_hugr().into() }; extract_dfg::rewrite_into_dfg(&mut circ)?; Ok(circ) diff --git a/tket2/src/circuit/extract_dfg.rs b/tket2/src/circuit/extract_dfg.rs index c5b5bb72..7cbec647 100644 --- a/tket2/src/circuit/extract_dfg.rs +++ b/tket2/src/circuit/extract_dfg.rs @@ -24,8 +24,7 @@ pub(super) fn rewrite_into_dfg(circ: &mut Circuit) -> Result<(), CircuitMutError _ => signature, }; - let dfg = DFG { signature }; - circ.hugr.replace_op(circ.parent(), OpType::DFG(dfg))?; + circ.hugr.replace_op(circ.parent(), DFG { signature })?; Ok(()) } @@ -81,10 +80,12 @@ fn remove_cfg_empty_output_tuple( // Add a new output node. let new_types = output_sig.input[1..].to_vec(); - let new_op = Output { - types: new_types.clone().into(), - }; - let new_node = hugr.add_node_after(input_node, new_op); + let new_node = hugr.add_node_after( + input_node, + Output { + types: new_types.clone().into(), + }, + ); // Reconnect the outputs. for (i, (neigh, port)) in input_neighs.into_iter().enumerate() { diff --git a/tket2/src/ops.rs b/tket2/src/ops.rs index 6565bf5e..080ba287 100644 --- a/tket2/src/ops.rs +++ b/tket2/src/ops.rs @@ -138,6 +138,10 @@ impl MakeOpDef for Tk2Op { .into() } + fn extension(&self) -> ExtensionId { + EXTENSION_ID.to_owned() + } + fn post_opdef(&self, def: &mut OpDef) { def.add_misc( "commutation", @@ -146,7 +150,7 @@ impl MakeOpDef for Tk2Op { } fn from_def(op_def: &OpDef) -> Result { - try_from_name(op_def.name()) + try_from_name(op_def.name(), &EXTENSION_ID) } } @@ -244,10 +248,7 @@ impl TryFrom<&OpType> for Tk2Op { match custom_op { CustomOp::Extension(ext) => Tk2Op::from_extension_op(ext).ok(), - CustomOp::Opaque(opaque) => match opaque.extension() == &EXTENSION_ID { - true => try_from_name(opaque.name()).ok(), - false => None, - }, + CustomOp::Opaque(opaque) => try_from_name(opaque.name(), &EXTENSION_ID).ok(), } .ok_or_else(|| NotTk2Op { op: op.clone() }) }