-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
Cythoned UniqueRepresentation #14054
Comments
comment:1
Note that the patch also needed to change some auxiliary class For the timings, I use
With sage-5.6.rc0 plus #14017:
Adding the patch from here:
Hence, the time drops by 2/3. I did run make ptest successfully. Needs review! |
comment:2
Cc to Nicolas as the original author of |
comment:3
I just did some experiments with the tp_hash function from Python's C-API: It is 1/3 faster than a cythoned hash. I'll try to do similar things with the comparison methods. |
comment:4
While we are at speeding up Some classes misuse I suggest to split the two features. |
comment:5
FWIW, I finished a more experimental and rather intrusive version of Idea:
It remains possible to override those parts of comparison that can't be decided by looking at identity (such as "a<b" if "a is not b"). It would be great to just define the fast hash and comparison for I still think it is a good idea to separate Let the patchbot do some work: Apply trac14054_fast_methods.patch |
comment:6
From sage-devel, I understand that people think that separating the cache feature from the uniqueness feature of However, in my old patch, I was enforcing uniqueness behaviour for instances of Question In the current implementation, inheritance from Patchbot reported two failures with the previous patch version. I guess that's because of an additional dependency. So, as soon as I have a decent internet connection, I'll download the latest beta, and rebase on top of it. Apply trac14054_fast_methods.patch |
comment:7
Other question: Does |
comment:8
The updated patch should make the coverage script happy, but three tests with 5.7.rc0 currently fail. I am downloading 5.7.rc0 now. Apply trac14054_fast_methods.patch |
comment:9
I am not qualified to look over this ticket, but glancing at it I spotted this
which looks like a typo. |
comment:10
Replying to @sagetrac-jlopez:
Yes, thank you for spotting it! Will remove it when I rebase the patch against 5.7.rc0. |
comment:11
Hey Simon, Let me know when this is ready for review again. Best, Travis |
Reviewer: Travis Scrimshaw |
comment:12
The patch should now be ready for review. Two questions that I'd like to have addressed:
Pathbot: Apply trac14054_fast_methods.patch |
This comment has been minimized.
This comment has been minimized.
comment:13
To answer the question about the hash contract: Apparently dictionaries use the rich comparison methods and not cmp:
Since
Hence, dictionaries use comparison by |
comment:14
Replying to @simon-king-jena:
Yes, you should. I'm pretty sure changing
I think Python requires There's another peculiarity for membership and lookup in python:
They explicitly mention this in the documentation: because hash collisions are rare, they first test "is" for dict lookup before trying "==" (it's cheaper). |
comment:15
Replying to @nbruin:
OK.
Right, that's a difference.
Nope! See my post on sage-devel. If you have a non-cdef class, then it seems So, the decisive question is: Do dictionaries compare stuff by cmp(a,b)==0 or by a==b? It is the latter, and thus making For now, it needs work, because I will delete the C API hack, and apparently some script of the patchbot has a complaint... |
Attachment: trac14054_fast_methods.patch.gz Separate cache and uniqueness. |
comment:16
Done! It seems that the patchbot complains about an increased startup time. How did that happen? Is it because of a slightly longer mro for Patchbot: Apply trac14054_fast_methods.patch |
comment:17
What's your rationale to define 'a < b' etc. when The behaviour you are implementing is much easier to explain if you don't override those cases: Then you can just say that I think |
comment:18
Hey, Replying to @nbruin:
So how would you want comparisons in the complex numbers to behave? In python, they return an error:
However in sage they are not so well-behaved (see #14088):
so there's no prescribed sage way. As far as the actual comparison code, I think it would be better to do something like
but this is a micro-optimization, so feel free to ignore this.
I believe the response to both of these points depends on how we want to do comparison between objects (when there is not a [natural] ordering). Last thing for now, shouldn't we issue a deprecation warning for Thanks, Travis |
comment:19
The issue is that if someone wants to define
they will find that
which might surprise them, because they thought that There have been extensive discussions about what inequality testing SHOULD be in sage and for the most part the implementation here is staying clear of the topic (which I think is a good thing). There's just this one small optimization that's probably usually OK, but if left out makes for much more predictable behaviour. |
comment:20
Replying to @nbruin:
Python does not. But I think "comparison by identity" implies a semantics. And that is:
OK.
Good idea. Replying to @tscrim:
I think I introduced it. But when? Or what ticket? I don't think anyone used it. |
comment:70
FWIW I also get the same error as the patchbot. |
This comment has been minimized.
This comment has been minimized.
comment:71
Now it should work(T). Apply trac14054_fast_methods-5.8.patch trac_14054-fix-rigged-list.2.patch |
comment:72
This fails to apply for me:
|
comment:73
Argh. Jeroen forgot to update the list of dependencies, it seems. |
comment:74
Rebasing really has been trivial. The error was about a missing newline at the end of the file... Apply trac14054_fast_methods-5.8.patch trac_14054-fix-rigged-list.2.patch |
comment:75
Note that the tests in rigged_configurations do pass for me, with
applied on top of sage-5.8.beta0. But they fail if I have some more patches applied. In other words, I get the impression that sorting of the output of |
comment:76
Arrgh. Can it be that Jeroen, what can we do, since apparently sorting the output is not available here? I would say that it is not the fault (for a reasonable definition of "fault") of my patch that the test in rigged_configurations is unstable. |
comment:77
Would it be better to give them an (somewhat unnatural) ordering or to change the doctest? Actually...why not just make it |
comment:78
Replying to @simon-king-jena:
True, but with doctests there is no alternative but to shoot the messenger (i.e. the person adding the patch causing the doctest failure always gets the blame) |
comment:79
Replying to @tscrim:
I would be fine with making it random, and test that the length of the output (or another easy invariant) is correct. Is there a mathematically meaningful ordering? From the code, I guess that rigged configuration elements rely on list of tableaus, and if the tableaus can be ordered then one might have some kind of lexicographical ordering, perhaps. But this should be on a different ticket (and perhaps would not make sense at all), so that I would prefer to change the test. Jeroen, what is your opinion on that matter? |
comment:80
Thankfully I'm here to take the bullet. :P I don't know of any mathematical meaning of sorting rigged configurations. I don't think there is one... The reason why there's different (unsorted) outputs is because at the backend of the iterator in |
Mark output of |
comment:81
Attachment: trac_14054-fix-rigged-list.2.patch.gz I have updated the patch, marking the test random and testing that the length of the list coincides with the cardinality. Apply trac14054_fast_methods-5.8.patch trac_14054-fix-rigged-list.2.patch |
comment:82
PS: With the new patch, the tests will also pass (for me, at least) when I apply the remaining patches in my queue... |
comment:83
Everything looks good to me as well. I don't know why the patchbot just timed-out so I gave it a kick. For patchbot: Apply: trac14054_fast_methods-5.8.patch trac_14054-fix-rigged-list.2.patch |
comment:84
Hooray, and the patchbot doesn't complain either, except for the fact that a new module is loaded during start-up. But this can hardly be avoided in this case, and the patchbot does not observe the slightest increase in startup time :-) |
comment:85
Replying to @simon-king-jena:
Just for the record: in similar situations, I occasionally used the following idiom:
Which makes the output deterministic (well, assumming repr is ...) even if there is no natural total ordering on the objects to be sorted. |
comment:86
I forgot to say: great job getting this done! Thanks! |
comment:87
Replying to @simon-king-jena:
Well, it didn't pass tests :-) But seriously: is there any particular reason this patch should be in sage-5.8? I'd rather not take the risk and postpone it for sage-5.9.beta0. |
comment:88
Replying to @jdemeyer:
Well, it does, with the current version of the second patch. |
Merged: sage-5.8.beta4 |
UniqueRepresentation
provides a comfortable way to create unique parent structures, and automatically provides a hash and certain comparison methods.Problems:
ClasscallMetaclass
and thus has to be a Python class. That's bad for speed.Here, I suggest to
sage.unique_representation.CachedRepresentation
as one base ofUniqueRepresentation
.sage.misc.fast_methods.WithRichCmpById
, that provides hash and rich comparison, as expected for unique instance behaviour.Apply
Depends on #14017
Depends on #6495
Depends on #14182
Depends on #14040
Depends on #14011
CC: @nthiery
Component: performance
Keywords: cython UniqueRepresentation
Author: Simon King
Reviewer: Travis Scrimshaw
Merged: sage-5.8.beta4
Issue created by migration from https://trac.sagemath.org/ticket/14054
The text was updated successfully, but these errors were encountered: