Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
13 changes: 13 additions & 0 deletions .github/workflows/ci-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
uses: KyleMayes/install-llvm-action@v2
with:
version: ${{ env.LLVM_VERSION }}
- name: Install z3
run: sudo apt-get -y install z3
- name: Run clippy
run: cargo clippy --all-targets --all-features --workspace -- -D warnings
- name: Build docs
Expand Down Expand Up @@ -160,6 +162,8 @@ jobs:
uses: KyleMayes/install-llvm-action@v2
with:
version: ${{ env.LLVM_VERSION }}
- name: Install z3
run: sudo apt-get -y install z3
- name: Build with all features
run: cargo test --verbose --all-features --no-run
- name: Tests with all features
Expand All @@ -170,6 +174,12 @@ jobs:
- name: Tests hugr-llvm
if: ${{ needs.changes.outputs.llvm == 'true'}}
run: cargo test -p hugr-llvm --verbose --features llvm${{ env.LLVM_FEATURE_NAME }}
- name: Build hugr-persistent
if: ${{ needs.changes.outputs.rust == 'true'}}
run: cargo test -p hugr-persistent --verbose --no-run
- name: Tests hugr-persistent
if: ${{ needs.changes.outputs.rust == 'true'}}
run: cargo test -p hugr-persistent --verbose
- name: Build HUGR binary
run: cargo build -p hugr-cli
- name: Upload the binary to the artifacts
Expand Down Expand Up @@ -347,6 +357,8 @@ jobs:
uses: KyleMayes/install-llvm-action@v2
with:
version: ${{ env.LLVM_VERSION }}
- name: Install z3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Driveby z3 dependency? If this is new, it'd be good to mention in the PR description perhaps.

LGTM otherwise.

run: sudo apt-get -y install z3
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Run tests with coverage instrumentation
Expand All @@ -355,6 +367,7 @@ jobs:
cargo llvm-cov --no-report --no-default-features --doctests
cargo llvm-cov --no-report --all-features --doctests
cargo llvm-cov --no-report -p hugr-llvm --features llvm14-0 --doctests
cargo llvm-cov --no-report -p hugr-persistent --doctests
- name: Generate coverage report
run: cargo llvm-cov --all-features report --codecov --output-path coverage.json
- name: Upload coverage to codecov.io
Expand Down
27 changes: 22 additions & 5 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"hugr-model",
"hugr-llvm",
"hugr-py",
"hugr-persistent",
]
default-members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]

Expand Down
4 changes: 0 additions & 4 deletions hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ bench = false
[[test]]
name = "model"

[[test]]
name = "persistent_walker_example"

[dependencies]
hugr-model = { version = "0.20.0", path = "../hugr-model" }

Expand Down Expand Up @@ -63,7 +60,6 @@ thiserror = { workspace = true }
typetag = { workspace = true }
semver = { workspace = true, features = ["serde"] }
zstd = { workspace = true, optional = true }
relrc = { workspace = true, features = ["petgraph"] }

[dev-dependencies]
rstest = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion hugr-core/src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub mod hugrmut;
pub(crate) mod ident;
pub mod internal;
pub mod patch;
pub mod persistent;
pub mod serialize;
pub mod validate;
pub mod views;
Expand Down
16 changes: 16 additions & 0 deletions hugr-core/src/hugr/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,22 @@ impl HugrMutInternals for Hugr {
}
}

impl Hugr {
/// Consumes the HUGR and return a flat portgraph view of the region rooted
/// at `parent`.
#[inline]
pub fn into_region_portgraph(
self,
parent: Node,
) -> portgraph::view::FlatRegion<'static, MultiPortGraph> {
let root = parent.into_portgraph();
let Self {
graph, hierarchy, ..
} = self;
portgraph::view::FlatRegion::new_without_root(graph, hierarchy, root)
}
}

#[cfg(test)]
mod test {
use crate::{
Expand Down
15 changes: 6 additions & 9 deletions hugr-core/src/hugr/patch/simple_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,24 +498,21 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
/// Map the host nodes in `self` according to `node_map`.
///
/// `node_map` must map nodes in the current HUGR of the subgraph to
/// its equivalent nodes in some `new_hugr`.
/// its equivalent nodes in some `new_host`.
///
/// This converts a replacement that acts on nodes of type `HostNode` to
/// a replacement that acts on `new_hugr`, with nodes of type `N`.
///
/// This does not check convexity. It is up to the caller to ensure that
/// the mapped replacement obtained from this applies on a convex subgraph
/// of the new HUGR.
pub(crate) fn map_host_nodes<N: HugrNode>(
/// a replacement that acts on `new_host`, with nodes of type `N`.
pub fn map_host_nodes<N: HugrNode>(
&self,
node_map: impl Fn(HostNode) -> N,
) -> SimpleReplacement<N> {
new_host: &impl HugrView<Node = N>,
) -> Result<SimpleReplacement<N>, InvalidReplacement> {
let Self {
subgraph,
replacement,
} = self;
let subgraph = subgraph.map_nodes(node_map);
SimpleReplacement::new_unchecked(subgraph, replacement.clone())
SimpleReplacement::try_new(subgraph, new_host, replacement.clone())
}
}

Expand Down
39 changes: 33 additions & 6 deletions hugr-core/src/hugr/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::borrow::Cow;
use std::collections::HashMap;

pub use self::petgraph::PetgraphWrapper;
use self::render::RenderConfig;
use self::render::{FullRenderConfig, RenderConfig};
pub use rerooted::Rerooted;
pub use root_checked::{InvalidSignature, RootCheckable, RootChecked, check_tag};
pub use sibling_subgraph::SiblingSubgraph;
Expand Down Expand Up @@ -396,6 +396,28 @@ pub trait HugrView: HugrInternals {
/// format instead.
fn mermaid_string_with_config(&self, config: RenderConfig<Self::Node>) -> String;

/// Return the mermaid representation of the underlying hierarchical graph,
/// accepting the full set of configuration options.
///
/// By default, the configuration will be converted to a [`RenderConfig`]
/// struct and may panic if the configuration is not supported. Where
/// possible, users are encouraged to provide an implementation for this
/// method instead and forward calls to [HugrView::mermaid_string_with_config]
/// to this method.
///
/// The hierarchy is represented using subgraphs. Edges are labelled with
/// their source and target ports.
///
/// For a more detailed representation, use the [`HugrView::dot_string`]
/// format instead.
fn mermaid_string_with_full_config(
&self,
config: impl Into<FullRenderConfig<Self::Node>>,
) -> String {
let config: RenderConfig<_> = config.into().try_into().expect("unsupported config");
self.mermaid_string_with_config(config)
}

/// Return the graphviz representation of the underlying graph and hierarchy side by side.
///
/// For a simpler representation, use the [`HugrView::mermaid_string`] format instead.
Expand Down Expand Up @@ -639,10 +661,15 @@ impl HugrView for Hugr {
}

fn mermaid_string_with_config(&self, config: RenderConfig) -> String {
self.mermaid_string_with_full_config(config)
}

fn mermaid_string_with_full_config(&self, config: impl Into<FullRenderConfig>) -> String {
let config = config.into();
self.graph
.mermaid_format()
.with_hierarchy(&self.hierarchy)
.with_node_style(render::node_style(self, config, |n| n.index().to_string()))
.with_node_style(render::node_style(self, config.clone()))
.with_edge_style(render::edge_style(self, config))
.finish()
}
Expand All @@ -651,15 +678,15 @@ impl HugrView for Hugr {
where
Self: Sized,
{
let config = RenderConfig {
let config = FullRenderConfig {
entrypoint: Some(self.entrypoint()),
..RenderConfig::default()
..FullRenderConfig::default()
};
self.graph
.dot_format()
.with_hierarchy(&self.hierarchy)
.with_node_style(render::node_style(self, config, |n| n.index().to_string()))
.with_port_style(render::port_style(self, config))
.with_node_style(render::node_style(self, config.clone()))
.with_port_style(render::port_style(self))
.with_edge_style(render::edge_style(self, config))
.finish()
}
Expand Down
1 change: 1 addition & 0 deletions hugr-core/src/hugr/views/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ macro_rules! hugr_view_methods {
fn all_neighbours(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> + Clone;
fn mermaid_string(&self) -> String;
fn mermaid_string_with_config(&self, config: crate::hugr::views::render::RenderConfig<Self::Node>) -> String;
fn mermaid_string_with_full_config(&self, config: impl Into<crate::hugr::views::render::FullRenderConfig<Self::Node>>) -> String;
fn dot_string(&self) -> String;
fn static_source(&self, node: Self::Node) -> Option<Self::Node>;
fn static_targets(&self, node: Self::Node) -> Option<impl Iterator<Item = (Self::Node, crate::IncomingPort)>>;
Expand Down
Loading
Loading