Skip to content

Fix infinite method call in forest_cover_edge_sequence; add tests.#170

Merged
mtfishman merged 10 commits into
mainfrom
jd/fix-forest-cover-edge-sequence
May 28, 2026
Merged

Fix infinite method call in forest_cover_edge_sequence; add tests.#170
mtfishman merged 10 commits into
mainfrom
jd/fix-forest-cover-edge-sequence

Conversation

@jack-dunham
Copy link
Copy Markdown
Contributor

@jack-dunham jack-dunham commented May 20, 2026

The forest_cover_edge_sequence method dispatching on AbstractNamedGraph would call itself repeatedly as there was no forest_cover_edge_sequence method dispatching on concrete NamedGraph.

I've removed this method as it was also not necessarily given the generic implementation of forest_cover_edge_sequence on AbstractGraph, and added some simple tests for this function.

This PR also refactors the implementation of similar_graph, moving this function back into GraphsExtensions.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 90.14085% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.57%. Comparing base (7284411) to head (e1ab8b3).

Files with missing lines Patch % Lines
src/similar_graph.jl 80.00% 4 Missing ⚠️
src/lib/GraphsExtensions/src/abstractgraph.jl 91.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #170      +/-   ##
==========================================
+ Coverage   78.99%   80.57%   +1.58%     
==========================================
  Files          55       56       +1     
  Lines        2099     2111      +12     
==========================================
+ Hits         1658     1701      +43     
+ Misses        441      410      -31     
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman
Copy link
Copy Markdown
Member

Looks good, ready to merge? Would this mean we don't need to define forest_cover_edge_sequence for AbstractDataGraph, i.e. in ITensor/DataGraphs.jl#121?

@jack-dunham jack-dunham force-pushed the jd/fix-forest-cover-edge-sequence branch from dac25b7 to b8c3d8d Compare May 26, 2026 23:34
Comment thread src/lib/GraphsExtensions/src/abstractgraph.jl
@mtfishman
Copy link
Copy Markdown
Member

Looks like some downstream tests are failing, is the goal to make this PR non-breaking?

Comment thread src/similar_graph.jl Outdated
Comment thread src/lib/GraphsExtensions/src/abstractgraph.jl
@jack-dunham
Copy link
Copy Markdown
Contributor Author

The ITensorNetworksNext tests failing is strange, i'll investigate.

I am less bothered if DataGraphs breaks and needs updated slightly as we have an open PR for that package anyway, so can upgrade to the new NamedGraphs version (assuming that doesn't breaking downstream tests).

@mtfishman
Copy link
Copy Markdown
Member

The ITensorNetworksNext tests failing is strange, i'll investigate.

I am less bothered if DataGraphs breaks and needs updated slightly as we have an open PR for that package anyway, so can upgrade to the new NamedGraphs version (assuming that doesn't breaking downstream tests).

I agree it isn't a huge deal if this PR is breaking, I just wanted to check if that is deliberate, check how easy it would be to make it non-breaking, inquire what specifically about the PR is breaking, etc. But also if it does break DataGraphs we should mark this PR as breaking with a minor version bump.

@jack-dunham
Copy link
Copy Markdown
Contributor Author

jack-dunham commented May 27, 2026

inquire what specifically about the PR is breaking

For DataGraphs, there's a test of the function empty_graph on a DataGraph (checks this function removes data). I have moved this function from NamedGraphs to GraphsExtensions, as is generic to any AbstractGraph, so the import statement in the tests fails.

That should be the only place where code is breaking AFAIK. We can reverse this change, but it seems logical to move that function in this PR.

@mtfishman
Copy link
Copy Markdown
Member

inquire what specifically about the PR is breaking

For DataGraphs, there's a test of the function empty_graph on a DataGraph (checks this function removes data). I have moved this function from NamedGraphs to GraphsExtensions, as is generic to any AbstractGraph, so the import statement in the tests fails.

That should be the only place where code is breaking AFAIK. We can reverse this change, but it seems logical to move that function in this PR.

Can we add a statement using .GraphsExtensions: empty_graph in NamedGraphs for backwards compatibility?

Comment thread src/lib/PartitionedGraphs/src/quotientvertex.jl
Comment thread src/lib/PartitionedGraphs/src/quotientvertex.jl
Comment thread src/lib/GraphsExtensions/src/abstractgraph.jl Outdated
function forest_cover(g::AbstractGraph; spanning_tree = spanning_tree)
edges_collected = edgetype(g)[]
g = similar_dataless_graph(g)
g_reduced = copy(g)
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.

Probably doesn't matter too much, but I don't see what this copy is needed for since it doesn't look like the graph is being modified in-place. If it isn't needed we can just write g_reduced = g if the point is primarily to have a different variable name to use. I would just find that clearer since when I saw a copy I then expected to see an in-place operation somewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@mtfishman mtfishman merged commit 24f10ea into main May 28, 2026
21 checks passed
@mtfishman mtfishman deleted the jd/fix-forest-cover-edge-sequence branch May 28, 2026 21:20
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