sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.4k stars 473 forks source link

17 internet doctest failing in findstat.py #28864

Closed seblabbe closed 4 years ago

seblabbe commented 4 years ago

findstat.org has now a proper api. In this ticket we switch to this api, and create a hierarchy of classes that better models what findstat provides.

In particular, this allows search for maps, iterating over all statistics or maps with given domain, easier access to search for distributions, etc.

Restricted to the capabilities of the old interface, the usage remains the same.

We also fix all the failing doctest.

Original ticket description

Using SageMath version 9.2.beta2, Release Date: 2020-06-26, the command

sage -t --optional=sage,internet src/sage/databases/findstat.py

gives

**********************************************************************
7 items had failures:
   4 of  16 in sage.databases.findstat
   3 of  10 in sage.databases.findstat.FindStat
   1 of  11 in sage.databases.findstat.FindStat.__call__
   1 of  10 in sage.databases.findstat.FindStatCollection.in_range
   3 of   5 in sage.databases.findstat.FindStatStatistic.first_terms
   3 of   5 in sage.databases.findstat.FindStatStatistic.generating_functions
   2 of   4 in sage.databases.findstat.FindStatStatistic.oeis_search
    [249 tests, 17 failures, 41.24 s]
----------------------------------------------------------------------
sage -t src/sage/databases/findstat.py  # 17 doctests failed
----------------------------------------------------------------------

CC: @mantepse @stumpc5

Component: combinatorics

Keywords: FindStat

Author: Martin Rubey

Branch/Commit: 52c576e

Reviewer: Sébastien Labbé

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

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

6448d1fremove obsolete field
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 5d2cce4 to 6448d1f

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 6448d1f to 08fdb3a

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

08fdb3afix doc syntax
mantepse commented 4 years ago
comment:31

Replying to @stumpc5:

Here are some first comments:

  • """ There is a new collection available at The Combinatorial Statistic Finder (https://www.findstat.org/): Signed permutations. To use it with this interface, it has to be added to the dictionary SupportedFindStatCollections in src/sage/databases/findstat.py of the SageMath distribution. Please open a ticket on trac! """

    Would it be possible to automatize this? Otherwise, every user will see this on startup and likely get confused.

Unfortunately, support of new collections cannot be made automatic. However, a new collection appears possibly once a year, so it shouldn't be a big problem. I cleaned the message a bit.

  • I would prefer a single entry point (maybe FindStat with FindStat.find_statistic and FindStat.find_map?). If I know findstat but not findmap, I might completely miss the latter? Also, using FindStat? would immediately give instructions how to proceed.

No, I don't want to do this. If you discover findstat, I am sure you will discover findstat, too. Introducing a new layer introduces more typing with very little benefit - it is extremely unlikely that there will be a third item analogous to findstat and findmap. To get the tutorial, sage.databases.findstat? suffices, as with all of sage.

  • 41: St001489oMp00081oMp00059 (quality [100, 100]) The term quality is not obviously explained. In the doc, it might be referred to as "a number which says how many values...". a proper definition of this quality might be helpful.

The quality is explained in the tutorial, but I agree it should also be explained in findstat? and findmap?. Patches welcome.

  • The term distribution is not explained how to be used in the input section of findstat: it is twice referred to as "distribution must be None".

Indeed, the documentation of findstat and findmap still needs to be improved.

  • It remains unclear (I think, to a new user) what "a new statistic" means. I would suggest to not show this as one of the "results" of a DababaseQuery. Instead, I would suggest to have this available as a method submit_as_new_statistic.
    • This method fails if the input datum is not a statistic (but a distribution).
    • If there is no result, the user gets prompted a message that this method is available in case she wants to submit the data.

Done, with the exception of failing for "distributions", because it is not clear when to fail exactly. I think it is better (and easier) to allow submission in case of doubt.

  • The term offset is not exlained, is it?

It is now in the tutorial, but should also be explained by findstat?

  • What about two methods matching values and unmatched_values ?
    • Each of these could consist of lists of pairs of the form ( ( elt1, elt2, elt3 ), val ).

That's non-trivial, and I'd therefore like not to do it now.

  • Finally: Since the output might be long and confusing, I think it would be great if FindStatMatchingStatistic had a method info or detailed_info or alike which would in detail present this match:

done.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 08fdb3a to f52803d

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

f52803dwhitespace fixes, remove obsolete code
484a923e-33e0-4225-8144-674e3026e28c commented 4 years ago
comment:33

I just tried this for the first time and get

sage: findstat(3)
<repr(<sage.databases.findstat.FindStatStatistics_with_category.element_class at 0x1be3bcfc0>) failed: requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.>

What do I do?

It appears that openssl is not installed on macOS Catalina:

sage: import ssl
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-bc7fc2b48773> in <module>()
----> 1 import ssl

/Users/kathrinmeier/sage/local/lib/python3.7/ssl.py in <module>()
     96 from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag
     97 
---> 98 import _ssl             # if we can't import it, let the error propagate
     99 
    100 from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION

ModuleNotFoundError: No module named '_ssl'
mantepse commented 4 years ago
comment:34

Hi Kathrin! I'm afraid I can't help you here (I am unfamiliar with macOS), maybe you can ask on sage-devel or sage-support. Did you try whether oeis([1,2,5,14,42]) works?

Here is a (very stupid) workaround - but you absolutely have to fix openssl support:

sage: from sage.databases.findstat import FINDSTAT_URL
sage: sage.databases.findstat.FINDSTAT_URL = 'http://www.findstat.org/'
484a923e-33e0-4225-8144-674e3026e28c commented 4 years ago
comment:35

Hi, unfortunately neither oeis([1,2,5,14,42]) nor your workaround worked.

I even tried

sage -i pip openssl

now but without any new result.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

c09cfc5factor out submission
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from f52803d to c09cfc5

fchapoton commented 4 years ago
comment:37

Replying to @kathrin2006:

Hi, unfortunately neither oeis([1,2,5,14,42]) nor your workaround worked.

I even tried

sage -i pip openssl

now but without any new result.

Installing openssl should be followed by sage -f python that will rebuild all of sage.

stumpc5 commented 4 years ago
comment:38

Is the following a bug?

sage: sts = findstat("DyckPaths", [ ( list(DyckWords(n)), [inner_trians(T,n+2) for T in trians(n+2)] ) for n in [2 .. 5] ])
sage: sts.submit()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-42-ef4ef8d3bffa> in <module>()
----> 1 sts.submit()

/home/stumpcl2/Programs/sage/local/lib/python3.7/site-packages/sage/databases/findstat.py in submit(self, max_values)
   2319         else:
   2320             url = FINDSTAT_NEWSTATISTIC_FORM_HEADER % (FINDSTAT_URL_EDIT_STATISTIC + self.id_str())
-> 2321         _submit(args, url)
   2322 
   2323     # editing and submitting is really the same thing

/home/stumpcl2/Programs/sage/local/lib/python3.7/site-packages/sage/databases/findstat.py in _submit(args, url)
    443     verbose("Created temporary file %s" % f.name, caller_name='FindStat')
    444     f.write(FINDSTAT_POST_HEADER)
--> 445     if not int(id_str[2:]):
    446         f.write(url_header % url_new)
    447     else:

NameError: name 'id_str' is not defined

Also, submit_as_new_statistic is more explicit than submit. The docstring says "Open the FindStat web page for editing the statistic in a browser." even though this data is not an existing statistic that can be edited.

stumpc5 commented 4 years ago
comment:39

The docstring of the method quality does not explain the tuple of two integers. Should it?

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from c09cfc5 to 0a1e60c

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

0a1e60cdoctest _submit, docstring quality, fix docstring submit
mantepse commented 4 years ago
comment:41

unfortunately, I have a problem with submit, it doesn't do the right thing with line breaks :-(

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

5b38d96fix py2-3 unicode encoding issue
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 0a1e60c to 5b38d96

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

8e2be83fix some docstrings and make docbuild pass
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 5b38d96 to 8e2be83

seblabbe commented 4 years ago

Reviewer: Sébastien Labbé

seblabbe commented 4 years ago
comment:44

With sage-9.1.beta2 + this branch, the command

sage -t --optional=sage,internet src/sage/databases/findstat.py

gives

sage -t src/sage/databases/findstat.py
**********************************************************************
File "src/sage/databases/findstat.py", line 49, in sage.databases.findstat
Failed example:
    r = findstat([(m, m.number_of_nestings()) for n in range(6) for m in PM(2*n)]); r # optional -- internet
Expected:
    0: St000042oMp00116 (quality [100, 100])
    1: St000041 (quality [20, 100])
    ...
Got:
    The Combinatorial Statistic Finder (https://www.findstat.org/) provides a new collection:
        Cc0026: Decorated permutations
    To use it with this interface, it has to be added to the dictionary
        _SupportedFindStatCollections in src/sage/databases/findstat.py
    of the SageMath distribution.  Please open a ticket on trac!
    The Combinatorial Statistic Finder (https://www.findstat.org/) provides a new collection:
        Cc0025: Plane partitions
    To use it with this interface, it has to be added to the dictionary
        _SupportedFindStatCollections in src/sage/databases/findstat.py
    of the SageMath distribution.  Please open a ticket on trac!
    0: St000042oMp00116 (quality [100, 100])
    1: St000041 (quality [20, 100])
    2: St000232oMp00115oMp00092 (quality [17, 70])
    3: St000233oMp00092 (quality [16, 100])
    4: St000496oMp00092 (quality [16, 100])
    5: St000123oMp00087oMp00058 (quality [13, 70])
    6: St000359oMp00087oMp00058 (quality [13, 70])
**********************************************************************
1 item had failures:
   1 of  16 in sage.databases.findstat
    [382 tests, 1 failure, 39.76 s]
----------------------------------------------------------------------
sage -t src/sage/databases/findstat.py  # 1 doctest failed
----------------------------------------------------------------------
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

da7d01buse ordered dicts for first_terms and work around api quirk
f0be65dMerge branch 'u/mantepse/1_internet_doctest_failing_in_findstat_py' of git://trac.sagemath.org/sage into t/28864/1_internet_doctest_failing_in_findstat_py
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 8e2be83 to f0be65d

mkoeppe commented 4 years ago
comment:46

Moving tickets to milestone sage-9.2 based on a review of last modification date, branch status, and severity.

stumpc5 commented 4 years ago
comment:47

Merge conflict with 9.2.beta0.

stumpc5 commented 4 years ago
comment:48
The Combinatorial Statistic Finder (https://www.findstat.org/) provides a new collection:
    Cc0026: Decorated permutations
    Cc0025: Plane partitions
To use it with this interface, it has to be added to the dictionary
    _SupportedFindStatCollections in src/sage/databases/findstat.py
of the SageMath distribution.  Please open a ticket on trac!
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

04c64bcMerge branch 'develop' into t/28864/1_internet_doctest_failing_in_findstat_py
4539d65remove unnecessary imports
cf01a69fix doctests
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from f0be65d to cf01a69

seblabbe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,3 +1,4 @@
+Using `SageMath version 9.2.beta2, Release Date: 2020-06-26`, the command

sage -t --optional=sage,internet src/sage/databases/findstat.py @@ -6,40 +7,17 @@ gives

-Using --optional=internet,memlimit,sage
-Doctesting 1 file.
-sage -t --warn-long 69.4 src/sage/databases/findstat.py
 **********************************************************************
-File "src/sage/databases/findstat.py", line 2117, in sage.databases.findstat.FindStatCollection.in_range
-Failed example:
-    for c in l:                                                   # optional -- internet, random
-        if c.id() not in long and c.is_supported():
-            f = c.first_terms(lambda x: 1, max_values=10000)
-            print("{} {} {}".format(c, len(f), all(c.in_range(e) for e, _ in f)))
-Exception raised:
-    Traceback (most recent call last):
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
-        self.compile_and_execute(example, compiler, test.globs)
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1123, in compile_and_execute
-        exec(compiled, globs)
-      File "<doctest sage.databases.findstat.FindStatCollection.in_range[8]>", line 3, in <module>
-        f = c.first_terms(lambda x: Integer(1), max_values=Integer(10000))
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/databases/findstat.py", line 2174, in first_terms
-        return [(x, statistic(x)) for (x,_) in zip(g, range(max_values))]
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/databases/findstat.py", line 2174, in <listcomp>
-        return [(x, statistic(x)) for (x,_) in zip(g, range(max_values))]
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/databases/findstat.py", line 2170, in <genexpr>
-        g = (x for n in self._levels.keys() for x in self._sageconstructor(n))
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/databases/findstat.py", line 2453, in <lambda>
-        19: [None, None, None, SemistandardTableau,   lambda x: SemistandardTableaux(x),
-      File "sage/misc/classcall_metaclass.pyx", line 334, in sage.misc.classcall_metaclass.ClasscallMetaclass.__call__ (build/cythonized/sage/misc/classcall_metaclass.c:1741)
-        return cls.classcall(cls, *args, **kwds)
-      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/combinat/tableau.py", line 5941, in __classcall_private__
-        raise ValueError( "shape must be a (skew) partition" )
-    ValueError: shape must be a (skew) partition
-**********************************************************************
-
+7 items had failures:
+   4 of  16 in sage.databases.findstat
+   3 of  10 in sage.databases.findstat.FindStat
+   1 of  11 in sage.databases.findstat.FindStat.__call__
+   1 of  10 in sage.databases.findstat.FindStatCollection.in_range
+   3 of   5 in sage.databases.findstat.FindStatStatistic.first_terms
+   3 of   5 in sage.databases.findstat.FindStatStatistic.generating_functions
+   2 of   4 in sage.databases.findstat.FindStatStatistic.oeis_search
+    [249 tests, 17 failures, 41.24 s]
 ----------------------------------------------------------------------
-sage -t --warn-long 69.4 src/sage/databases/findstat.py  # 1 doctests failed
+sage -t src/sage/databases/findstat.py  # 17 doctests failed
 ----------------------------------------------------------------------
seblabbe commented 4 years ago
comment:50

Updating the description of the ticket to mention the 17 failing doctests.

seblabbe commented 4 years ago
comment:51

Testing the current branch, I get only one doctest failure copied below:

sage -t src/sage/databases/findstat.py
**********************************************************************
File "src/sage/databases/findstat.py", line 49, in sage.databases.findstat
Failed example:
    r = findstat([(m, m.number_of_nestings()) for n in range(6) for m in PM(2*n)]); r # optional -- internet
Expected:
    0: St000042oMp00116 (quality [100, 100])
    1: St000041 (quality [20, 100])
    ...
Got:
    The Combinatorial Statistic Finder (https://www.findstat.org/) provides a new collection:
        Cc0026: Decorated permutations
    To use it with this interface, it has to be added to the dictionary
        _SupportedFindStatCollections in src/sage/databases/findstat.py
    of the SageMath distribution.  Please open a ticket on trac!
    The Combinatorial Statistic Finder (https://www.findstat.org/) provides a new collection:
        Cc0025: Plane partitions
    To use it with this interface, it has to be added to the dictionary
        _SupportedFindStatCollections in src/sage/databases/findstat.py
    of the SageMath distribution.  Please open a ticket on trac!
    0: St000042oMp00116 (quality [100, 100])
    1: St000041 (quality [20, 100])
    2: St000232oMp00115oMp00092 (quality [17, 70])
    3: St000233oMp00092 (quality [16, 100])
    4: St000496oMp00092 (quality [16, 100])
    5: St000123oMp00087oMp00058 (quality [13, 70])
    6: St000359oMp00087oMp00058 (quality [13, 70])
**********************************************************************
1 item had failures:
   1 of  16 in sage.databases.findstat
    [382 tests, 1 failure, 46.16 s]
----------------------------------------------------------------------
sage -t src/sage/databases/findstat.py  # 1 doctest failed
----------------------------------------------------------------------

Tell me when this needs review again or change the status to needs review.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from cf01a69 to dc78691

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

2e29b3bMerge branch 'develop' into t/28864/1_internet_doctest_failing_in_findstat_py
dc78691fix to-string for graphs
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from dc78691 to 3ec989b

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

3ec989bMerge branch 'develop' into t/28864/1_internet_doctest_failing_in_findstat_py
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

cdf2c22more fixes for edge labels, cgi is replaced with html
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from 3ec989b to cdf2c22

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from cdf2c22 to b25802a

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

b25802aaccept FindStatStatistic and FindStatMap for values and distribution
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from b25802a to d7fbbf9

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

2d6b266Merge branch 'develop' of git://trac.sagemath.org/sage into t/28864/1_internet_doctest_failing_in_findstat_py
f540af8Merge branch 'u/mantepse/1_internet_doctest_failing_in_findstat_py' of git://trac.sagemath.org/sage into t/28864/1_internet_doctest_failing_in_findstat_py
578ebcbMerge branch 'u/mantepse/1_internet_doctest_failing_in_findstat_py' of git://trac.sagemath.org/sage into t/28864/1_internet_doctest_failing_in_findstat_py
d7fbbf9add missing dictionary entry
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from d7fbbf9 to e564e53

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

31bbc92support for plane partitions
e564e53Merge branch 'u/mantepse/1_internet_doctest_failing_in_findstat_py' of git://trac.sagemath.org/sage into t/28864/1_internet_doctest_failing_in_findstat_py
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

dec07aasupport decorated permutations
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from e564e53 to dec07aa

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

Changed commit from dec07aa to bdefdf2

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 4 years ago

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

bdefdf2fix doctest of hash