Unreasonable docfails in symbolic/random_tests.py

1 view
Skip to first unread message

Andrey Novoseltsev

unread,
Jun 17, 2010, 4:14:07 PM6/17/10
to sage-devel
Hello everybody,

A while ago I noticed that my *new independent module* on toric
varieties causes an error in a really obscure long output for one of
the tests in symbolic/random_tests.py. Volker Braun pointed in
http://trac.sagemath.org/sage_trac/ticket/8988#comment:9

"I think the change in the random_test is because the patched sage/
schemes/generic/algebraic_scheme now imports latex which imports
random which changes the random seed. So it is all right, and fixing
the random_test doctest is the right thing to do (TM). "

(the patch at #8988 which leads to the error does not actually change
algebraic_scheme, it was changed earlier)

Now I rebased #8988, tried the test, and in addition to the previous
error (which has actually changed since the last time I looked at it),
I got
**********************************************************************
File "/home/novoselt/sage/devel/sage-main/sage/symbolic/
random_tests.py", line 211:
sage: random_expr(5, verbose=True)
Expected:
About to apply <built-in function mul> to [v1, v1]
About to apply <built-in function add> to [-1/3, v1]
About to apply <built-in function add> to [v1^2, v1 - 1/3]
v1^2 + v1 - 1/3
Got:
About to apply <built-in function mul> to [v1, v1]
About to apply <built-in function add> to [v1^2, v1]
About to apply <built-in function neg> to [v1^2 + v1]
-v1^2 - v1
**********************************************************************

I definitely can include a patch replacing the output with a new one,
which seems to be as correct as the previous one, but I think that all
these random tests should be somehow rewritten to give non-random
output. Can they just not show anything and check only if there were
exceptions raised in the process? Otherwise it just seems to me that
any patch may lead to new errors without any apparent reason.

Thank you!
Andrey

Volker Braun

unread,
Jun 17, 2010, 5:18:32 PM6/17/10
to sage-devel
Unsurprisingly, setting the random seed makes the random_expr() always
return the same value:

sage: set_random_seed(0xdeadbeef)
sage: random_expr(5)
tanh(-pi^real_part(v1)*sin(log(pi)*imag_part(v1)))
sage: set_random_seed(0xdeadbeef)
sage: random_expr(5)
tanh(-pi^real_part(v1)*sin(log(pi)*imag_part(v1)))
sage: random_expr(5)
v1 + arccos(e/golden_ratio)

I suggest that the doctests for sage.symbolic.random_tests simply set
the random seed to a fixed value.

Volker

Carl Witty

unread,
Jul 13, 2010, 5:37:12 AM7/13/10
to sage-...@googlegroups.com

The testing framework automatically runs set_random_seed(0) before
testing every docstring, so this shouldn't be necessary.

Carl Witty

Andrey Novoseltsev

unread,
Jul 13, 2010, 9:39:51 AM7/13/10
to sage-devel
On Jul 13, 3:37 am, Carl Witty <carl.wi...@gmail.com> wrote:
I completely agree that this should not be necessary, but the output
of this function does change!!!

Andrey

Carl Witty

unread,
Jul 15, 2010, 4:05:06 PM7/15/10
to sage-...@googlegroups.com

OK.

Setting the random seed seems like a fine workaround for getting your
patch in... the problem is unlikely to be in your patch, as you point
out.

But as the author of both sage.misc.randstate and
sage.symbolic.random_tests, it makes me nervous when I don't
understand what my code is doing. I tried to look into this, but I
couldn't figure out how to reproduce the problem. Could you do me a
favor and give nice simple instructions? (In particular, what version
of Sage do I start with and what is the complete list of patches to
apply?)

Thanks,

Carl

Andrey Novoseltsev

unread,
Jul 15, 2010, 4:38:41 PM7/15/10
to sage-devel
Hi Carl,

For example this installation of sage-4.5.alpha1

novoselt@sage:/scratch/novoselt/sage-4.5.alpha1/devel/sage-main$ hg
qapplied
trac_9502_basis_parent_bug_in_FreeModule.patch
trac_9128-sphinx_links_all-fh.patch
trac_9128-intersphinx_python_database-fh.patch
trac_9188_fix_facet_normal.patch
trac_9188_fix_facet_normal_reviewer.patch
trac_9062_add_support_for_toric_lattices.patch
trac_9062-cmp_fix.2.patch
trac_8986_add_support_for_convex_rational_polyhedral_cones.patch
trac_8986_cmp_fix.patch
trac_8987_add_support_for_rational_polyhedral_fans.patch
trac_8987_add_enhanced_cones_and_fans.patch
trac_8987_review_changes.patch
trac_8987_repr_changes.patch
trac_8987_cmp_fix.patch
trac_8988_add_support_for_toric_varieties.patch

shows two broken doctests in symbolic/random_tests. Moreover, it seems
that my doctest patch does not fix one of the issues anymore! It will
be very very good if you could fix this issue, as I have no idea
what's going on...

Thank you,
Andrey

On Jul 15, 2:05 pm, Carl Witty <carl.wi...@gmail.com> wrote:

Carl Witty

unread,
Jul 16, 2010, 12:36:37 AM7/16/10
to sage-...@googlegroups.com
On Thu, Jul 15, 2010 at 1:38 PM, Andrey Novoseltsev <novo...@gmail.com> wrote:
> Hi Carl,
>
> For example this installation of sage-4.5.alpha1
>
> novoselt@sage:/scratch/novoselt/sage-4.5.alpha1/devel/sage-main$ hg
> qapplied
> trac_9502_basis_parent_bug_in_FreeModule.patch
> trac_9128-sphinx_links_all-fh.patch
> trac_9128-intersphinx_python_database-fh.patch
> trac_9188_fix_facet_normal.patch
> trac_9188_fix_facet_normal_reviewer.patch
> trac_9062_add_support_for_toric_lattices.patch
> trac_9062-cmp_fix.2.patch
> trac_8986_add_support_for_convex_rational_polyhedral_cones.patch
> trac_8986_cmp_fix.patch
> trac_8987_add_support_for_rational_polyhedral_fans.patch
> trac_8987_add_enhanced_cones_and_fans.patch
> trac_8987_review_changes.patch
> trac_8987_repr_changes.patch
> trac_8987_cmp_fix.patch
> trac_8988_add_support_for_toric_varieties.patch
>
> shows two broken doctests in symbolic/random_tests. Moreover, it seems
> that my doctest patch does not fix one of the issues anymore! It will
> be very very good if you could fix this issue, as I have no idea
> what's going on...

Thanks, that's exactly what I needed to track down the issue. Turns
out it was a bug in random_tests.py. (I was inadvertently depending
on the order of the output of .values() on a dict, which is a Bad
Idea. The question isn't why it broke, it's why did it ever work.)

There's a patch up at #9514.

Carl

Andrey Novoseltsev

unread,
Jul 16, 2010, 10:29:20 AM7/16/10
to sage-...@googlegroups.com
Thank you!!!

Andrey

> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
>

Reply all
Reply to author
Forward
0 new messages