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

Failing doctest in poset_examples #26586

Closed
jdemeyer opened this issue Oct 28, 2018 · 31 comments
Closed

Failing doctest in poset_examples #26586

jdemeyer opened this issue Oct 28, 2018 · 31 comments

Comments

@jdemeyer
Copy link

With --gc=never, this doctest fails consistently:

./sage -t --gc=never src/sage/combinat/posets/poset_examples.py
too many failed tests, not using stored timings
Running doctests with ID 2018-10-28-23-55-00-fb2259d6.
Git branch: t/24593/upgrade_from_thebe_to_thebelab_for_live_documentation_support
Using --optional=dochtml,meataxe,memlimit,mpir,python2,sage
Doctesting 1 file.
sage -t src/sage/combinat/posets/poset_examples.py
**********************************************************************
File "src/sage/combinat/posets/poset_examples.py", line 1400, in sage.combinat.posets.poset_examples.Posets.YoungDiagramPoset
Failed example:
    P.cover_relations()
Expected:
    [[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0),
    (1, 1)]]
Got:
    [[(0, 0), (1, 0)], [(0, 0), (0, 1)], [(1, 0), (1, 1)], [(0, 1), (1, 1)]]
**********************************************************************
1 item had failures:
   1 of   3 in sage.combinat.posets.poset_examples.Posets.YoungDiagramPoset
    [159 tests, 1 failure, 11.36 s]
----------------------------------------------------------------------
sage -t src/sage/combinat/posets/poset_examples.py  # 1 doctest failed
----------------------------------------------------------------------

Component: combinatorics

Author: Jeroen Demeyer

Branch/Commit: dc77918

Reviewer: Volker Braun, Frédéric Chapoton

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

@jdemeyer jdemeyer added this to the sage-8.5 milestone Oct 28, 2018
@fchapoton
Copy link
Contributor

comment:1

It seems that adding sorted() to the doctest does not sort, hence does not fix the issue

chapoton@pc-chapoton:~/sage$ ./sage -t --gc=never src/sage/combinat/posets/poset_examples.py
too few successful tests, not using stored timings
Running doctests with ID 2018-10-29-10-25-27-f966edb9.
Git branch: poset
Using --optional=4ti2,ccache,dochtml,dot2tex,fricas,gfortran,latte_int,lidia,lrslib,memlimit,mpir,python2,sage
Doctesting 1 file.
sage -t src/sage/combinat/posets/poset_examples.py
**********************************************************************
File "src/sage/combinat/posets/poset_examples.py", line 1400, in sage.combinat.posets.poset_examples.Posets.YoungDiagramPoset
Failed example:
    sorted(P.cover_relations())
Expected:
    [[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0),
    (1, 1)]]
Got:
    [[(0, 0), (1, 0)], [(0, 0), (0, 1)], [(1, 0), (1, 1)], [(0, 1), (1, 1)]]
**********************************************************************
1 item had failures:
   1 of   3 in sage.combinat.posets.poset_examples.Posets.YoungDiagramPoset
    [159 tests, 1 failure, 1.79 s]
----------------------------------------------------------------------
sage -t src/sage/combinat/posets/poset_examples.py  # 1 doctest failed

@mantepse
Copy link
Contributor

comment:2

A difference also happens with respect to --long on the same file (on linux-ubuntu):

martin@convex63:~/sage-develop$ ./sage -t --long --optional=sage src/sage/combinat/posets/poset_examples.py                                          
too many failed tests, not using stored timings                                                                                                       
Running doctests with ID 2018-11-21-07-24-59-6ea730c0.                                                                                                
Git branch: develop                                                                                                                                   
Using --optional=memlimit,sage                                                                                                                        
Doctesting 1 file.                                                                                                                                    
sage -t --long src/sage/combinat/posets/poset_examples.py                                                                                             
    [160 tests, 2.88 s]                                                                                                                               
----------------------------------------------------------------------                                                                                
All tests passed!                                                                                                                                     
----------------------------------------------------------------------                                                                                
Total time for all tests: 3.0 seconds                                                                                                                 
    cpu time: 2.8 seconds                                                                                                                             
    cumulative wall time: 2.9 seconds
                                                                                                                 
martin@convex63:~/sage-develop$ ./sage -t --optional=sage src/sage/combinat/posets/poset_examples.py 
too many failed tests, not using stored timings                                                                                                       
Running doctests with ID 2018-11-21-07-25-08-142907c8.                                                                                                
Git branch: develop                                                                                                                                   
Using --optional=memlimit,sage                                                                                                                        
Doctesting 1 file.                                                                                                                                    
sage -t src/sage/combinat/posets/poset_examples.py                                                                                                    
**********************************************************************                                                                                
File "src/sage/combinat/posets/poset_examples.py", line 1400, in sage.combinat.posets.poset_examples.Posets.YoungDiagramPoset                         
Failed example:                                                                                                                                       
    P.cover_relations()                                                                                                                               
Expected:                                                                                                                                             
    [[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0),                                                                                   
    (1, 1)]]                                                                                                                                          
Got:                                                                                                                                                  
    [[(0, 0), (1, 0)], [(0, 0), (0, 1)], [(1, 0), (1, 1)], [(0, 1), (1, 1)]]                                                                          
**********************************************************************                                                                                
1 item had failures:                                                                                                                                  
   1 of   3 in sage.combinat.posets.poset_examples.Posets.YoungDiagramPoset                                                                           
    [159 tests, 1 failure, 2.09 s]                                                                                                                    
----------------------------------------------------------------------                                                                                
sage -t src/sage/combinat/posets/poset_examples.py  # 1 doctest failed 
----------------------------------------------------------------------                                                                                
Total time for all tests: 2.2 seconds                                                                                                                 
    cpu time: 2.0 seconds                                                                                                                             
    cumulative wall time: 2.1 seconds  

Moreover, removing the only # long marker from this file (in line 963), the problem is not visible anymore!

martin@convex63:~/sage-develop$ ./sage -t --long --optional=sage src/sage/combinat/posets/poset_examples.py                                          
too many failed tests, not using stored timings                                                                                                       
Running doctests with ID 2018-11-21-07-25-28-653967b1.                                                                                                
Git branch: develop                                                                                                                                   
Using --optional=memlimit,sage                                                                                                                        
Doctesting 1 file.                                                                                                                                    
sage -t --long src/sage/combinat/posets/poset_examples.py                                                                                             
    [160 tests, 2.88 s]                                                                                                                               
----------------------------------------------------------------------                                                                                
All tests passed!                                                                                                                                     
----------------------------------------------------------------------                                                                                
Total time for all tests: 2.9 seconds                                                                                                                 
    cpu time: 2.8 seconds                                                                                                                             
    cumulative wall time: 2.9 seconds                                                                                                                 

martin@convex63:~/sage-develop$ ./sage -t --optional=sage src/sage/combinat/posets/poset_examples.py                                          
too many failed tests, not using stored timings                                                                                                       
Running doctests with ID 2018-11-21-07-25-36-4df51548.                                                                                                
Git branch: develop                                                                                                                                   
Using --optional=memlimit,sage                                                                                                                        
Doctesting 1 file.                                                                                                                                    
sage -t src/sage/combinat/posets/poset_examples.py                                                                                                    
    [160 tests, 2.88 s]                                                                                                                               
----------------------------------------------------------------------                                                                                
All tests passed!                                                                                                                                     
----------------------------------------------------------------------                                                                                
Total time for all tests: 2.9 seconds                                                                                                                 
    cpu time: 2.8 seconds                                                                                                                             
    cumulative wall time: 2.9 seconds   

@mantepse
Copy link
Contributor

comment:3

Finally, when running the offending test on its own in a session, there is no mismatch:

martin@convex63:~/sage-develop$ ./sage                                                                                                                
┌────────────────────────────────────────────────────────────────────┐                                                                                
│ SageMath version 8.5.beta4, Release Date: 2018-11-18               │                                                                                
│ Using Python 2.7.15. Type "help()" for help.                       │                                                                                
└────────────────────────────────────────────────────────────────────┘                                                                                
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓                                                                                
┃ Warning: this is a prerelease version, and it may be unstable.     ┃                                                                                
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛                                                                                
sage: P = posets.YoungDiagramPoset(Partition([2,2])); P                                                                                               
Finite meet-semilattice containing 4 elements                                                                                                         
sage: P.cover_relations()                                                                                                                             
[[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0), (1, 1)]]

Adding

            sage: import gc                                                                                                                           
            sage: gc.collect() # random                                                                                                               
 

just before the test in line 1400 "fixes" it.

@mantepse
Copy link
Contributor

comment:4

Here is a minimal example for my computer. Could you please check whether this yields a failure when run without --long and no failure when run with --long?

def A():
    """
    sage: posets.ProductOfChains([2, 2]).linear_extension()
    [(0, 0), (1, 0), (0, 1), (1, 1)]
    
    sage: posets.SSTPoset([3,2]).bottom()  # long time
    [[1, 1, 1], [2, 2]]
    """

def B():
    """
    sage: posets.YoungDiagramPoset(Partition([2,2])).cover_relations()
    [[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0), (1, 1)]]
    """

@simon-king-jena
Copy link
Member

comment:5

Apparently it has nothing to do with the doctest framework, i.e., your example can be easily reproduced in an interactive session:

sage: posets.ProductOfChains([2, 2]).linear_extension()
[(0, 0), (1, 0), (0, 1), (1, 1)]
sage: posets.SSTPoset([3,2]).bottom()
[[1, 1, 1], [2, 2]]
sage: posets.YoungDiagramPoset(Partition([2,2])).cover_relations()
[[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0), (1, 1)]]

then restart Sage, then

sage: posets.ProductOfChains([2, 2]).linear_extension()
[(0, 0), (1, 0), (0, 1), (1, 1)]
sage: posets.YoungDiagramPoset(Partition([2,2])).cover_relations()
[[(0, 0), (1, 0)], [(0, 0), (0, 1)], [(1, 0), (1, 1)], [(0, 1), (1, 1)]]

Very likely some kind of caching is causing the inconsistency, but I am not familiar with the code and therefore have no clue where that cache can be found.

What I find odd: Even when sorting the output, the two results are different. Is sorting not properly implemented for sage.sets.cartesian_product.CartesianProduct_with_category.element_class?

@mantepse
Copy link
Contributor

comment:6

But shouldn't doctests in each function start with a fresh environment?

@simon-king-jena
Copy link
Member

comment:7

Replying to @mantepse:

But shouldn't doctests in each function start with a fresh environment?

No.

I could be mistaken, but when I write doctests, I always assume:

  • The tests of individual functions within a single file are ALL executed in the same environment.
  • The tests of the individual functions within a single file are executed in random order.

@vbraun
Copy link
Member

vbraun commented Nov 21, 2018

comment:8

Its in the nature of posets that there is usually no canonical total order, so trying to make the output canonical is probably not going to happen in all cases.

Without looking at the code I'm guessing that you are somewhere iterating over an associative container, which ends up being random because the elements can't be ordered.

You probably want to rewrite the test as X == Y instead of looking at the output

@simon-king-jena
Copy link
Member

comment:9

The output is a python list of python lists of elements. So, testing equality won't work. But perhaps one can turn the lists into sets and compare them?

@mantepse
Copy link
Contributor

comment:10

We could do

sage: sorted(map(tuple, P.cover_relations()), key=lambda c: map(tuple, c))
[((0, 0), (0, 1)), ((0, 0), (1, 0)), ((0, 1), (1, 1)), ((1, 0), (1, 1))]

if we do not want to have sorting for cartesian products.

@jm58660
Copy link
Mannequin

jm58660 mannequin commented Nov 22, 2018

comment:11

Is it easier to just say sorted(sorted(x) for x in posets.YoungDiagramPoset(Partition([2,2])).cover_relations())? I think I have seen that structure in some other parts of Sage.

@mantepse
Copy link
Contributor

comment:12

Wouldn't it be better to have cartesian product export sorting? (lexicographic)

@mantepse
Copy link
Contributor

comment:13

Besides, shouldn't upper and lower covers be tuples, not lists?

@vbraun
Copy link
Member

vbraun commented Dec 13, 2018

comment:14

Unless something happens real soon this will not be fixed in Sage 8.5

@fchapoton
Copy link
Contributor

Branch: u/chapoton/26586

@fchapoton
Copy link
Contributor

Commit: 3e8ef3b

@fchapoton
Copy link
Contributor

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor

comment:15

ok, here it is


New commits:

3e8ef3btrac 26586 fix the doctest in poset for -gc=never by sorting

@jdemeyer
Copy link
Author

comment:16

Why not use a plain sorted()?

@fchapoton
Copy link
Contributor

comment:17

Because this does not work. See comment:1

@vbraun
Copy link
Member

vbraun commented Dec 13, 2018

Reviewer: Volker Braun

@jdemeyer
Copy link
Author

comment:19

I understand that you want to get rid of this blocker, but this is not a right fix.

@jdemeyer
Copy link
Author

Changed branch from u/chapoton/26586 to u/jdemeyer/26586

@jdemeyer
Copy link
Author

Changed author from Frédéric Chapoton to Frédéric Chapoton, Jeroen Demeyer

@jdemeyer
Copy link
Author

Changed commit from 3e8ef3b to dc77918

@jdemeyer
Copy link
Author

comment:21

Don't hide bugs, at least mark it as # known bug


New commits:

dc77918Mark doctest as known bug

@jdemeyer
Copy link
Author

comment:22

Replying to @mantepse:

Wouldn't it be better to have cartesian product export sorting? (lexicographic)

Yes obviously. I opened #26890 for that.

@fchapoton
Copy link
Contributor

Changed author from Frédéric Chapoton, Jeroen Demeyer to Jeroen Demeyer

@fchapoton
Copy link
Contributor

Changed reviewer from Volker Braun to Volker Braun, Frédéric Chapoton

@fchapoton
Copy link
Contributor

comment:23

right. ok for me

@vbraun
Copy link
Member

vbraun commented Dec 15, 2018

Changed branch from u/jdemeyer/26586 to dc77918

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

5 participants