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 transitive_reduction (=> faster Poset creation) #17408
Comments
This comment has been minimized.
This comment has been minimized.
Branch: u/ncohen/17408 |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Commit: |
Changed keywords from none to poset |
This comment has been minimized.
This comment has been minimized.
comment:6
"That is actually pre-computing the equality relationships between all existing posets even if you never asked for it, and I personally see it as wasted time (especially since I cannot disable it)." What happens with key= -parameter? If you put a different one in every poset, I think it should not try to compare to posets with different key. |
comment:7
Indeed, but then the poset equality is broken. And I have no control the posets built by subfunctions like the poset constructors, the products, etc ... |
comment:8
Replying to @nathanncohen:
True. Should there be a global setting for it? Or an option in every poset function for this? |
comment:9
Truth is that I do not know. This feature is a class inheritance from Yep. Complicated. Don't know how to make both work easily Nathann |
comment:10
Objects produced in an inner loop should not be If you're finding that those "lightweight" posets need to be turned into full-fledged parents every now and again, then consider making it possible to create a full-scale poset from a lightweight one. See [#14356 comment:6] |
comment:11
Replying to @nbruin:
Maybe we already have this: it is called Hasse diagram? I mean, can we have a code generating only hasse diagrams and using functions from |
comment:12
Well, Jori wants to implement a way to enumerate all posets of a given size, so in this case we will have to pay a high tribute to parents. But how do you think that it should be implemented ? Jori is right that Hasse Diagrams have a lot of features already, but that is only... Well, a Hasse Diagram. No comparisons of elements, none of the products defined in the posets directly, well. What we would need as you say is a class exactly like Poset without the parent infrastructure, but how could we implement that with the smallest amount of copy/paste ? Nathann |
comment:13
|
comment:14
Replying to @nathanncohen:
It would require some thought and some major refactoring. The natural structure to me would seem to have a base class that does not inherit from UniqueRepresentation that implements all the basic stuff and then (hopefully) use multiple inheritance to equip this with the requisite parent stuff for the "full Parent POSet". If there are things that are incompatible between a usable "fast POSet" and a "full parent POSet" then the useful thing should probably inherit separately from the common base class. The "full parent poset" |
comment:15
What is the rationale behind current implementation? I mean, there must be some example where I understand the logic for, say, finite ring, but not for posets. |
comment:16
Replying to @jm58660:
I suspect it was done out of dogma: "Parents are supposed to be unique" in sage. That statement by itself is not correct: not all parents need to be unique. However, equal-but-non-identical parents can cause some minor problems in the coercion framework. The real catch is if you're building a parent that can serve as base for other parents that ARE unique representation. Because cache keys there are looked up by equality and not identity, you can really confuse the coercion framework to the point of getting buggy behaviour. See [#15248 comment:2] for an explanation of a classic example. There is always a solution to this: do not inherit from UniqueRepresentation or UniqueFactory but do inherit from WithEqualityById (or implement that by yourself). It gives you a very cheap but mathematically not terribly useful equality test. However, there's something to say for it: The two posets However, such strict equality might be too hard to swallow for people who want their computer algebra system to cater a little more to intuitive, human reasoning. In that case you can just make your parent non-unique, but still define equality to be by some looser equivalence relation. You should just document that your class is not appropriate for use as a base for another |
comment:17
Yooooo !
HMmmm... I am afraid that if I follow the mains lines of what you say, I have no clue how it is to be implemented in practice. I believe that the combinat guys use posets as exponents of polynomials, and that this is why they need a fast equality test. It would be cool if we could remove this We just can't give up enumerating posets up to isomorphism because of this cached equality test. And lose seconds like in the ticket's description. Nathann P.S. : What this ticket does is totally orthogonal to that, though, and still in |
comment:18
By the way I wonder if I should add a "if self.is_directed_acyclic()" in th function. I am not sure that those who use this Nathann |
comment:19
Replying to @nathanncohen:
For one thing, that use wouldn't require posets to be parents then. [possibly off-topic example] If you want to make POsets faster you should seriously consider splitting POsets-as-parents and POsets-as-objects. Both usage scenarios you describe seem to fall in the latter scenario, by the way, so perhaps POsets-as-parents aren't really needed beyond checking a box for which parents are available in sage. |
comment:20
Well, perhaps we could return "Poset-as-parents" when the user asks for a non-facade poset, and non-parent posets otherwise. Sigh. I'll write to the sage-devel and the combinat guys... Nathann |
comment:21
Replying to @nbruin:
Thank you for very good explanation! Generating all posets of size 7 up to isomorphism takes 18,5 second --- this is not a bottle neck then. But with #14110 the time drops to 2,5 seconds. And when generating just Hasse diagrams instead of posets it took 0,3 second. In the code I was asked to write this is the turning point: now slowest part is doing something with posets, not generating them. Maybe this is so specialized case that we should let posets to be like they are now. A user might then optimize by directly playing with Hasse diagrams. This optimization does not mean that you can do things with posets of size |
comment:22
(beyond the poset discussion, this ticket is still needing a review) |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:24
I removed the "acyclic" flag that nobody would have seen and added an automatic detection of acyclic graphs. This has a small cost, but as I believe that nobody ever calls this function except on acyclic graphs I would say that it is a win (really, nobody would have seen the optional flag). Nathann |
Changed branch from u/ncohen/17408 to public/ticket/17408 |
comment:25
There was a failing doctest, because undirected graphs do not have a is_directed_acyclic method. I have also made a few pep8 changes. Looks good to me. You can set a positive review if you agree with my changes. New commits:
|
Reviewer: Frédéric Chapoton |
comment:26
Helloooooo !
Oh, I see. Thanks !
You should see a doctor about that
Thanks again ! Nathann |
comment:27
doctests fail |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed branch from public/ticket/17408 to |
As reported on #17361, the call to
transitive_reduction
represents a non-negligible part of Poset creation.This branch re-implements it for acyclic graphs.
Now the critical part in the creation of a
Poset
is triggered byUniqueRepresentation
. As soon as you create aPoset
it is being compared with those that already exists... That is actually pre-computing the equality relationships between all existing posets even if you never asked for it, and I personally see it as wasted time (especially since I cannot disable it).Nathann
CC: @fchapoton @jm58660
Component: graph theory
Keywords: poset
Author: Nathann Cohen
Branch/Commit:
ade98aa
Reviewer: Frédéric Chapoton
Issue created by migration from https://trac.sagemath.org/ticket/17408
The text was updated successfully, but these errors were encountered: