Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lmondada committed Sep 29, 2023
1 parent 98e8ccf commit ee4fb54
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 96 deletions.
1 change: 1 addition & 0 deletions pyrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tket-json-rs = { git = "https://github.com/CQCL/tket-json-rs", rev="619db15d3",
quantinuum-hugr = { workspace = true }
portgraph = { workspace = true, features = ["pyo3"] }
pyo3 = { workspace = true, features = ["extension-module"] }
itertools.workspace = true
12 changes: 3 additions & 9 deletions pyrs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Python bindings for TKET2.
#![warn(missing_docs)]
use circuit::{add_circuit_module, try_with_hugr};
use optimiser::add_optimiser_module;
use pyo3::prelude::*;
use tket2::{json::TKETDecode, optimiser::taso, passes::apply_greedy_commutation};
use tket2::{json::TKETDecode, passes::apply_greedy_commutation};
use tket_json_rs::circuit_json::SerialCircuit;

mod circuit;
mod optimiser;

#[pyfunction]
fn greedy_depth_reduce(py_c: PyObject) -> PyResult<(PyObject, u32)> {
Expand Down Expand Up @@ -55,11 +57,3 @@ fn add_pass_module(py: Python, parent: &PyModule) -> PyResult<()> {
parent.add_submodule(m)?;
Ok(())
}

/// circuit optimisation module
fn add_optimiser_module(py: Python, parent: &PyModule) -> PyResult<()> {
let m = PyModule::new(py, "optimiser")?;
m.add_class::<taso::pyo3::PyDefaultTasoOptimiser>()?;

parent.add_submodule(m)
}
2 changes: 1 addition & 1 deletion src/optimiser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub mod taso;

#[cfg(feature = "portmatching")]
pub use taso::DefaultTasoOptimiser;
pub use taso::TasoOptimiser;
pub use taso::{TasoLogger, TasoOptimiser};
5 changes: 1 addition & 4 deletions src/optimiser/taso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ mod hugr_hash_set;
mod hugr_pchannel;
mod hugr_pqueue;
pub mod log;
#[cfg(all(feature = "pyo3", feature = "portmatching"))]
pub mod pyo3;
mod qtz_circuit;
mod worker;

use crossbeam_channel::select;
pub use eq_circ_class::{load_eccs_json_file, EqCircClass};
pub use log::TasoLogger;

use std::num::NonZeroUsize;
use std::time::{Duration, Instant};
Expand All @@ -37,8 +36,6 @@ use crate::optimiser::taso::worker::TasoWorker;
use crate::rewrite::strategy::RewriteStrategy;
use crate::rewrite::Rewriter;

use self::log::TasoLogger;

/// The TASO optimiser.
///
/// Adapted from [Quartz][], and originally [TASO][].
Expand Down
62 changes: 0 additions & 62 deletions src/optimiser/taso/pyo3.rs

This file was deleted.

11 changes: 9 additions & 2 deletions src/portmatching/pyo3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ use std::fmt;

use derive_more::{From, Into};
use hugr::hugr::views::sibling_subgraph::PyInvalidReplacementError;
use hugr::Port;
use hugr::{Hugr, Port};
use itertools::Itertools;
use portmatching::{HashMap, PatternID};
use pyo3::{prelude::*, types::PyIterator};
use tket_json_rs::circuit_json::SerialCircuit;

use super::{CircuitPattern, PatternMatch, PatternMatcher};
use crate::circuit::Circuit;
use crate::json::TKETDecode;
use crate::rewrite::CircuitRewrite;
use crate::utils::pyobj_as_hugr;

#[pymethods]
impl CircuitPattern {
Expand Down Expand Up @@ -195,3 +196,9 @@ impl Node {
format!("{:?}", self)
}
}

fn pyobj_as_hugr(circ: PyObject) -> PyResult<Hugr> {
let ser_c = SerialCircuit::_from_tket1(circ);
let hugr: Hugr = ser_c.decode()?;
Ok(hugr)
}
18 changes: 0 additions & 18 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@ pub(crate) fn type_is_linear(typ: &Type) -> bool {
!TypeBound::Copyable.contains(typ.least_upper_bound())
}

// Convert a pytket object to HUGR
#[cfg(feature = "pyo3")]
mod pyo3 {
use hugr::Hugr;
use pyo3::prelude::*;
use tket_json_rs::circuit_json::SerialCircuit;

use crate::json::TKETDecode;

pub(crate) fn pyobj_as_hugr(circ: PyObject) -> PyResult<Hugr> {
let ser_c = SerialCircuit::_from_tket1(circ);
let hugr: Hugr = ser_c.decode()?;
Ok(hugr)
}
}
#[cfg(feature = "pyo3")]
pub(crate) use self::pyo3::pyobj_as_hugr;

// utility for building simple qubit-only circuits.
#[allow(unused)]
pub(crate) fn build_simple_circuit(
Expand Down

0 comments on commit ee4fb54

Please sign in to comment.