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

Pickling and otherwise enhancing global options #18555

Closed
AndrewMathas opened this issue May 31, 2015 · 43 comments
Closed

Pickling and otherwise enhancing global options #18555

AndrewMathas opened this issue May 31, 2015 · 43 comments

Comments

@AndrewMathas
Copy link
Member

Instances of the GlobalOptions class in sage.structure.global_options do not pickle, which is annoying and causes various problems. (This is a defect.)

In addition, when the GlobalOptions class was introduced it was suggested in sage-dev that it "would be nice" if we could implement the syntax used in the IPython configuration:


    A.options.foobar = 1

in addition to

    A.options(foobar=1)

This ticket implements both of these features and, in addition, makes it possible to construct options classes dynamically.

As was also suggested on sage-dev, I have also renamed all of the global_options methods simply as options, with the global_options variants being deprecated. The "stand-alone" options classes such as PartitionOoptions, TableauxOptions, ... have also been deprecated and, instead, put inside their "parent" classes where they are accessible using the options method (global_options methods have been deprecated). This is cleaned up the code a little and it seems to speed up the sage start-up time.

The pickling is done by adding an extra module argument to the GlobalOptions that specifies the module which contains the class that the options are attached -- name of of the class defaults to the name of the options class but this can be explicitly set using the options_class argument. The options class is assumed to have an options method, and this is used to unpickle a pickle for an options class. GlobalOptions that do not arise as options methods for standard sage classes cannot be unpickled. The reason why the name of the module and class are passed, as strings, to GlobalOptions rather than the actual class is that this approach allows the options to be constructed during the initialisation of the (instance of the) class and, in turn, this allows the class to dynamically construct their options classes.

CC: @nathanncohen @tscrim

Component: interfaces

Keywords: days78, options

Author: Andrew Mathas

Branch/Commit: ba7dd98

Reviewer: Travis Scrimshaw

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

@AndrewMathas AndrewMathas added this to the sage-6.8 milestone May 31, 2015
@AndrewMathas
Copy link
Member Author

Changed keywords from none to options

@AndrewMathas

This comment has been minimized.

@AndrewMathas
Copy link
Member Author

Author: Andrew Mathas

@AndrewMathas AndrewMathas changed the title Pickling global options Pickling and otherwise enhancing global options Jun 3, 2015
@AndrewMathas
Copy link
Member Author

comment:3

As I am cleaning this up a related question comes to mind: the name GlobalOptions is slightly unfortunate because instances of this class are really just options for an associated family of objects. I can sort of forgive myself for using this name for the class, but in all of the instances of this class the associated "parent" classes have a global_options method that points back to its options class. This method is now being enshrined more firmly inside the code because it is exploited to allow pickling. I would be happier if these methods were simply called options, rather than global_options, even though this change would necessitate deprecating the existing global_options methods.

Thoughts?

@AndrewMathas

This comment has been minimized.

@AndrewMathas
Copy link
Member Author

@AndrewMathas
Copy link
Member Author

Commit: 2ba392f

@AndrewMathas
Copy link
Member Author

New commits:

f006a84Adding pickling methods
2ba392fInitial version - some failing doctests

@AndrewMathas

This comment has been minimized.

@AndrewMathas

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2016

Changed commit from 2ba392f to 12cb846

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2016

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

3a4a9d220618: imported sage.modules.tutorial_free_modules and thematic_tutorials/tutorial-implementing-algebraic-structures from the Sage-Combinat queue
3e3e35020618: fixed missing file
500d2d8Global options to options
52d7cf6Recasting options as attributes
64d0209Global options as class attributes
25ab72fFixing doctests
23f2c56Merging into 7.3.beta4
12cb846Fixing more doc-tests

@AndrewMathas

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2016

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

c676864Global options to options
9313ce8Recasting options as attributes
11a13f4Global options as class attributes
217b5b4Fixing doctests
b761fecMerging into 7.3.beta4
caabdb0Fixing more doc-tests
11b7080More doc-tests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2016

Changed commit from 12cb846 to 11b7080

@AndrewMathas
Copy link
Member Author

comment:12

Replying to @sagetrac-git:

This was to remove 20618 from the commit tree as it shouldn't have been there...

@tscrim
Copy link
Collaborator

tscrim commented Jul 2, 2016

@tscrim
Copy link
Collaborator

tscrim commented Jul 2, 2016

comment:13

Okay, I fixed the doctest failures with permutation.py. The issue was that the _Option (now Option so it appears in the doc) did not define a __ne__ method, and so it returned True for things like opt != X even when opt == X.

The other doctest failures were due to lack of conversion to options from global_options.

This is a very nice improvement over the current interface to (global) options. If the doctest pass for you and my changes are good, then you can set this to a positive review.


New commits:

0636c87Merge branch 'u/andrew.mathas/pickling_global_options' of trac.sagemath.org:sage into public/misc/pickling_global_options-18555
9642057Making everything work with the new API.
f42beb4Rename _Option to Option and some PEP8 to global_options.py.

@tscrim
Copy link
Collaborator

tscrim commented Jul 2, 2016

Changed commit from 11b7080 to f42beb4

@tscrim
Copy link
Collaborator

tscrim commented Jul 2, 2016

Changed keywords from options to days78, options

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 4, 2016

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

4013abbFixing failing doctests identified by the patchbot

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 4, 2016

Changed commit from f42beb4 to 4013abb

@tscrim
Copy link
Collaborator

tscrim commented Jul 5, 2016

comment:15

There's some doc issues in the manifold.py options: EXAMPLES:: and everything including and after sage: latex(f) is over indented.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 5, 2016

Changed commit from 4013abb to 3f5e0e9

@vbraun
Copy link
Member

vbraun commented Jul 6, 2016

comment:21

Reviewer name is missing

@tscrim
Copy link
Collaborator

tscrim commented Jul 6, 2016

Reviewer: Travis Scrimshaw

@vbraun
Copy link
Member

vbraun commented Jul 7, 2016

comment:23

Merge conflict, try next beta

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2016

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

ed5070dMerging 7.3.beta7

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2016

Changed commit from 8322fd5 to ed5070d

@AndrewMathas
Copy link
Member Author

comment:25

Merged into 7.3.beta7. Tests pass.

@vbraun
Copy link
Member

vbraun commented Jul 9, 2016

comment:26

Fails on 32-bit

sage -t --long src/sage/structure/global_options.py
**********************************************************************
File "src/sage/structure/global_options.py", line 599, in sage.structure.global_options.Option.__hash__
Failed example:
    hash( Tableaux.options.convention ) # indirect doc-test
Expected:
    -6673246059928475433
Got:
    -1691342633
**********************************************************************
1 item had failures:
   1 of   2 in sage.structure.global_options.Option.__hash__
    [135 tests, 1 failure, 0.03 s]

@tscrim
Copy link
Collaborator

tscrim commented Jul 9, 2016

comment:27

This just needs to mark the different output as # 32-bit and # 64-bit, but I'd change the actual test to hash(Tableaux.options.convention) == hash(Tableaux.options('convention') (it also doesn't need the # indirect doctest marker). Sorry for not catching that sooner.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 11, 2016

Changed commit from ed5070d to ba7dd98

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 11, 2016

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

ba7dd98Fixing hashed doct-test

@AndrewMathas
Copy link
Member Author

comment:29

Replying to @tscrim:

This just needs to mark the different output as # 32-bit and # 64-bit, but I'd change the actual test to hash(Tableaux.options.convention) == hash(Tableaux.options('convention') (it also doesn't need the # indirect doctest marker). Sorry for not catching that sooner.

Thanks Travis! Fixed and changed back to a positive review.

@vbraun
Copy link
Member

vbraun commented Jul 12, 2016

Changed branch from public/misc/pickling_global_options-18555 to ba7dd98

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

3 participants