New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] Random expanders utilities #6761
Conversation
To get the tests working, you need to set up the import and tests so that this function doesn't impact the rest of networkx when numpy isn't even installed. You've done some of it, but How to test functions/modules which use numpy/scipy/matplotlib, etc:
Hopefully I have remembered everything. This should fix the CI failures due to missing numpy. |
Ok thanks for the help, hopefully it won't break the CI pipeline now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you wrap the comment lines (or remove words/length from them so that the file is within the 88 char style for the code? (<80 is better but you can overflow to 88 occasionally)
For the doc_strings, the first line is used as a short description on links in the documentation to the page for that function. So could you move the long first lines down, add a short one-liner as a doc_string heading followed by a blank line and then finally the longer (paragraph) description of what the function actually does.
Thanks for this!
Also, since this is a new function, can you please make the keyword arguments "keyword only" by adding a *, between the positional arguments and the keyword arguments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution!
And sorry for the delay in our review.
I've got a few comments below -- many of which you could probably use the "batch commit" feature within the github interface -- where you commit the suggestions you "batch" all together as one commit. Remember to pull those changes to your local machine before making further changes. Some of the other comments will require you to make changes on your branch so if you prefer to make them all locally and then push them that is fine -- you don't have to use the github commit suggestions interface.
@dschult Thanks for review I've implemented almost all changes, just not sure about scipy since we need to know for sure we computed the second biggest eigenvalue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
Is the maybe_regular_expander
function a helper function that should be made private?
Should random_regular_expander
be called random_regular_expander_graph
?
Could you add a paragraph to each doc_string briefly explaining what an expander graph is -- and a Ramanajan graph where you bring that term up.
I wonder if the whlie loops could become effectively infinite. Often we put a max_tries
argument to avoid that, raising a NetworkXError if one is not found. If there's a reason that shouldn't be necessary here that's fine.
Because these involve random number generators, this should have a seed
argument and a decorator like nx.utils.np_random_state
to process the inoput and use the resulting input variable seed
when calling any function with random aspects.
You'll need to connect these to the documentation with an entry in doc/reference/generators/expanders.rst
. model it after paley_graph
I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have some (one?) example network where you know from a trusted source /publication/worked it out what the result should be? That would help a lot in ensuring that it is working.
The scipy eigsh function does return the largest two eigenvalues when the right which
option is specified. So I think we're good there.
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Thanks @rossbar for the review! I've added the seed pattern. Do you have any idea what's wrong with the failing test?
|
The invalid sequence comes from your docstring where the latex code is interreted as containing escaped special characters instead of as latex code. If you don't need special characters in your doc_string, take out the |
Ack -- I think I got it backwards... The doc_strings work with To fix it, replace all the double backslashes with single backslashes. |
Ok this is confusing me now it breaks the tests again. Can you fix this? |
You are correct -- the tests used to work. But we were getting warnings at import time, so a new test was added last week to check for warnings at import time -- and you were unfortunate enough to get caught by it. Sorry about that. I have got it working by making every doc_string that has latex in it a "raw string" (using I think this is ready to go, but I've only quickly checked the resolutions of @rossbar's suggestions. |
Thank you for the fix! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fcrozatier , I made a few very minor tweaks to the docstring but otherwise LGTM!
Adds functionality to both generate and assess whether graphs are regular expanders. * add maybe_regular_expander, is_regular_expander, random_regular_expander utilities --------- Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Hmm, the random test suite cron job is failing as the seed is tripping up |
Adds functionality to both generate and assess whether graphs are regular expanders. * add maybe_regular_expander, is_regular_expander, random_regular_expander utilities --------- Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Implements #6541