Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to portgraph v0.7 #219

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;