#16275: Hom: introduce a check argument to simplify the unpickling detection 
logic
-------------------------------------+-------------------------------------
       Reporter:  nthiery            |        Owner:
           Type:  enhancement        |       Status:  new
       Priority:  major              |    Milestone:  sage-6.2
      Component:  categories         |   Resolution:
       Keywords:  homset, pickling   |    Merged in:
        Authors:  Nicolas M. ThiƩry  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  
u/nthiery/hom__introduce_a_check_argument_to_simplify_the_unpickling_detection_logic|
  ae3ca8080a8412891722695d1e24e1dfe374d787
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Replying to [comment:3 tscrim]:
 > I agree with these changes, although I don't understand pickling well
 enough to answer those issues. Simon, could you render judgement on this
 or clarify the issue?

 Let's try...

 The problem occurs if Python's default way of pickling/copying is used:
 Assume that you have an object `O`, pickle it, and want to unpickle it
 into a new object `N`.

 When pickling `O` in Python's default way, `type(O)` and `O.__dict__` are
 stored. When unpickling, `N` is created as a new instance of `type(O)`,
 and `N.__dict__` is filled by unpickling the pickle of `O.__dict__`. Of
 course, when unpickling `O.__dict__`, `N` takes the role of `O`.

 The problem: It could be that you need `N.__dict__['foo']` in order to
 unpickle `N.__dict__['bar']`. To be more concrete, it could be that some
 morphism `phi` from `O` to somewhere else is stored as an attribute
 `O.foo`. Hence, to unpickle `phi`, you also need to unpickle some
 `Hom(O,P,C)` for some category `C`. So, `Hom(N,P,C)` will be created. But
 at that point, `N.__dict__` is not completely filled. Perhaps `N` can not
 tell whether it is an object of `C` before `N.bar` is available. Thus,
 some assertion during creation of the homset will fail.

 The obvious approach towards a solution: When we have a pickle, then the
 assertions need not be made, as we ''know'' that the to-be-unpickled
 object belongs to the category of the to-be-unpickled homset.

 In #14793, it was suggested to skip the assertion if the category of
 domain or codomain is not initialised, since this indicates that we are in
 the process of unpickling domain and/or codomain.

 Here, it is suggested to be more explicit and have an optional argument
 for skipping the assertion.

 I think explicit is better than implicit. Moreover, it has another use
 case (as demonstrated by Nicolas) and should also be faster than the old
 solution. Hence, I am all in favour of the new solution.

 The only problem is: (How) Do we care about old pickles whose unpickling
 requires to skip the assertion, but which are unaware of the "check=False"
 argument?

 I suggest the following scheme:
 {{{
     if check:
         if domain not in category:
             if domain's category is initialised:
                 raise error, since that means we are not unpickling an old
 pickle
         if codomain not in category:
             if codomain's category is initialised:
                 raise error
     proceed with creating the homset
 }}}
 Hence, the assertion is skipped if this is explicitly requested, and
 before raising an actual error it is verified if we need to skip the
 assertion implicitly.

--
Ticket URL: <http://trac.sagemath.org/ticket/16275#comment:9>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to