Skip to content

Commit

Permalink
Only require tket2/hugr pyo3 features for error bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Nov 10, 2023
1 parent cdccd95 commit 53d5b15
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tket2-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tket2 = { workspace = true, features = ["pyo3", "portmatching"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tket-json-rs = { workspace = true, features = ["pyo3"] }
quantinuum-hugr = { workspace = true }
quantinuum-hugr = { workspace = true, features = ["pyo3"] }
portgraph = { workspace = true, features = ["pyo3", "serde"] }
pyo3 = { workspace = true, features = ["extension-module"] }
num_cpus = "1.16.0"
Expand Down
4 changes: 2 additions & 2 deletions tket2-py/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ pub fn to_hugr_dot(c: Py<PyAny>) -> PyResult<String> {

/// Downcast a python object to a [`Hugr`].
#[pyfunction]
pub fn to_hugr(c: Py<PyAny>) -> PyResult<Hugr> {
with_hugr(c, |hugr| hugr)
pub fn to_hugr(c: Py<PyAny>) -> PyResult<T2Circuit> {
with_hugr(c, |hugr| hugr.into())
}

/// A [`hugr::Node`] wrapper for Python.
Expand Down
5 changes: 3 additions & 2 deletions tket2-py/src/circuit/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use pyo3::{prelude::*, PyTypeInfo};

use derive_more::From;
use hugr::{Hugr, HugrView};
use tket2::extension::REGISTRY;
use tket2::json::TKETDecode;
Expand All @@ -12,7 +13,7 @@ use crate::pattern::rewrite::PyCircuitRewrite;

/// A manager for tket 2 operations on a tket 1 Circuit.
#[pyclass]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, From)]
pub struct T2Circuit {
/// Rust representation of the circuit.
pub hugr: Hugr,
Expand All @@ -23,7 +24,7 @@ impl T2Circuit {
#[new]
fn from_circuit(circ: PyObject) -> PyResult<Self> {
Ok(Self {
hugr: super::to_hugr(circ)?,
hugr: with_hugr(circ, |hugr| hugr)?,
})
}

Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Rule {
let l = to_hugr(l)?;
let r = to_hugr(r)?;

Ok(Rule([l, r]))
Ok(Rule([l.hugr, r.hugr]))
}
}
#[pyclass]
Expand Down
7 changes: 3 additions & 4 deletions tket2-py/src/pattern/portmatching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
use std::fmt;

use derive_more::{From, Into};
use hugr::Node;
use itertools::Itertools;
use portmatching::PatternID;
use pyo3::{prelude::*, types::PyIterator};

use tket2::portmatching::{CircuitPattern, PatternMatch, PatternMatcher};

use crate::circuit::{try_with_hugr, with_hugr};
use crate::circuit::{try_with_hugr, with_hugr, PyNode};

/// A pattern that match a circuit exactly
///
Expand Down Expand Up @@ -111,8 +110,8 @@ impl PyPatternMatch {
}

/// Returns the root of the pattern in the circuit.
pub fn root(&self) -> Node {
self.pmatch.root()
pub fn root(&self) -> PyNode {
self.pmatch.root().into()
}

/// A string representation of the pattern.
Expand Down
7 changes: 1 addition & 6 deletions tket2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ name = "tket2"
path = "src/lib.rs"

[features]
pyo3 = [
"dep:pyo3",
"tket-json-rs/pyo3",
"portgraph/pyo3",
"quantinuum-hugr/pyo3",
]
pyo3 = ["dep:pyo3"]
portmatching = ["dep:portmatching", "dep:rmp-serde"]

[dependencies]
Expand Down

0 comments on commit 53d5b15

Please sign in to comment.