Skip to content

Fix intermittent test failures in expander graph generator tests - #8048

Merged
dschult merged 4 commits into
networkx:mainfrom
Peiffap:maybe_regular_expander_test
May 17, 2025
Merged

dschult merged 4 commits into
networkx:mainfrom
Peiffap:maybe_regular_expander_test

Conversation

@Peiffap

@Peiffap Peiffap commented May 16, 2025

Copy link
Copy Markdown
Member

Fixes gh-8046.

This adds an explicit seed to the maybe_regular_expander and random_regular_expander_graph (is there a reason for the inconsistency in appending _graph to generator names?) tests which avoids stochastic failures when the maximum number of iterations gets exceeded.

Since this is a simple fix and the linked issue has a discussion surrounding how it should be fixed, this can also be left as a good first issue imo.

Peiffap added 2 commits May 16, 2025 16:23
In `maybe_regular_expander` and `random_regular_expander_graph` tests
Fixes networkxgh-8046
dschult
dschult previously approved these changes May 17, 2025

@dschult dschult left a comment

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.

As for adding _graph at the end of the function name, we want to have the suffix when the function creates a graph. So this case should be maybe_regular_expander_graph. In the review of the PR that created this I got the main function to add the _graph suffix, but got distracted with whether maybe_regular_expander was a helper function and never returned to thinking about its name. So that's my bad --

I guess we could update the name and deprecate the old name. That can be a separate PR.

I approve this PR.

@dschult dschult left a comment

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.

OK... just after I approved the PR, I built a loop over seed values and found a seed that makes it fail (6818) -- and then looped over max_tries using that seed to find that it succeeds for max_tries=130.

Can you add a new test of maybe_regular_expander and its max_tries?
It should verify that convergence fails with seed 6818 and that it succeeds with that seed when max_tries=130?

Thanks!

Code for exploring seed impact
import networkx as nx

d, n = (4, 10)

print(f"seed worked:", end='')
for seed in range(50000):
    try:
        G = nx.maybe_regular_expander(n, d, seed=seed)
        if seed % 100 == 0:
            print(seed, end=', ')
    except nx.NetworkXError:
        print(f"seed raised!! {seed=}")
        break
print("Done check various seed values\n")

# results  seed=6818 is the first seed that
#       fails to converge for 100 max_tries

for max_tries in range(100, 200, 10):
    try:
        G = nx.maybe_regular_expander(n, d, max_tries=max_tries, seed=6818)
        print(f"{max_tries=} works with seed 6818!")
        break
    except nx.NetworkXError:
        pass
# works for max_tries=130

@dschult
dschult self-requested a review May 17, 2025 01:39
@dschult
dschult dismissed their stale review May 17, 2025 01:41

Add tests of not converging and then converging when max_tries is increased

@Peiffap

Peiffap commented May 17, 2025

Copy link
Copy Markdown
Member Author

I've added the convergence tests for the max_tries argument. I'll address the function name change in a separate PR once this gets merged.

@dschult dschult left a comment

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.

I approve this PR.

@dschult
dschult merged commit d9e78f8 into networkx:main May 17, 2025
@Peiffap
Peiffap deleted the maybe_regular_expander_test branch May 18, 2025 11:17
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

MAINT: Finicky test for maybe_regular_expander

5 participants