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
adding extendability problem (2nd try) #4890
Conversation
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.
Can you add your new function to the doc/reference/algorithms/bipartite.rst file? Use the same form as for the other modules. Your's has a single function in it so it will be short. Be careful of the spacing to match that of the other modules being documented in there.
That way the autodoc system will find your function and slip the docstring into the main documentation.
Also, please add your module and function to the __init__.py
file in the bipartite
directory. Use a similar syntax as for the other modules. You should be able to say
import networkx as nx
G=nx.path_graph(4)
nx.bipartite.extendability(G)
Igraph made a new release right before you updated your PR: I haven't looked into it yet, but the error is not related to what you did. One of us will sort out the igraph issue and let you know what to do next. |
This looks good... Can you check out the docs (starting at the bipartitie reference to find_extendability) These are available from the final test "Details" link. The final test is a "Build Artifact" -- that is, something created during the Circle CI test -- it is a build of the documentation webpages. Anyway, you can see what the docs will look like in the online documentation and change things if you want. It looks like the docstring needs different underlines on the sections:
to similar but different:
Similar changes to the other sections will help them format nicely too. |
I followed your instructions and made all necessary changes. Also, i changed the docs. It is not nice to see an example on the documentation webpage for bipartite module. It seems the tests did not fail this time and worked properly. |
I got an error again. Please give me instructions how to fix it when you are avalaible. |
I'm not sure what exactly is causing tis error, but it is certainly not your code. # add the remote if you haven't before...
git remote add upstream https://github.com/networkx/networkx.git
git remote -v # check that it worked
git branch -v # make sure you are on the branch you want to update
git pull upstream main
# there may be some conflicts when merging if someone has made changes on the main branch to files you are changing.
# edit those files to make sure you don't un-do whatever someone else did that conflicted with your work.
git status
git add ...
git commit -a
git push origin <branchname> # or just `git push` if you aren't doing other stuff in other branches you don't want pushed |
So i guess that can not contribute to that error. |
Correct, the error was unrelated to your changes.
The problem has been fixed on |
Thank you. It worked this time |
Unfortunately, an error occured again. |
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.
I haven't had a chance to take a detailed look, but a couple things jumped out to me as potential improvements:
- I think the amount of comments in the code can be significantly reduced to improve readability. One of the nice things about Python is that the code itself is very readable, so adding explicit commenting is often unnecessary. Of course, there's a bit of subjectivity to this, but a good rule of thumb is "if I came back to this code in 6 months, would the additional comment help me understand what's happening".
- Re: the tests --- they seem to be quite specific; are they derived from somewhere specific, e.g. one of the papers referenced in the docstring? If so, it would be nice to reference them in test docstrings.
- Also re: the tests - I'm not 100% sure, but from a quick glance it seems that explicitly specifying the nodes is unnecessary (i.e. the
add_nodes_from
step could be skipped). It would only be necessary if you wanted to add nodes that were not connected, but AFAICT that's never the case. Also, it's a minor thing but you could save quite a few characters by using integer nodes instead of strings!
I'll take a closer look as soon as I have a chance.
By mentioning that the amount of comments can significantly reduced, did you refer to the ones made in the code or the theory part ? |
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.
By mentioning that the amount of comments can significantly reduced, did you refer to the ones made in the code or the theory part ?
Good question - I was referring to some of the inline comments in the code itself. See below for an example. I've left one example, but I think you could trim quite a few more of the inline comments along the same lines.
The tests are actually examples made by me and not by the papers. I am sure that they are correct. In case it will be helpful, i could mention one more theorem which helps anyone in constructing a k-extendable graph.
Got it, thanks for the info. An additional not on how the tests are formulated would be useful I think, but not necessary!
What do you suggest me to do in order to fix the last mentioned problem ( replace add_nodes_from ) ?
The add_edges_from
method automatically adds any nodes from the edges themselves if the nodes are not already present in the graph. Therefore, you should be able to eliminate the nodelist and the call to add_nodes_from
from the tests --- see example below. There are some potential exceptions to this, e.g. if the ordering of the nodes matters or if you are trying to add nodes that are not connected to any other edges, but AFAICT that's not the case.
I guess that all the necessary changes have been done. Please let me know if you would like to make any additional change. |
I was wondering about whether the code is going to be added in networkx library. |
Thanks for the ping and sorry for the delay; the release of NetworkX v2.6 has taken up a lot of time recently and we haven't had a chance yet to switch gears back to reviewing new contributions for later releases. I aim to give this PR another review as soon as I can. |
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!
I guess the main big questions in this review pertain to whether you might want to include other related functions. That might be beyond the scope of this PR though... Thanks for this function.
Lemma([1]) | ||
Let M be a perfect matching of G. G is k-extendable if and only if its residual | ||
graph $G_M$ is strongly connected and there are $k$ vertex-disjoint directed | ||
paths between every vertex of U and every vertex of V. |
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.
Can you add a sentence or two after the Lemma to explain why/how this lemma relates to this function? Are you explaining the algorithm you use -- there must be a reason to include this lemma at this point.
This lemma also leads to a question of whether you should provide a function that returns the residual graph.
Actually extendability is defined as the maximum k for which the graph is k-extendable. |
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.
I took the liberty of pushing up some formatting-related changes to the docstring. I had a few other questions/suggestions from another pass through the implementation.
One general note about the tests: I noticed that some of the graphs used can actually be constructed using networkx generators. IMO it's an improvement to specify the test graphs in this way when possible, as it makes the test much more readable! I left an explicit suggestion for the first, but would recommend repeating that pattern as far as possible for the other test cases (e.g. I noticed the second test is the Platonic cubical graph).
A good canonical article to link to for k-extendable graphs is: As for names, the original article uses Thoughts? (These two items fulfill my missions stated above, so I have checked them in the comment.) |
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.
This LGTM too, thanks @gsemer and @dschult !
I took the liberty of pushing up a few minor changes: some docstring formatting things in 659138a , and a few additional tests for exception-raising branches of the code in 4188a13 . Hopefully these aren't too controversial, but don't let them be a blocker either - feel free to reset and merge without them!
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.
Nice changes! Thanks!
Looks ready for merging to me.
* adding extendability problem (2nd try) * updated tests * updated tests * updated tests round 3 * updated tests round 4 * update tests round 5 * subtraction of a comment in raise part * updating files for extendability * review changes * review the changes * new changes * new changes * new changes 2 * Fixup docstring formatting. * From review: Edit docs, rename funct, simplify tests, use list comp * fix lint * remove selfloop test.Rely on bipartite test instead. * Docstring formatting touchups. * TST: Add tests for exceptions. --------- Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@caltech.edu>
* adding extendability problem (2nd try) * updated tests * updated tests * updated tests round 3 * updated tests round 4 * update tests round 5 * subtraction of a comment in raise part * updating files for extendability * review changes * review the changes * new changes * new changes * new changes 2 * Fixup docstring formatting. * From review: Edit docs, rename funct, simplify tests, use list comp * fix lint * remove selfloop test.Rely on bipartite test instead. * Docstring formatting touchups. * TST: Add tests for exceptions. --------- Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@caltech.edu>
No description provided.