#13400: Use strong caches diligently
-------------------------------+--------------------------------------------
       Reporter:  nbruin       |         Owner:  robertwb     
           Type:  enhancement  |        Status:  new          
       Priority:  major        |     Milestone:  sage-wishlist
      Component:  coercion     |    Resolution:               
       Keywords:               |   Work issues:               
Report Upstream:  N/A          |     Reviewers:               
        Authors:               |     Merged in:               
   Dependencies:               |      Stopgaps:               
-------------------------------+--------------------------------------------

Comment (by nbruin):

 Replying to [comment:4 SimonKing]:
 > ... it ''is'' cached, mainly.
 >
 > Do we talk about the same version of sage? Namely, with #11943,

 In that case you might want to check if that ticket was properly merged in
 the
 5.3b2 source, as available in `sage.math.washington.edu:/home/release`.

 What I see is
 `sage/categories/covariant_functorial_construction.py:359`:
 {{{#!python
     @cached_method
     def is_subcategory(self, C):
         """
         .. todo:: doctests + explain why this method is needed
         """
         if C is self:
             return True
         return any(X.is_subcategory(C) for X in self._super_categories)
 }}}
 if I add  `print("is_subcategory(self=%s,C=%s)"%(self,C)")` as a first
 statement
 I get lines such as:
 {{{
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of quotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of quotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of sets,C=Category of fields)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of sets,C=Category of fields)
 is_subcategory(self=Category of quotients of sets,C=Category of fields)
 is_subcategory(self=Category of subquotients of sets,C=Category of fields)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of quotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 quotients of semigroups)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 commutative rings)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of quotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of sets,C=Category of
 subquotients of monoids)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 finite enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of quotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of sets,C=Category of finite
 enumerated sets)
 is_subcategory(self=Category of subquotients of monoids,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of sets,C=Category of fields)
 is_subcategory(self=Category of quotients of semigroups,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of semigroups,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of magmas,C=Category of
 fields)
 is_subcategory(self=Category of subquotients of sets,C=Category of fields)
 is_subcategory(self=Category of quotients of sets,C=Category of fields)
 is_subcategory(self=Category of subquotients of sets,C=Category of fields)
 }}}
 a lot of them, and as you can see, all "static" categories. None of those
 funny
 dynamically generated ones. If I decorate with `@cached_method` I get
 these
 lines at startup but not afterwards anymore.

 `make ptest` improves (5.3b2 + tickets + cached is_subcategory):
 {{{
 Total time for all tests: 989.4 seconds
 Total time for all tests: 994.4 seconds
 }}}

 and perhaps more significantly, the multimodular variant above now
 profiles to:

 multimodular echelonization loop (5.3b2 + tickets + cached
 is_subcategory):
 {{{
          1263618 function calls (1229625 primitive calls) in 5.191 seconds

    Ordered by: internal time

    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      1000    2.176    0.002    4.766    0.005 {method 'echelon_form' of
 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' objects}
      4994    0.330    0.000    0.590    0.000
 matrix_space.py:230(__init__)
      2142    0.297    0.000    0.374    0.000
 quotient_ring.py:322(__init__)
      5000    0.193    0.000    0.946    0.000 matrix_space.py:1180(matrix)
      6031    0.186    0.000    0.187    0.000
 dynamic_class.py:259(dynamic_class_internal)
      2142    0.120    0.000    0.139    0.000 {method 'ideal' of
 'sage.rings.ring.Ring' objects}
     16880    0.098    0.000    0.106    0.000 {method 'is_prime' of
 'sage.rings.integer.Integer' objects}
      1000    0.094    0.000    0.094    0.000 {method 'range' of
 'sage.rings.integer_ring.IntegerRing_class' objects}
      6253    0.088    0.000    0.272    0.000 category.py:112(_join)
 18121/6128    0.079    0.000    0.585    0.000
 lazy_attribute.py:506(__get__)
         1    0.075    0.075    5.193    5.193 <ipython console>:1(test1)
     14911    0.069    0.000    0.208    0.000 arith.py:401(is_prime)
    130255    0.057    0.000    0.057    0.000 {isinstance}
     43753    0.057    0.000    0.072    0.000 weakref.py:55(__getitem__)
     10000    0.055    0.000    0.713    0.000
 matrix_space.py:154(__classcall__)
      2962    0.051    0.000    0.256    0.000 {sage.rings.ring.is_Field}
      2000    0.048    0.000    0.235    0.000
 arith.py:1051(previous_prime)
      2142    0.046    0.000    0.726    0.000
 integer_mod_ring.py:191(__init__)
      1993    0.043    0.000    0.159    0.000
 matrix_space.py:1133(zero_matrix)
      4994    0.037    0.000    0.064    0.000
 matrix_space.py:904(_get_matrix_class)
 6000/1000    0.037    0.000    0.508    0.001
 category.py:1023(parent_class)
      7000    0.037    0.000    0.048    0.000
 category_types.py:261(__init__)
      3962    0.036    0.000    0.069    0.000
 sageinspect.py:917(sage_getargspec)
     19278    0.035    0.000    0.078    0.000 weakref.py:79(__setitem__)
      2000    0.033    0.000    0.053    0.000 sequence.py:86(Sequence)
     12000    0.030    0.000    0.059    0.000 misc.py:179(cputime)
     55239    0.029    0.000    0.058    0.000 category.py:148(<genexpr>)
       993    0.028    0.000    0.086    0.000 homset.py:80(Hom)
     14911    0.028    0.000    0.033    0.000 all.py:1(arithmetic)
 12994/9994    0.028    0.000    0.659    0.000
 unique_representation.py:452(__classcall__)
     48986    0.026    0.000    0.050    0.000 category.py:150(<genexpr>)
       993    0.025    0.000    0.050    0.000 homset.py:353(__init__)
     25236    0.025    0.000    0.025    0.000 weakref.py:228(__init__)
     38622    0.021    0.000    0.046    0.000
 category.py:1102(is_subcategory)
     12000    0.021    0.000    0.021    0.000 {resource.getrusage}
 12994/9994    0.021    0.000    0.636    0.000
 {sage.misc.classcall_metaclass.typecall}
      1000    0.019    0.000    0.168    0.000 misc.py:1051(srange)
     27378    0.019    0.000    0.029    0.000 weakref.py:223(__new__)
      1000    0.017    0.000    0.184    0.000 constructor.py:34(matrix)
 }}}
 '''Strongly caching matrix spaces''': Wouldn't help much with the current
 design.
 The primes used in some of the multimodular steps are randomized, so even
 when
 doing the same computation, you'll end up with other rings.

 It might be an idea to keep a cache of good fields for multimodular stuff,
 that
 get used before trying random primes. That at least saves creating the
 fields.
 Caching the matrix spaces might be painful, since you don't know which
 dimensions you'll need...

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13400#comment:11>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to