#31985 closed defect (fixed)

WQSym.M().basis(3) is broken

Reported by: Darij Grinberg Owned by:
Priority: major Milestone: sage-9.4
Component: combinatorics Keywords: WQSym, combinatorial Hopf algebras, ordered set partitions
Cc: Travis Scrimshaw, Darij Grinberg, lauve Merged in:
Authors: Darij Grinberg Reviewers: Frédéric Chapoton, Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 27b3b4c (Commits, GitHub, GitLab) Commit: 27b3b4cd55ac0b79dcd92f2a4c47d10eda5ebf03
Dependencies: Stopgaps:

Status badges

Description (last modified by Darij Grinberg)

Attached is a *minimal* fix, which defines

def subset(self, size=None, **kwargs)

for the classes OrderedSetPartitions_all and SetPartitions_all. Judging by partition.py, it might be conventional to also define this method for other classes of (ordered) set partitions, although I'm not sure why or what for.


This should return a basis for the degree-3 component of WQSym (and yes, it is finite):

sage: WQSym = algebras.WQSym(QQ)
sage: M = WQSym.M()
sage: M.basis(3)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/sage/local/lib/python3.6/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:10303)()
   1942             try:
-> 1943                 return cache[k]
   1944             except TypeError:  # k is not hashable

KeyError: ((3,), ())

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~/sage/local/lib/python3.6/site-packages/sage/structure/category_object.pyx in sage.structure.category_object.CategoryObject.getattr_from_category (build/cythonized/sage/structure/category_object.c:7074)()
    838         try:
--> 839             return self.__cached_methods[name]
    840         except KeyError:

KeyError: 'subset'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
~/sage/local/lib/python3.6/site-packages/sage/categories/filtered_modules_with_basis.py in homogeneous_component_basis(self, d)
    214             try:
--> 215                 S = self._indices.subset(size=d)
    216             except (AttributeError, ValueError, TypeError):

~/sage/local/lib/python3.6/site-packages/sage/structure/category_object.pyx in sage.structure.category_object.CategoryObject.__getattr__ (build/cythonized/sage/structure/category_object.c:6993)()
    832         """
--> 833         return self.getattr_from_category(name)
    834

~/sage/local/lib/python3.6/site-packages/sage/structure/category_object.pyx in sage.structure.category_object.CategoryObject.getattr_from_category (build/cythonized/sage/structure/category_object.c:7159)()
    847
--> 848             attr = getattr_from_other_class(self, cls, name)
    849             self.__cached_methods[name] = attr

~/sage/local/lib/python3.6/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2551)()
    366         dummy_error_message.name = name
--> 367         raise AttributeError(dummy_error_message)
    368     cdef PyObject* attr = instance_getattr(cls, name)

AttributeError: 'OrderedSetPartitions_all_with_category' object has no attribute 'subset'

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-5-446eb4b46bf3> in <module>
----> 1 M.basis(Integer(3))

~/sage/local/lib/python3.6/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:10437)()
   1946                 return cache[k]
   1947         except KeyError:
-> 1948             w = self._instance_call(*args, **kwds)
   1949             cache[k] = w
   1950             return w

~/sage/local/lib/python3.6/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller._instance_call (build/cythonized/sage/misc/cachefunc.c:9916)()
   1822             True
   1823         """
-> 1824         return self.f(self._instance, *args, **kwds)
   1825
   1826     cdef fix_args_kwds(self, tuple args, dict kwds):

~/sage/local/lib/python3.6/site-packages/sage/categories/filtered_modules_with_basis.py in basis(self, d)
    186                 return Family(self._indices, self.monomial)
    187             else:
--> 188                 return self.homogeneous_component_basis(d)
    189
    190         # TODO: Change `list(self._indices)` to `self._indices` and move

~/sage/local/lib/python3.6/site-packages/sage/categories/filtered_modules_with_basis.py in homogeneous_component_basis(self, d)
    215                 S = self._indices.subset(size=d)
    216             except (AttributeError, ValueError, TypeError):
--> 217                 S = [i for i in list(self._indices) if self.degree_on_basis(i) == d]
    218             return Family(S, self.monomial)
    219

~/sage/local/lib/python3.6/site-packages/sage/categories/enumerated_sets.py in __len__(self)
    477                 c = self.cardinality()
    478                 if c is Infinity:
--> 479                     raise NotImplementedError('infinite set')
    480                 return int(c)
    481             except AttributeError:

NotImplementedError: infinite set

Same problem with other bases.

I assume the problem is that OrderedSetPartition? has no subset(size=d) method.

Change History (16)

comment:1 Changed 18 months ago by Darij Grinberg

Description: modified (diff)

comment:2 Changed 18 months ago by Darij Grinberg

Authors: Darij Grinberg
Description: modified (diff)
Status: newneeds_review

comment:3 Changed 18 months ago by Darij Grinberg

Description: modified (diff)

comment:4 Changed 18 months ago by Darij Grinberg

Branch: public/ticket/31985
Commit: 68be17b29aa4f90a494992a9d14c54f37c258ae5
Description: modified (diff)

New commits:

68be17ballow slicing set partition classes by size

comment:5 Changed 18 months ago by Frédéric Chapoton

Returns should be Return

comment:6 Changed 18 months ago by git

Commit: 68be17b29aa4f90a494992a9d14c54f37c258ae527b3b4cd55ac0b79dcd92f2a4c47d10eda5ebf03

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

27b3b4cconvention fix

comment:7 Changed 18 months ago by Travis Scrimshaw

Reviewers: Frédéric Chapoton, Travis Scrimshaw
Status: needs_reviewpositive_review

LGTM. Thanks. There might be others CHAs that need a similar treatment as a warning.

Frédéric, I added you as a reviewer for comment:5.

comment:8 Changed 18 months ago by Darij Grinberg

Thanks, both of you!

comment:9 Changed 17 months ago by Volker Braun

Status: positive_reviewneeds_work
sage -t --long --warn-long 41.1 --random-seed=0 src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py  # 1 doctest failed
sage -t --long --warn-long 41.1 --random-seed=0 src/sage/categories/quotient_fields.py  # 2 doctests failed

comment:10 Changed 17 months ago by Darij Grinberg

Status: needs_workpositive_review

I don't think these have anything to do with my branch.

skraeling@moria ~/sage
$ sage -t --long --warn-long 41.1 --random-seed=0 src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py  # 1 doctest failed
Running doctests with ID 2021-06-30-23-20-11-ecd9f2e8.
Git branch: ospsize
Using --optional=build,cygwin,dochtml,pip,rubiks,sage,sage_spkg
Doctesting 1 file.
sage -t --long --warn-long 41.1 --random-seed=0 src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py
    [110 tests, 16.76 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 23.1 seconds
    cpu time: 4.2 seconds
    cumulative wall time: 16.8 seconds

skraeling@moria ~/sage
$ sage -t --long --warn-long 41.1 --random-seed=0 src/sage/categories/quotient_fields.py  # 2 doctests failed
Running doctests with ID 2021-06-30-23-30-34-35f1c6cc.
Git branch: ospsize
Using --optional=build,cygwin,dochtml,pip,rubiks,sage,sage_spkg
Doctesting 1 file.
sage -t --long --warn-long 41.1 --random-seed=0 src/sage/categories/quotient_fields.py
    [158 tests, 7.91 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 8.7 seconds
    cpu time: 3.3 seconds
    cumulative wall time: 7.9 seconds

comment:11 Changed 17 months ago by Darij Grinberg

While I don't have your logs, both of the files that are randomly failing involve approximate values in doctest results. I wouldn't be surprised if they need to be hardened for approximation errors.

comment:12 Changed 17 months ago by Volker Braun

Status: positive_reviewneeds_work

Can you try on top of the latest beta?

sage -t --long --warn-long 43.2 --random-seed=0 src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py
**********************************************************************
File "src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py", line 260, in sage.tests.books.computational-mathematics-with-sagemath.polynomes_doctest
Failed example:
    Frac(C['x'])(r).partial_fraction_decomposition()
Exception raised:
    Traceback (most recent call last):
      File "/home/release/Sage/local/lib64/python3.9/site-packages/sage/doctest/forker.py", line 718, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/release/Sage/local/lib64/python3.9/site-packages/sage/doctest/forker.py", line 1137, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.tests.books.computational-mathematics-with-sagemath.polynomes_doctest[69]>", line 1, in <module>
        Frac(C['x'])(r).partial_fraction_decomposition()
      File "/home/release/Sage/local/lib64/python3.9/site-packages/sage/categories/quotient_fields.py", line 540, in partial_fraction_decomposition
        for r in factor:
    NameError: name 'factor' is not defined
**********************************************************************

comment:13 Changed 17 months ago by Darij Grinberg

Line 540 of quotient_fields.py says "for r in factors", not "for r in factor":

https://github.com/sagemath/sage/blob/develop/src/sage/categories/quotient_fields.py

Nothing about my branch changes this. Are you sure your setup isn't corrupted (e.g., by some broken E701/702 fix)?

Last edited 17 months ago by Darij Grinberg (previous) (diff)

comment:14 Changed 17 months ago by Darij Grinberg

That, or your bot is either merging or testing the wrong branch.

comment:15 Changed 17 months ago by Darij Grinberg

Status: needs_workpositive_review

comment:16 Changed 17 months ago by Volker Braun

Branch: public/ticket/3198527b3b4cd55ac0b79dcd92f2a4c47d10eda5ebf03
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.