Repository navigation
Fix intermittent test failures in expander graph generator tests - #8048
Conversation
In `maybe_regular_expander` and `random_regular_expander_graph` tests Fixes networkxgh-8046
dschult
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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=130Add tests of not converging and then converging when max_tries is increased
|
I've added the convergence tests for the |
Fixes gh-8046.
This adds an explicit seed to the
maybe_regular_expanderandrandom_regular_expander_graph(is there a reason for the inconsistency in appending_graphto 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.