Skip to content
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

Cached methods with do_pickle=True fail for UniqueRepresentation objects #28096

Open
kwankyu opened this issue Jul 2, 2019 · 57 comments
Open

Comments

@kwankyu
Copy link
Collaborator

kwankyu commented Jul 2, 2019

The decorator @cached_method(do_pickle=True) is used to make a method to cache the result and the cached result pickled along with the object.

This fails for objects of UniqueRepresentation class. It is a consequence of the defective behavior of UniqueRepresentation object not putting its state into the pickle.

This ticket solves the problem. A discussion on this issue was in

https://groups.google.com/forum/#!topic/sage-devel/n7v71cnVTmk

CC: @simon-king-jena @tscrim @nbruin

Component: pickling

Author: Kwankyu Lee

Branch/Commit: u/mkoeppe/28096 @ ab2eb86

Issue created by migration from https://trac.sagemath.org/ticket/28096

@kwankyu kwankyu added this to the sage-8.9 milestone Jul 2, 2019
@kwankyu
Copy link
Collaborator Author

kwankyu commented Jul 2, 2019

Branch: u/klee/28096

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jul 2, 2019

Author: Kwankyu Lee

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 2, 2019

Commit: f17e57a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 2, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

f17e57aMake UniqueRepresentation do_pickle

@nbruin
Copy link
Contributor

nbruin commented Jul 3, 2019

comment:4

We can definitely not turn pickling on by default. See #15692.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jul 3, 2019

comment:5

This is not about turn pickling on by default. This turns on pickling only for @cached_methods with do_pickle=True.

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jul 3, 2019

comment:6

This ticket makes UniqueRepresentation objects do what other sage objects do, for pickling cached methods.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

09fc937Ignore cached functions with do_pickle=False

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Changed commit from f17e57a to 09fc937

@kwankyu
Copy link
Collaborator Author

kwankyu commented Jul 3, 2019

comment:8

To a reviewer:

Before this ticket,

  • the cached function attached to cached method with do_pickle=False (the default) is not pickled

  • the cached function attached to cached method with do_pickle=True is not pickled

With this ticket and before the last commit,

  • the cached function attached to cached method with do_pickle=False (the default) is pickled without the cache

  • the cached function attached to cached method with do_pickle=True is pickled with the cache

After the last commit,

  • the cached function attached to cached method with do_pickle=False (the default) is not pickled

  • the cached function attached to cached method with do_pickle=True is pickled with the cache

This last pickling behaviour of UniqueRepresentation objects is somewhat halfway between the old pickling behavior of UniqueRepresentation objects and that of other sage objects (second behavior).

The last version seems preferable because it does not increase the size of a pickle to keep unnecessary information, namely cached function without the cache.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Changed commit from 09fc937 to c979635

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

c979635Fix a format mistake

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

983577bMerge branch 'develop'
9d6e0c7Rename to is_pickled_with_cache

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Changed commit from c979635 to 9d6e0c7

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Changed commit from 9d6e0c7 to 6d47b68

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 3, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

6d47b68A little more documentation fixes

@kwankyu

This comment has been minimized.

@simon-king-jena
Copy link
Member

comment:14

After a brief look at the diff, it seems to me that there are many changes that have nothing to do with the purpose of this ticket: You remove from future import absolute_import and you have various changes of the following form:

@@ -167,9 +167,9 @@ class Manifolds(Category_over_base_ring):
 
             TESTS::
 
-                sage: TestSuite(Manifolds(RR).Smooth()).run()
                 sage: Manifolds(RR).Smooth.__module__
                 'sage.categories.manifolds'
+                sage: TestSuite(Manifolds(RR).Smooth()).run()
             """
             return self._with_axiom('Smooth')

Why?

@kwankyu
Copy link
Collaborator Author

kwankyu commented Aug 5, 2019

comment:15

Replying to @simon-king-jena:

After a brief look at the diff, it seems to me that there are many changes that have nothing to do with the purpose of this ticket: You remove from future import absolute_import

Right. This is nothing to do with the purpose of the ticket. You know that this import statement is not necessary any more since python 2.7. It happens that as I am writing a patch for a ticket, I encounter things to be easily fixed, like obvious typos, docstrings in bad style, unnecessary imports (like the above) and so on. Sometimes I fix them. Other times I pass them.

Is this bad? Do you think I should revert these small changes not related with the purpose of the ticket before I push the commits?

I think if developers do not make such spontaneous fixes, improvement of the overall quality of sage code will get slower.

and you have various changes of the following form:

@@ -167,9 +167,9 @@ class Manifolds(Category_over_base_ring):
 
             TESTS::
 
-                sage: TestSuite(Manifolds(RR).Smooth()).run()
                 sage: Manifolds(RR).Smooth.__module__
                 'sage.categories.manifolds'
+                sage: TestSuite(Manifolds(RR).Smooth()).run()
             """
             return self._with_axiom('Smooth')

Why?

This (and many others like this) was related with the ticket. Without this reordering, I got doctest failures. But strangely but happily, now with 8.9.beta5, I don't have them any more even without reordering. I will revert back these changes.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

c14d10bMerge branch 'develop'
bd0bebbMerge branch 'develop'
bcd500eRevert back unnecessary changes in doctests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2019

Changed commit from 6d47b68 to bcd500e

@mwageringel
Copy link

comment:17

Replying to @kwankyu:

Replying to @simon-king-jena:

After a brief look at the diff, it seems to me that there are many changes that have nothing to do with the purpose of this ticket: You remove from future import absolute_import

Right. This is nothing to do with the purpose of the ticket. You know that this import statement is not necessary any more since python 2.7.

I might be wrong, but I think this is still needed in Python 2.7, as I have recently had to add the statement in one of my own projects to solve a problem that did not exist with Python 3.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2019

Changed commit from bcd500e to 084a2ab

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

084a2abAdd back absolute_import

@kwankyu
Copy link
Collaborator Author

kwankyu commented Aug 5, 2019

comment:19

Replying to @mwageringel:

Replying to @kwankyu:

Replying to @simon-king-jena:

After a brief look at the diff, it seems to me that there are many changes that have nothing to do with the purpose of this ticket: You remove from future import absolute_import

Right. This is nothing to do with the purpose of the ticket. You know that this import statement is not necessary any more since python 2.7.

I might be wrong, but I think this is still needed in Python 2.7, as I have recently had to add the statement in one of my own projects to solve a problem that did not exist with Python 3.

Ah, I am wrong. You are right. I had somehow wrong understanding on this matter. I added back the imports.

Thanks!

@mkoeppe mkoeppe modified the milestones: sage-9.2, sage-9.3 Oct 24, 2020
@mkoeppe
Copy link
Member

mkoeppe commented Mar 15, 2021

comment:39

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Mar 15, 2021
@mkoeppe
Copy link
Member

mkoeppe commented Jul 19, 2021

comment:40

Setting a new milestone for this ticket based on a cursory review.

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@mkoeppe
Copy link
Member

mkoeppe commented Dec 18, 2021

comment:41

Stalled in needs_review or needs_info; likely won't make it into Sage 9.5.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe
Copy link
Member

mkoeppe commented Mar 21, 2022

comment:42

needs rebase

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 22, 2022

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

6f14c1cMake do_pickle work for UniqueRepresentation objects

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 22, 2022

Changed commit from f0b387e to 6f14c1c

@mkoeppe
Copy link
Member

mkoeppe commented Aug 13, 2022

Changed branch from u/klee/28096 to u/mkoeppe/28096

@mkoeppe
Copy link
Member

mkoeppe commented Aug 13, 2022

Changed commit from 6f14c1c to ab2eb86

@mkoeppe
Copy link
Member

mkoeppe commented Aug 13, 2022

comment:47

rebased


New commits:

ab2eb86Make do_pickle work for UniqueRepresentation objects

@kwankyu
Copy link
Collaborator Author

kwankyu commented Aug 13, 2022

comment:48

Thank you. This is long neglected, even by me. Perhaps it may need some revision.

@mkoeppe
Copy link
Member

mkoeppe commented Aug 13, 2022

comment:49

I ran into an issue with UniqueRepresentation in #19195, so I'm taking a look at open related tickets (#25388, #25389, #14167)

@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants