sagemath/sage

Make combinat doctests ready for random seeds

Closed this issue · 30 comments

kliem commented

Part of #29935.

This ticket makes

sage -t --long --random-seed=n src/sage/combinat/

pass for n more general than just 0.

See also:

  • #30186 containment check for standard bracketed Lyndon words does not work.

Along the way we fix a tiny but annoying bug, where random derangements could fail.

That was because randint(0, n) has range range(0, n + 1),
which had caused confusion.

Depends on #29962

Component: doctest framework

Author: Jonathan Kliem

Branch: 928863f

Reviewer: Sébastien Labbé

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

kliem commented

Branch: public/29974

kliem commented

New commits:

da1c6bestart from a "random" random seed for doctesting
b7b836dmake random seed reproducible
eedbe5edocument random_seed
998b1b9default random seed 0 for now
1d7b00edash instead of underscore for command line options
e0e572emake combinat fuzz ready
7c3a1ffanother file for combinat
kliem commented

Commit: 7c3a1ff

kliem commented
comment:2

Merge conflict.

I also need to go through it again and check I respected the design decision in #29935.

kliem commented
comment:3

Note that elements of g = GelfandTsetlinPatterns(4, 5) have the wrong parent.

kliem commented

Description changed:

--- 
+++ 
@@ -4,3 +4,5 @@
 sage -t --long --random-seed=n src/sage/combinat/
 ```
 pass for different values `n` than just `0`.
+
+See also: #30186 containment check for standard bracketed lyndon words does not work 
kliem commented

Changed commit from 7c3a1ff to none

kliem commented

Changed branch from public/29974 to public/29974-reb

Branch pushed to git repo; I updated commit sha1. Last 10 new commits:

eedbe5edocument random_seed
998b1b9default random seed 0 for now
1d7b00edash instead of underscore for command line options
b31e2d5Merge branch 'public/29962' of git://trac.sagemath.org/sage into public/29962-reb
2f30dd9small fixes
b62f781doctests do not start from a random seed by default yet
1d99129fix merge conflict
d40d826make combinat fuzz ready
b9f88cfanother file for combinat
a914b8dmodify doctests according to decisions in 29935
comment:8

I get one failure in combinat:

----------------------------------------------------------------------
sage -t --long --random-seed=2 src/sage/combinat/derangements.py  # 1 doctest failed
----------------------------------------------------------------------

Can you reproduce it?

sage -t --long --random-seed=2 src/sage/combinat/derangements.py
**********************************************************************
File "src/sage/combinat/derangements.py", line 129, in sage.combinat.derangements.Derangements
Failed example:
    D2.random_element() # random
Exception raised:
    Traceback (most recent call last):
      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 715, 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 1139, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.combinat.derangements.Derangements[7]>", line 1, in <module>
        D2.random_element() # random
      File "/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/combinat/derangements.py", line 504, in random_element
        return L[i]
    IndexError: list index out of range
**********************************************************************
1 item had failures:
   1 of   9 in sage.combinat.derangements.Derangements
    [85 tests, 1 failure, 0.10 s]
kliem commented
comment:9

Yes, I can confirm the problem.

Reviewer: Sébastien Labbé

comment:10

But it works for --random-seed=0, --random-seed=1, --random-seed=3, --random-seed=4.

kliem commented

Changed branch from public/29974-reb to public/29974-reb2

kliem commented
comment:11

Tiny mistake that the range of randint(0,n) is actually range(0,n+1).


New commits:

48bd40eMerge branch 'public/29974-reb' of git://trac.sagemath.org/sage into test_29974
39f94e6fix index error with random derangements
kliem commented

Changed commit from a914b8d to 39f94e6

kliem commented

Description changed:

--- 
+++ 
@@ -5,4 +5,6 @@
 ```
 pass for different values `n` than just `0`.
 
-See also: #30186 containment check for standard bracketed lyndon words does not work 
+See also: #30186 containment check for standard bracketed lyndon words does not work.
+
+Along the way we fix a tiny but annoying bug, where random dearangments could fail, because `randint(0,n)` has range `range(0,n+1)`. 
comment:12

There is

from random import randrange

for that. Do you mind to change to the lesser known randrange?

Changed commit from 39f94e6 to a391a3e

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

a391a3euse randrange instead of randint
kliem commented
comment:14

I like randrange much better. It is much more intuitive if you are used to range. (But reading the very short docstring that was exactly the point of introducing it.)

comment:15

In fact, I think we want to import it from prandom

from sage.misc.prandom import randrange  

in order for it to depend on the --random-seed.

kliem commented
comment:16

I was wondering about what the point was of duplicating that thing.

Changed commit from a391a3e to 928863f

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

928863fimport randrange from the correct place
kliem commented
comment:19

Thank you.

Changed branch from public/29974-reb2 to 928863f

slel commented

Description changed:

--- 
+++ 
@@ -1,10 +1,16 @@
+Part of #29935.
+
 This ticket makes
 
 ```
 sage -t --long --random-seed=n src/sage/combinat/
 ```
-pass for different values `n` than just `0`.
+pass for `n` more general than just `0`.
 
-See also: #30186 containment check for standard bracketed lyndon words does not work.
+See also:
+- #30186 containment check for standard bracketed Lyndon words does not work.
 
-Along the way we fix a tiny but annoying bug, where random dearangments could fail, because `randint(0,n)` has range `range(0,n+1)`. 
+Along the way we fix a tiny but annoying bug, where random derangements could fail.
+
+That was because `randint(0, n)` has range `range(0, n + 1)`,
+which had caused confusion.
slel commented

Changed commit from 928863f to none