Skip to content

Commit

Permalink
chore: Update to hugr 0.13.2, fix deprecation warnings (#669)
Browse files Browse the repository at this point in the history
We can now drop the dependency on `hugr-cli` for `tket2{,-py}`.

Hugr roots now have (disconnected) ports, so I had to fix the low-level
`rewrite_dfg` to ensure we keep the root valid.
  • Loading branch information
aborgna-q authored Oct 23, 2024
1 parent 6a31663 commit 2226fed
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 74 deletions.
93 changes: 46 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions tket2-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 6 additions & 8 deletions tket2-py/src/circuit/tk2circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -97,20 +97,18 @@ impl Tk2Circuit {
/// Decode a HUGR json string to a circuit.
#[staticmethod]
pub fn from_hugr_json(json: &str) -> PyResult<Self> {
let pkg: Package = serde_json::from_str(json)
let mut pkg: Package = serde_json::from_str(json)
.map_err(|e| PyErr::new::<PyAttributeError, _>(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::<PyAttributeError, _>(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.
Expand Down
Loading

0 comments on commit 2226fed

Please sign in to comment.