diff --git a/Cargo.lock b/Cargo.lock index 7d74d08e..d6c08ab1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,9 +185,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cast" @@ -197,9 +197,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.29" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58e804ac3194a48bb129643eb1d62fcc20d18c6b8c181704489353d13120bcd1" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ "jobserver", "libc", @@ -317,7 +317,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -539,7 +539,7 @@ checksum = "4e018fccbeeb50ff26562ece792ed06659b9c2dae79ece77c4456bb10d9bf79b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -550,7 +550,7 @@ checksum = "bc2323e10c92e1cf4d86e11538512e6dc03ceb586842970b6332af3d4046a046" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -572,7 +572,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -592,7 +592,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "unicode-xid", ] @@ -627,7 +627,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -739,7 +739,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -857,9 +857,9 @@ dependencies = [ [[package]] name = "hugr" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1591e9f21f7c32c1b6f25bc85239d607fe86d39d8913dd5fa24c26c8bb2859" +checksum = "a4d3b355ab819143e7dd85bda162f1a496fbbf8485a4bb1ff55f5dd52b031fca" dependencies = [ "hugr-core", "hugr-passes", @@ -867,14 +867,15 @@ dependencies = [ [[package]] name = "hugr-cli" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510dc98333646f9a9cecd9443055a83b9f09cdd72a9cb0a8fab2b740e304d478" +checksum = "3407f8549502a9b8905db5b1ec5dd70bfc05b072313a3f2381ec3414f450f80d" dependencies = [ "clap", "clap-verbosity-flag", "clio", - "hugr-core", + "derive_more 1.0.0", + "hugr", "serde", "serde_json", "thiserror", @@ -882,9 +883,9 @@ dependencies = [ [[package]] name = "hugr-core" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c692210006389030fe0cab753c0982e62d0d45b0ee366b748d8c568593f639" +checksum = "a86a0796418a62b4cd83c3776021ec46671142fd46b5d355e2078db4c8d286c3" dependencies = [ "bitvec", "bumpalo", @@ -916,9 +917,9 @@ dependencies = [ [[package]] name = "hugr-passes" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "050a23a7f4226712bcefa3d115c102647ed9e95709b284eecc115233dc9e6bfc" +checksum = "f8a375f48c93f2839faad0a2ab6a58c4c88ad656d70398dbd6b45e6371362348" dependencies = [ "hugr-core", "itertools 0.13.0", @@ -1078,9 +1079,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "linux-raw-sys" @@ -1291,7 +1292,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1441,9 +1442,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] @@ -1495,7 +1496,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1508,7 +1509,7 @@ dependencies = [ "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1639,7 +1640,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.79", + "syn 2.0.82", "unicode-ident", ] @@ -1673,9 +1674,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "ryu" @@ -1703,22 +1704,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.211" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "1ac55e59090389fb9f0dd9e0f3c09615afed1d19094284d0b200441f13550793" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.211" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "54be4f245ce16bc58d57ef2716271d0d4519e0f6defa147f6e081005bcb278ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1812,7 +1813,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1828,9 +1829,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" dependencies = [ "proc-macro2", "quote", @@ -1879,7 +1880,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1998,7 +1999,6 @@ dependencies = [ "downcast-rs", "fxhash", "hugr", - "hugr-cli", "hugr-core", "indexmap", "itertools 0.13.0", @@ -2055,7 +2055,6 @@ dependencies = [ "cool_asserts", "derive_more 1.0.0", "hugr", - "hugr-cli", "itertools 0.13.0", "num_cpus", "portgraph 0.12.2", @@ -2117,7 +2116,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2188,7 +2187,7 @@ checksum = "70b20a22c42c8f1cd23ce5e34f165d4d37038f5b663ad20fb6adbdf029172483" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2261,9 +2260,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "serde", ] @@ -2312,7 +2311,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-shared", ] @@ -2334,7 +2333,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index cf13f4f0..212d621f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,9 @@ missing_docs = "warn" [workspace.dependencies] # Make sure to run `just recompile-eccs` if the hugr serialisation format changes. -hugr = "0.13.1" -hugr-core = "0.13.1" -hugr-cli = "0.13.1" +hugr = "0.13.2" +hugr-core = "0.13.2" +hugr-cli = "0.13.2" portgraph = "0.12" pyo3 = "0.22.5" itertools = "0.13.0" diff --git a/tket2-py/Cargo.toml b/tket2-py/Cargo.toml index 80ea025e..8ceeb6b5 100644 --- a/tket2-py/Cargo.toml +++ b/tket2-py/Cargo.toml @@ -34,9 +34,6 @@ derive_more = { workspace = true, features = ["into", "from"] } itertools = { workspace = true } portmatching = { workspace = true } strum = { workspace = true } -# Required to acces the `Package` type. -# Remove once https://github.com/CQCL/hugr/issues/1530 is fixed. -hugr-cli = { workspace = true } [dev-dependencies] rstest = { workspace = true } diff --git a/tket2-py/src/circuit/tk2circuit.rs b/tket2-py/src/circuit/tk2circuit.rs index 91ff0993..7677b336 100644 --- a/tket2-py/src/circuit/tk2circuit.rs +++ b/tket2-py/src/circuit/tk2circuit.rs @@ -8,8 +8,8 @@ use hugr::extension::prelude::QB_T; use hugr::extension::{ExtensionRegistry, EMPTY_REG}; use hugr::ops::handle::NodeHandle; use hugr::ops::{ExtensionOp, NamedOp, OpType}; +use hugr::package::Package; use hugr::types::Type; -use hugr_cli::Package; use itertools::Itertools; use pyo3::exceptions::{PyAttributeError, PyValueError}; use pyo3::types::{PyAnyMethods, PyModule, PyString, PyTypeMethods}; @@ -97,20 +97,18 @@ impl Tk2Circuit { /// Decode a HUGR json string to a circuit. #[staticmethod] pub fn from_hugr_json(json: &str) -> PyResult { - let pkg: Package = serde_json::from_str(json) + let mut pkg: Package = serde_json::from_str(json) .map_err(|e| PyErr::new::(format!("Invalid encoded HUGR: {e}")))?; let mut reg = REGISTRY.clone(); - let mut hugrs = pkg.validate(&mut reg).map_err(|e| { + pkg.update_validate(&mut reg).map_err(|e| { PyErr::new::(format!("Invalid encoded circuit: {e}")) })?; - if hugrs.len() != 1 { + let Ok(hugr) = pkg.modules.into_iter().exactly_one() else { return Err(PyValueError::new_err( "Invalid HUGR json: Package must contain exactly one hugr.", )); - } - Ok(Tk2Circuit { - circ: mem::take(&mut hugrs[0]).into(), - }) + }; + Ok(Tk2Circuit { circ: hugr.into() }) } /// Load a function from a compiled guppy module, encoded as a json string. diff --git a/tket2/Cargo.toml b/tket2/Cargo.toml index ca92ca5a..457d496e 100644 --- a/tket2/Cargo.toml +++ b/tket2/Cargo.toml @@ -72,9 +72,6 @@ tracing = { workspace = true } pest = { workspace = true } pest_derive = { workspace = true } zstd = { workspace = true, optional = true } -# Required to acces the `Package` type. -# Remove once https://github.com/CQCL/hugr/issues/1530 is fixed. -hugr-cli = { workspace = true } [dev-dependencies] diff --git a/tket2/src/circuit/extract_dfg.rs b/tket2/src/circuit/extract_dfg.rs index 38b12d85..ce2cf0a9 100644 --- a/tket2/src/circuit/extract_dfg.rs +++ b/tket2/src/circuit/extract_dfg.rs @@ -24,6 +24,11 @@ pub(super) fn rewrite_into_dfg(circ: &mut Circuit) -> Result<(), CircuitMutError _ => signature, }; + circ.hugr.set_num_ports( + circ.parent(), + signature.input_count() + 1, + signature.input_count() + 1, + ); circ.hugr.replace_op(circ.parent(), DFG { signature })?; Ok(()) diff --git a/tket2/src/serialize/guppy.rs b/tket2/src/serialize/guppy.rs index f1d48a77..a85accee 100644 --- a/tket2/src/serialize/guppy.rs +++ b/tket2/src/serialize/guppy.rs @@ -1,12 +1,12 @@ //! Load pre-compiled guppy functions. use std::path::Path; -use std::{fs, io, mem}; +use std::{fs, io}; use derive_more::{Display, Error, From}; use hugr::ops::{NamedOp, OpTag, OpTrait, OpType}; +use hugr::package::{Package, PackageValidationError}; use hugr::{Hugr, HugrView}; -use hugr_cli::Package; use itertools::Itertools; use crate::extension::REGISTRY; @@ -33,12 +33,12 @@ pub fn load_guppy_json_reader( reader: impl io::Read, function: &str, ) -> Result { - let pkg: Package = serde_json::from_reader(reader)?; - let mut hugrs = pkg.validate(&mut REGISTRY.clone())?; - if hugrs.len() != 1 { - return Err(CircuitLoadError::InvalidNumHugrs { count: hugrs.len() }); - } - let hugr = mem::take(&mut hugrs[0]); + let mut pkg: Package = serde_json::from_reader(reader)?; + pkg.update_validate(&mut REGISTRY.clone())?; + let count = pkg.modules.len(); + let Ok(hugr) = pkg.modules.into_iter().exactly_one() else { + return Err(CircuitLoadError::InvalidNumHugrs { count }); + }; find_function(hugr, function) } @@ -151,9 +151,8 @@ pub enum CircuitLoadError { #[from] CircuitLoadError(CircuitError), /// Error validating the loaded circuit. - #[display("{_0}")] #[from] - ValError(hugr_cli::validate::ValError), + PackageError(PackageValidationError), /// The encoded HUGR package must have a single HUGR. #[display("The encoded HUGR package must have a single HUGR, but it has {count} HUGRs.")] InvalidNumHugrs {