Skip to content

Faster loop enumeration#177

Merged
mtfishman merged 43 commits into
mainfrom
Faster_Loop_Enumeration
Jul 13, 2026
Merged

Faster loop enumeration#177
mtfishman merged 43 commits into
mainfrom
Faster_Loop_Enumeration

Conversation

@JoeyT1994

Copy link
Copy Markdown
Collaborator

This PR replaces the edgeinduced_subgraphs_no_leaves(g::AbstractGraph, max_edges::Integer) function with a much faster and fully correct implementation.

The function takes a graph g and enumerates all connected, edge induced subgraphs with up to max_edges which contain no leaf (degree 1) vertices. This induced graphs are the basis of a cluster expansion.

The function is now completely correct (the previous version missed out subgraphs with bridges) and much much faster (many hundreds of times on large graphs).

Tests are updated to reflect this and check the expansion.

JoeyT1994 and others added 30 commits November 7, 2024 16:08
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
@ITensorBot

ITensorBot commented Jul 13, 2026

Copy link
Copy Markdown
Member

Your PR no longer requires formatting changes. Thank you for your contribution!

Comment thread src/simplecycles.jl Outdated
Comment on lines +16 to +33
mutable struct NoLeafSubgraphSearch
# Endpoints of each edge, as integer vertex indices (indexed by edge index).
const edge_src::Vector{Int}
const edge_dst::Vector{Int}
# Line-graph adjacency: `edge_neighbours[i]` lists the edges sharing a vertex with edge `i`.
const edge_neighbours::Vector{Vector{Int}}
const max_edges::Int
# Induced degree of each vertex within the current edge set.
const vertex_degree::Vector{Int}
# Number of vertices whose induced degree is exactly 1 (i.e. leaves of the current set).
num_leaves::Int
# `marked[u]` is true while edge `u` is in the current set or already queued for it.
const marked::Vector{Bool}
# The current edge set, used as a stack.
const current_edges::Vector{Int}
# Completed leaf-free edge sets (each a vector of edge indices).
const results::Vector{Vector{Int}}
end

@mtfishman mtfishman Jul 13, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since most of the fields are set to const anyway, it might be better to make the type not mutable and then make the field num_leaves::Base.RefValue{Int}. Then you can update it with search.num_leaves[] += 1 and access it with search.num_leaves[].

Comment thread Project.toml Outdated
name = "NamedGraphs"
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
version = "0.12.2"
version = "0.12.3"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we are deleting unique_simplecycles_limited_length I think we'll need to mark this as breaking, i.e. v0.13. I guess the idea is that function is just not very useful so we may as well not support it any more?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it was only being used inside the previous version of edgeinduced_subgraphs_no_leaves so seems no point in supporting it. Will bump it

@mtfishman

Copy link
Copy Markdown
Member

@JoeyT1994 what do you think of the name leafless_edge_induced_subgraphs?

@JoeyT1994

Copy link
Copy Markdown
Collaborator Author

@mtfishman Yeah that's a slightly simpler name, I'll change to that

@mtfishman
mtfishman enabled auto-merge (squash) July 13, 2026 18:31
@mtfishman
mtfishman merged commit 9409afd into main Jul 13, 2026
19 checks passed
@mtfishman
mtfishman deleted the Faster_Loop_Enumeration branch July 13, 2026 18:37
mtfishman added a commit to ITensor/DataGraphs.jl that referenced this pull request Jul 13, 2026
## Summary

Widen the `NamedGraphs` compat to allow v0.13
(ITensor/NamedGraphs.jl#177). That release
rewrites the leaf-free edge-induced subgraph enumeration and drops the
old internal cycle-enumeration helpers, none of which DataGraphs uses,
so it stays compatible with both v0.12 and v0.13.
mtfishman added a commit to ITensor/ITensorNetworks.jl that referenced this pull request Jul 13, 2026
## Summary

Widen the `NamedGraphs` compat to allow v0.13
(ITensor/NamedGraphs.jl#177). That release
rewrites the leaf-free edge-induced subgraph enumeration and drops the
old internal cycle-enumeration helpers, none of which ITensorNetworks
uses, so it stays compatible with both v0.12 and v0.13.
mtfishman added a commit to ITensor/ITensorNetworksNext.jl that referenced this pull request Jul 13, 2026
## Summary

Widen the `NamedGraphs` compat to allow v0.13
(ITensor/NamedGraphs.jl#177). That release
rewrites the leaf-free edge-induced subgraph enumeration and drops the
old internal cycle-enumeration helpers, none of which
ITensorNetworksNext uses, so it stays compatible with both v0.12 and
v0.13.
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.

3 participants