Skip to content

Commit

Permalink
Update to portgraph v0.7 (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q authored Jun 29, 2023
1 parent ed5f3a5 commit 04ecd83
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 197 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ path = "src/lib.rs"

[dependencies]
thiserror = "1.0.28"
portgraph = { version = "0.6.0", features = ["serde", "petgraph"] }
portgraph = { version = "0.7.0", features = ["serde", "petgraph"] }
pyo3 = { version = "0.19.0", optional = true, features = [
"multiple-pymethods",
] }
Expand Down
2 changes: 1 addition & 1 deletion src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) use self::hugrmut::HugrMut;
pub use self::validate::ValidationError;

use derive_more::From;
pub use rewrite::{Replace, ReplaceError, Rewrite, SimpleReplacement, SimpleReplacementError};
pub use rewrite::{Rewrite, SimpleReplacement, SimpleReplacementError};

use portgraph::dot::{DotFormat, EdgeStyle, NodeStyle, PortStyle};
use portgraph::multiportgraph::MultiPortGraph;
Expand Down
20 changes: 6 additions & 14 deletions src/hugr/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,10 @@ impl<'g> HugrView for FlatRegionView<'g> {
}

fn children(&self, node: Node) -> Self::Children<'_> {
let mut iter = self.hierarchy.children(node.index).map_into();
if node != self.root {
// Eagerly empty the iterator.
// Ideally we would construct an empty iterator directly, but
// `Children` is not `Default`.
while iter.next().is_some() {}
match node == self.root {
true => self.hierarchy.children(node.index).map_into(),
false => portgraph::hierarchy::Children::default().map_into(),
}
iter
}

fn neighbours(&self, node: Node, dir: Direction) -> Self::Neighbours<'_> {
Expand Down Expand Up @@ -271,14 +267,10 @@ impl<'g> HugrView for RegionView<'g> {
}

fn children(&self, node: Node) -> Self::Children<'_> {
let mut iter = self.hierarchy.children(node.index).map_into();
if !self.graph.contains_node(node.index) {
// Eagerly empty the iterator.
// Ideally we would construct an empty iterator directly, but
// `Children` is not `Default`.
while iter.next().is_some() {}
match self.graph.contains_node(node.index) {
true => self.hierarchy.children(node.index).map_into(),
false => portgraph::hierarchy::Children::default().map_into(),
}
iter
}

fn neighbours(&self, node: Node, dir: Direction) -> Self::Neighbours<'_> {
Expand Down
2 changes: 0 additions & 2 deletions src/hugr/rewrite.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! Rewrite operations on the HUGR - replacement, outlining, etc.
pub mod replace;
pub mod simple_replace;
use std::mem;

use crate::Hugr;
pub use replace::{OpenHugr, Replace, ReplaceError};
pub use simple_replace::{SimpleReplacement, SimpleReplacementError};

/// An operation that can be applied to mutate a Hugr
Expand Down
176 changes: 0 additions & 176 deletions src/hugr/rewrite/replace.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ pub mod resource;
pub mod types;
mod utils;

pub use crate::hugr::{
Direction, Hugr, HugrView, Node, Port, Replace, ReplaceError, SimpleReplacement, Wire,
};
pub use crate::hugr::{Direction, Hugr, HugrView, Node, Port, SimpleReplacement, Wire};
pub use crate::resource::Resource;

0 comments on commit 04ecd83

Please sign in to comment.