Skip to content

Commit

Permalink
chore: update to pyo3 0.23.2 and tket-json-rs 0.7.1 (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Nov 29, 2024
1 parent 7d3e5f5 commit b17736d
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 89 deletions.
55 changes: 28 additions & 27 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ hugr = "0.13.3"
hugr-core = "0.13.3"
hugr-cli = "0.13.3"
portgraph = "0.12"
pyo3 = "0.22.5"
pyo3 = "0.23.2"
itertools = "0.13.0"
tket-json-rs = "0.6.2"
tket-json-rs = "0.7.1"
tracing = "0.1.37"
portmatching = "0.3.1"
bytemuck = "1.20.0"
Expand Down
12 changes: 6 additions & 6 deletions tket2-py/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use tket2::{Pauli, Tk2Op};

/// The module definition
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "circuit")?;
let m = PyModule::new(py, "circuit")?;
m.add_class::<Tk2Circuit>()?;
m.add_class::<PyNode>()?;
m.add_class::<PyWire>()?;
Expand All @@ -40,14 +40,14 @@ pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
m.add_function(wrap_pyfunction!(render_circuit_dot, &m)?)?;
m.add_function(wrap_pyfunction!(render_circuit_mermaid, &m)?)?;

m.add("HugrError", py.get_type_bound::<PyHugrError>())?;
m.add("BuildError", py.get_type_bound::<PyBuildError>())?;
m.add("ValidationError", py.get_type_bound::<PyValidationError>())?;
m.add("HugrError", py.get_type::<PyHugrError>())?;
m.add("BuildError", py.get_type::<PyBuildError>())?;
m.add("ValidationError", py.get_type::<PyValidationError>())?;
m.add(
"HUGRSerializationError",
py.get_type_bound::<PyHUGRSerializationError>(),
py.get_type::<PyHUGRSerializationError>(),
)?;
m.add("TK1ConvertError", py.get_type_bound::<PyTK1ConvertError>())?;
m.add("TK1ConvertError", py.get_type::<PyTK1ConvertError>())?;

Ok(m)
}
Expand Down
4 changes: 2 additions & 2 deletions tket2-py/src/circuit/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use itertools::Itertools;
use pyo3::exceptions::{PyAttributeError, PyValueError};
use pyo3::types::{PyAnyMethods, PyModule, PyString, PyTypeMethods};
use pyo3::{
pyclass, pymethods, Bound, FromPyObject, PyAny, PyErr, PyObject, PyRefMut, PyResult,
PyTypeInfo, Python, ToPyObject,
pyclass, pymethods, Bound, FromPyObject, IntoPyObject, PyAny, PyErr, PyObject, PyRefMut,
PyResult, PyTypeInfo, Python,
};

use derive_more::From;
Expand Down
8 changes: 3 additions & 5 deletions tket2-py/src/circuit/tk2circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use itertools::Itertools;
use pyo3::exceptions::{PyAttributeError, PyValueError};
use pyo3::types::{PyAnyMethods, PyModule, PyString, PyTypeMethods};
use pyo3::{
pyclass, pymethods, Bound, FromPyObject, PyAny, PyErr, PyObject, PyRef, PyRefMut, PyResult,
PyTypeInfo, Python, ToPyObject,
pyclass, pymethods, Bound, FromPyObject, IntoPyObject, PyAny, PyErr, PyObject, PyRef, PyRefMut,
PyResult, PyTypeInfo, Python,
};

use derive_more::From;
Expand Down Expand Up @@ -177,9 +177,7 @@ impl Tk2Circuit {
};
let tk2_py_op = PyTk2Op::from(tk2_op);
let cost = cost_fn.call1((tk2_py_op,))?;
Ok(PyCircuitCost {
cost: cost.to_object(py),
})
Ok(PyCircuitCost { cost: cost.into() })
};
let circ_cost = self.circ.circuit_cost(cost_fn)?;
Ok(circ_cost.cost.into_bound(py))
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn add_submodule(py: Python, parent: &Bound<PyModule>, submodule: Bound<PyModule
// See [https://github.com/PyO3/pyo3/issues/759]
let parent_name = parent.name()?;
let submodule_name = submodule.name()?;
let modules = py.import_bound("sys")?.getattr("modules")?;
let modules = py.import("sys")?.getattr("modules")?;
modules.set_item(format!("{parent_name}.{submodule_name}"), submodule)?;
Ok(())
}
2 changes: 1 addition & 1 deletion tket2-py/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::types::PyHugrType;

/// The module definition
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "ops")?;
let m = PyModule::new(py, "ops")?;
m.add_class::<PyTk2Op>()?;
m.add_class::<PyPauli>()?;
m.add_class::<PyExtensionOp>()?;
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/optimiser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::circuit::update_circ;

/// The module definition
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "optimiser")?;
let m = PyModule::new(py, "optimiser")?;
m.add_class::<PyBadgerOptimiser>()?;
Ok(m)
}
Expand Down
15 changes: 6 additions & 9 deletions tket2-py/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ use crate::{
///
/// This module is re-exported from the python module with the same name.
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "passes")?;
let m = PyModule::new(py, "passes")?;
m.add_function(wrap_pyfunction!(greedy_depth_reduce, &m)?)?;
m.add_function(wrap_pyfunction!(lower_to_pytket, &m)?)?;
m.add_function(wrap_pyfunction!(badger_optimise, &m)?)?;
m.add_class::<self::chunks::PyCircuitChunks>()?;
m.add_function(wrap_pyfunction!(self::chunks::chunks, &m)?)?;
m.add(
"PullForwardError",
py.get_type_bound::<PyPullForwardError>(),
)?;
m.add("PullForwardError", py.get_type::<PyPullForwardError>())?;
Ok(m)
}

Expand Down Expand Up @@ -66,11 +63,11 @@ fn greedy_depth_reduce<'py>(circ: &Bound<'py, PyAny>) -> PyResult<(Bound<'py, Py
fn rebase_nam(circ: &Bound<PyAny>) -> PyResult<()> {
let py = circ.py();
let auto_rebase = py
.import_bound("pytket.passes.auto_rebase")?
.import("pytket.passes.auto_rebase")?
.getattr("auto_rebase_pass")?;
let optype = py.import_bound("pytket")?.getattr("OpType")?;
let locals = [("OpType", &optype)].into_py_dict_bound(py);
let op_set = py.eval_bound("{OpType.CX, OpType.Rz, OpType.H}", None, Some(&locals))?;
let optype = py.import("pytket")?.getattr("OpType")?;
let locals = [("OpType", &optype)].into_py_dict(py)?;
let op_set = py.eval(c"{OpType.CX, OpType.Rz, OpType.H}", None, Some(&locals))?;
let rebase_pass = auto_rebase.call1((op_set,))?.getattr("apply")?;
rebase_pass.call1((circ,)).map(|_| ())
}
Expand Down
6 changes: 3 additions & 3 deletions tket2-py/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tket2::Circuit;

/// The module definition
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "pattern")?;
let m = PyModule::new(py, "pattern")?;
m.add_class::<Rule>()?;
m.add_class::<RuleMatcher>()?;
m.add_class::<self::portmatching::PyCircuitPattern>()?;
Expand All @@ -23,11 +23,11 @@ pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {

m.add(
"InvalidPatternError",
py.get_type_bound::<PyInvalidPatternError>(),
py.get_type::<PyInvalidPatternError>(),
)?;
m.add(
"InvalidReplacementError",
py.get_type_bound::<PyInvalidReplacementError>(),
py.get_type::<PyInvalidReplacementError>(),
)?;

Ok(m)
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/pattern/portmatching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl PyPatternMatcher {
pub fn py_from_patterns(patterns: &Bound<PyIterator>) -> PyResult<Self> {
Ok(PatternMatcher::from_patterns(
patterns
.iter()?
.try_iter()?
.map(|p| {
let py_pattern = p?.extract::<PyCircuitPattern>()?;
Ok(py_pattern.pattern)
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::circuit::{PyNode, Tk2Circuit};

/// The module definition
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "rewrite")?;
let m = PyModule::new(py, "rewrite")?;
m.add_class::<PyECCRewriter>()?;
m.add_class::<PyCircuitRewrite>()?;
m.add_class::<PySubcircuit>()?;
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fmt;

/// The module definition
pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
let m = PyModule::new_bound(py, "types")?;
let m = PyModule::new(py, "types")?;
m.add_class::<PyHugrType>()?;
m.add_class::<PyTypeBound>()?;

Expand Down
Loading

0 comments on commit b17736d

Please sign in to comment.