-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
faster matroid 3 connectivity #18539
Comments
This comment has been minimized.
This comment has been minimized.
Commit: |
New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:8
Running the following code shows the new implementation matches the current behavior on named matroids.
I will generate some larger examples to test the running time and start optimizing. For the base case, I need to access Uniform(r,n). A direct import seems to cause circular dependency. If I use
then the error |
comment:9
Replying to @chaoxu:
A matroid of rank 1 is uniform if and only if it has no loops, and dually a matroid of corank 1 is uniform iff it has no coloops. So you could also replace your test
with this simpler one
|
comment:10
While I agree that Rudi's method is better (isomorphism testing is VERY expensive), let's look at the import issue too. Was your import inside the method instead of global? You might want to look at the way it was done in, for instance, the _minor method in matroid.pyx. I think you can't do it better than that. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:12
Thanks Rudi, I have incorporated your suggestions. It's much faster now. One can use the following code to test the running time of the current implementation and the original one.
I also benchmarked on 3-connected binary matroids listed here. The old algorithm takes 925 ms, the new one takes 51 ms. For correctness, I will try to see if the original and the new implementation agrees for all matroids with at most 9 elements. (data from Database of Matroids). |
all matroids on n<= 9 elements with rank <= n/2 |
comment:13
Attachment: matroids9_low_rank.sobj.gz Replying to @chaoxu:
That really is very nice work. Cheers! What part of your code is currently using most of the time on these test cases?
I have attached the set of matroids on at most 9 elements, perhaps that will save you some time translating their data. If you want I can also send the Sage code I used to generate these matroids, just let me know. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:16
Replying to @sagetrac-Rudi:
Thanks, that's really helpful. I found a bug and now it have been fixed. Now it works for all test cases. I'm pretty convinced of the correctness.
For the named cases, _corank and minor operation taking the most of the time.
I will get it to return a separator and write some docs for the next update. |
comment:17
Replying to @chaoxu:
Thanks for sending that data. The many calls to circuits() are probably happening in the Matroids.components() routine. I think I may have written that routine, and looks as if I did not really optimize it for speed.
So the following tweaks to
You could also consider rewriting a bit more, use the above when Since your routine is_3connected_beta also computes fundamental cocircuits, you would also gain a bit by using the unguarded _fundamental_cocircuit. It is perhaps wasteful to compute those fundamental cocircuits again in It is very, very strange indeed that a single call to A quicker method to create the parallel class of e is:
The minor-taking/deletion is also expensive in your method. Improving the inefficiency of |
comment:18
Hi Chao, somehow the inefficiency of components() became a major earworm for me today, so I coded a more efficient version for BasisExchangeMatroid (ticket #18591) to get it out of my system. The real inefficiency turned out to be in the set union operations, and calculating with bitsets rather than python sets works miracles for that. I also felt a bit bad for luring you into my bad habits of premature code optimization, but by just using my patch you can stay focussed on testing correctness and enhancing functionality, which is probably better. I realized why is_cosimple() is that much slower than is_simple() for BinaryMatroids (and Ternary and Quaternary). There is a specialized ultra fast method to get a fundamental cocircuit for such matroids, essentially copying the row of a bitpacked matrix (which is a bitset) into another bitset, which is the internal representation of the cocircuit. For circuits you are back to touching each of the groundset elements one by one, which is way slower. This asymmetry makes closure() faster that coclosure, and in turn is_simple faster than is_cosimple. I still need to see what is a clean way to solve that. Rudi |
comment:42
Hi Chao, I think the code as such looks great and works great. Repair these last few issues and I'll give a positive review: The docstring of is_3connected only mentions BC under When _is_3connected_BC throws In the docstring of _is_3connected_CE and _is_3connected_BC, there are several X and one T that need to have single accolades (now double). You can check the appearance of the docstring in the notebook by entering Finally, I don't believe keeping&depricating the option If the others agree you can perhaps still change this. Otherwise I'll give the positive review after you settled the above 3 issues. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:44
|
Changed reviewer from Michael Welsh to Michael Welsh, Rudi Pendavingh |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:46
Code compiles, tests succeed, docs build. Positive review! |
comment:47
merge conflict, probably #18448 |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:50
What can I do at this point to resolve the merge conflict? |
comment:51
Hi Chao, I am also still learning git so perhaps I'm not the right person to give expert advice. But take a look at the way a merge conflict is resolved in this recent ticket #17492. The way to go seems to be to merge the conflicting ticket #18448 into your code. You can do so by a git trac pull 18448 while working on your ticket (this is destructive so if you want to be safe, perform a merge of the two patches in a separate branch). The automatic merge will partially fail and you have to repair some of the source (probably matroid.pyx). Places where the automerger could not decide what to do will be indicated in the source with <<< and >>>. I doubt that the manual merge will be very difficult in this case, the issue is probably that the new code in both tickets are more or less in the same location. If you want, I will attempt the merge for you. Just merging develop into your branch as you just did may not suffice, since 18448 is not yet part of develop. Cheers, |
Branch pushed to git repo; I updated commit sha1. Last 10 new commits:
|
comment:53
Thanks Rudi, I followed your steps. |
comment:54
Yes, that should do it. Positive review again. |
Dependencies: 18448 |
Changed branch from u/chaoxu/faster_matroid_3_connectivity to |
Implement the efficient 3 connectivity algorithm.
R. E. Bixby, W. H. Cunningham, Matroids, Graphs, and 3-Connectivity. In Graph theory and related topics (Proc. Conf., Univ. Waterloo, Waterloo, ON, 1977), 91-103
Depends on #18448
CC: @sagetrac-Stefan @sagetrac-yomcat @sagetrac-Rudi
Component: matroid theory
Author: Chao Xu
Branch/Commit:
482ce85
Reviewer: Michael Welsh, Rudi Pendavingh
Issue created by migration from https://trac.sagemath.org/ticket/18539
The text was updated successfully, but these errors were encountered: