Skip to content

Test if (open)hypergraphs are acyclic#24

Merged
statusfailed merged 16 commits intohellas-ai:masterfrom
mstn:acyclicity
Feb 18, 2026
Merged

Test if (open)hypergraphs are acyclic#24
statusfailed merged 16 commits intohellas-ai:masterfrom
mstn:acyclicity

Conversation

@mstn
Copy link
Contributor

@mstn mstn commented Feb 5, 2026

Context

For rewrites in SMC we need acycle hypergraphs.

Details

  • Added acyclicity checks for strict hypergraphs on the induced node graph; exposed is is_acyclic on Hypergraph and OpenHypergraph. We define the condition on strict because cycles can be the result of quotiening, if the graph is not strict, we might wrongly assume that it is acyclic.
  • We defined node_adjacency similar to operation_adjacency where adjacency is IndexedCoproduct<K, FiniteFunction<K>>, intuitively a map nodes -> list of next nodes. We run kahn on node_adjacency for testing for cycles: Kahn’s algorithm removes all nodes if and only if the directed graph is acyclic (it runs on each connected components). Initial implementation used DFS, but better to reuse existing logic.
  • Added tests: basic acyclic/cyclic cases, identity and symmetry acyclic, and a composed‑example that becomes cyclic.
  • Refactored layer.rs, moved "graph" code in a separate module for reusability.

Known Issues and Tradeoffs

At the moment we don't cache or optimize memory, but it is something we might consider in the future.

  • is_acyclic rebuilds node level adjacency each call; repeated checks will pay this cost repeatedly. We could cache adjacency.
  • Full adjacency expands each hyperedge into source/target pairs, which can be memory‑heavy; a lighter node->outgoing‑edges index could reduce memory at the cost of per‑step traversal overhead.

@mstn mstn marked this pull request as draft February 5, 2026 09:58
@mstn mstn marked this pull request as ready for review February 5, 2026 16:26
@mstn mstn marked this pull request as draft February 5, 2026 16:30
@mstn mstn marked this pull request as ready for review February 5, 2026 16:33
Copy link
Contributor

@statusfailed statusfailed left a comment

Choose a reason for hiding this comment

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

only one minor change - operation_adjacency breaks public API. Please keep this one the same & add another function taking a Hypergraph argument if needed

@mstn mstn requested a review from statusfailed February 16, 2026 08:49
@mstn
Copy link
Contributor Author

mstn commented Feb 16, 2026

  • Made API pub(crate) as discussed on discord.
  • Moved tests from integration tests to unit tests.

@mstn mstn mentioned this pull request Feb 18, 2026
@statusfailed statusfailed merged commit cc189b8 into hellas-ai:master Feb 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments