Opened 7 years ago

Closed 7 years ago

#17238 closed defect (fixed)

Increase Precision in Failing Doctests

Reported by: strogdon Owned by:
Priority: blocker Milestone: sage-6.4
Component: doctest coverage Keywords:
Cc: jpflori Merged in:
Authors: Steven Trogdon, Jean-Pierre Flori Reviewers: Jeroen Demeyer
Report Upstream: N/A Work issues:
Branch: ec64d52 (Commits, GitHub, GitLab) Commit: ec64d527939f985f26248800211b72d24fa8a80b
Dependencies: Stopgaps:

Status badges

Description

Certain doctests may now fail due to precision issues. This is apparently a consequence of #16858. For reference see

https://groups.google.com/forum/#!topic/sage-release/jdhuVBY7rLU

Change History (37)

comment:1 Changed 7 years ago by strogdon

With

uname -a
Linux ledaig 3.6.11-gentoo #6 SMP Mon Aug 25 17:39:25 CDT 2014 x86_64 Dual-Core AMD Opteron(tm) Processor 2218 AuthenticAMD GNU/Linux

and Sage-6.4.beta6 installed I have the following doctest failures

sage -t --long src/sage/rings/polynomial/polynomial_element.pyx
**********************************************************************
File "src/sage/rings/polynomial/polynomial_element.pyx", line 5360, in sage.rings.polynomial.polynomial_element.Polynomial.roots
Failed example:
    [f(z) for z in f.roots(multiplicities=False)]  # abs tol 1e-12
Expected:
    [1.3704315460216776e-15 + 3.3306690738754696e-15*I, 5.287107591627866e-16 + 1.9984014443252818e-15*I, 2.0616104309811867e-16 + 1.7763568394002505e-15*I]
Got:
    [1.1102230246251565e-16 - 8.881784197001252e-16*I,
     -8.728374398092689e-16,
     7.771561172376096e-16 + 6.661338147750939e-16*I]
**********************************************************************
sage -t --long src/sage/tests/french_book/mpoly.py
**********************************************************************
File "src/sage/tests/french_book/mpoly.py", line 364, in sage.tests.french_book.mpoly
Failed example:
    ys = CDF['y'](Jy.0).roots(); ys
Expected:
    [(-0.8000000000000002, 1), (0.0, 1), (0.8, 1)]
Got:
    [(-0.8, 1), (0.0, 1), (0.7999999999999997, 1)]
************************************************************************
sage -t --long src/sage/matrix/matrix_double_dense.pyx
File "src/sage/matrix/matrix_double_dense.pyx", line 1012, in sage.matrix.matrix_double_dense.Matrix_double_dense.singular_values
Failed example:
    A.singular_values(eps=None)  # abs tol 2e-16
Expected:
    [1.7953720595619975, 0.38027524595503703, 0.04473854875218107, 0.0037223122378911614, 0.0002330890890217751, 1.116335748323284e-05, 4.082376110397296e-07, 1.1228610675717613e
-08, 2.2519645713496478e-10, 3.1113486853814003e-12, 2.6500422260778388e-14, 9.87312834948426e-17]
Got:
    [1.795372059561997,
     0.3802752459550371,
     0.04473854875218108,
     0.0037223122378911614,
     0.00023308908902177134,
     1.1163357483233473e-05,
     4.0823761103887333e-07,
     1.1228610666951528e-08,
     2.2519645134867946e-10,
     3.1113495994353857e-12,
     2.649222799410179e-14,
     1.0793843611330301e-16]
Tolerance exceeded in 1 of 12:
    1.7953720595619975 vs 1.795372059561997, tolerance 5e-16 > 2e-16
**********************************************************************
File "src/sage/matrix/matrix_double_dense.pyx", line 1014, in sage.matrix.matrix_double_dense.Matrix_double_dense.singular_values
Failed example:
    A.singular_values(eps='auto')  # abs tol 2e-16
Expected:
    [1.7953720595619975, 0.38027524595503703, 0.04473854875218107, 0.0037223122378911614, 0.0002330890890217751, 1.116335748323284e-05, 4.082376110397296e-07, 1.1228610675717613e
-08, 2.2519645713496478e-10, 3.1113486853814003e-12, 2.6500422260778388e-14, 0.0]
Got:
    [1.795372059561997,
     0.3802752459550371,
     0.04473854875218108,
     0.0037223122378911614,
     0.00023308908902177134,
     1.1163357483233473e-05,
     4.0823761103887333e-07,
     1.1228610666951528e-08,
     2.2519645134867946e-10,
     3.1113495994353857e-12,
     2.649222799410179e-14,
     0.0]
Tolerance exceeded in 1 of 12:
    1.7953720595619975 vs 1.795372059561997, tolerance 5e-16 > 2e-16
**********************************************************************
File "src/sage/matrix/matrix_double_dense.pyx", line 1016, in sage.matrix.matrix_double_dense.Matrix_double_dense.singular_values
Failed example:
    A.singular_values(eps=1e-4)  # abs tol 2e-16
Expected:
    [1.7953720595619975, 0.38027524595503703, 0.04473854875218107, 0.0037223122378911614, 0.0002330890890217751, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Got:
    [1.795372059561997,
     0.3802752459550371,
     0.04473854875218108,
     0.0037223122378911614,
     0.00023308908902177134,
     0.0,
     0.0,
     0.0,
     0.0,
     0.0,
     0.0,
     0.0]
Tolerance exceeded in 1 of 12:
    1.7953720595619975 vs 1.795372059561997, tolerance 5e-16 > 2e-16
******************************************************************************************************************************************
sage -t --long src/doc/ru/tutorial/tour_linalg.rst
**********************************************************************
File "src/doc/ru/tutorial/tour_linalg.rst", line 109, in doc.ru.tutorial.tour_linalg
Failed example:
    ARDF.eigenvalues()
Expected:
    [-0.09317121994613098, 4.293171219946131]
Got:
    [-0.09317121994613091, 4.293171219946131]
**********************************************************************
File "src/doc/ru/tutorial/tour_linalg.rst", line 112, in doc.ru.tutorial.tour_linalg
Failed example:
    ACDF.eigenvectors_right()  # rel tol 1e-15
Expected:
    [(0.8818456983293743 - 0.8209140653434135*I, [(0.7505608183809549, -0.616145932704589 + 0.2387941530333261*I)], 1),
    (3.3181543016706256 + 0.8209140653434133*I, [(0.14559469829270957 + 0.3756690858502104*I, 0.9152458258662108)], 1)]
Got:
    [(0.8818456983293741 - 0.8209140653434133*I,
      [(0.7505608183809549, -0.6161459327045887 + 0.23879415303332602*I)],
      1),
     (3.3181543016706256 + 0.8209140653434132*I,
      [(0.14559469829270977 + 0.3756690858502104*I, 0.9152458258662107)],
      1)]
Tolerance exceeded in 1 of 12:
    0.14559469829270957 vs 0.14559469829270977, tolerance 1e-15 > 1e-15
**********************************************************************
sage -t --long src/doc/de/tutorial/tour_linalg.rst
**********************************************************************
File "src/doc/de/tutorial/tour_linalg.rst", line 117, in doc.de.tutorial.tour_linalg
Failed example:
    ARDF.eigenvalues()
Expected:
    [-0.09317121994613098, 4.293171219946131]
Got:
    [-0.09317121994613091, 4.293171219946131]
**********************************************************************
File "src/doc/de/tutorial/tour_linalg.rst", line 120, in doc.de.tutorial.tour_linalg
Failed example:
    ACDF.eigenvectors_right()  # rel tol 1e-15
Expected:
    [(0.8818456983293743 - 0.8209140653434135*I, [(0.7505608183809549, -0.616145932704589 + 0.2387941530333261*I)], 1),
    (3.3181543016706256 + 0.8209140653434133*I, [(0.14559469829270957 + 0.3756690858502104*I, 0.9152458258662108)], 1)]
Got:
    [(0.8818456983293741 - 0.8209140653434133*I,
      [(0.7505608183809549, -0.6161459327045887 + 0.23879415303332602*I)],
      1),
     (3.3181543016706256 + 0.8209140653434132*I,
      [(0.14559469829270977 + 0.3756690858502104*I, 0.9152458258662107)],
      1)]
Tolerance exceeded in 1 of 12:
    0.14559469829270957 vs 0.14559469829270977, tolerance 1e-15 > 1e-15
**********************************************************************
sage -t --long src/doc/fr/tutorial/tour_linalg.rst
**********************************************************************
File "src/doc/fr/tutorial/tour_linalg.rst", line 115, in doc.fr.tutorial.tour_linalg
Failed example:
    ARDF.eigenvalues()
Expected:
    [-0.09317121994613098, 4.293171219946131]
Got:
    [-0.09317121994613091, 4.293171219946131]
**********************************************************************
File "src/doc/fr/tutorial/tour_linalg.rst", line 118, in doc.fr.tutorial.tour_linalg
Failed example:
    ACDF.eigenvectors_right()  # rel tol 1e-15
Expected:
    [(0.8818456983293743 - 0.8209140653434135*I, [(0.7505608183809549, -0.616145932704589 + 0.2387941530333261*I)], 1),
    (3.3181543016706256 + 0.8209140653434133*I, [(0.14559469829270957 + 0.3756690858502104*I, 0.9152458258662108)], 1)]
Got:
    [(0.8818456983293741 - 0.8209140653434133*I,
      [(0.7505608183809549, -0.6161459327045887 + 0.23879415303332602*I)],
      1),
     (3.3181543016706256 + 0.8209140653434132*I,
      [(0.14559469829270977 + 0.3756690858502104*I, 0.9152458258662107)],
      1)]
Tolerance exceeded in 1 of 12:
    0.14559469829270957 vs 0.14559469829270977, tolerance 1e-15 > 1e-15
**********************************************************************
sage -t --long src/doc/en/tutorial/tour_linalg.rst
**********************************************************************
File "src/doc/en/tutorial/tour_linalg.rst", line 114, in doc.en.tutorial.tour_linalg
Failed example:
    ARDF.eigenvalues()
Expected:
    [-0.09317121994613098, 4.293171219946131]
Got:
    [-0.09317121994613091, 4.293171219946131]
**********************************************************************
File "src/doc/en/tutorial/tour_linalg.rst", line 117, in doc.en.tutorial.tour_linalg
Failed example:
    ACDF.eigenvectors_right()  # rel tol 1e-15
Expected:
    [(0.8818456983293743 - 0.8209140653434135*I, [(0.7505608183809549, -0.616145932704589 + 0.2387941530333261*I)], 1),
    (3.3181543016706256 + 0.8209140653434133*I, [(0.14559469829270957 + 0.3756690858502104*I, 0.9152458258662108)], 1)]
Got:
    [(0.8818456983293741 - 0.8209140653434133*I,
      [(0.7505608183809549, -0.6161459327045887 + 0.23879415303332602*I)],
      1),
     (3.3181543016706256 + 0.8209140653434132*I,
      [(0.14559469829270977 + 0.3756690858502104*I, 0.9152458258662107)],
      1)]
Tolerance exceeded in 1 of 12:
    0.14559469829270957 vs 0.14559469829270977, tolerance 1e-15 > 1e-15
**********************************************************************

which appear to be precision related.

comment:2 Changed 7 years ago by strogdon

  • Branch set to u/strogdon/increase_precision

comment:3 follow-up: Changed 7 years ago by strogdon

  • Commit set to cad29f8061f0760a9410e66fe4f5a6c03a8c9404

Here is a partial push that may not work for everyone. It does work here. I'm not quite sure how to handle the failure

sage -t --long src/sage/rings/polynomial/polynomial_element.pyx


New commits:

01f8611increase abs tol to prevent doctest failures in matrix_double_dense.pyx
57bb552increase rel tol in ru/tutorial/tour_linalg.rst to prevent doctest failures
48e582eincrease rel tol in de/tutorial/tour_linalg.rst to prevent doctest failures
a772108increase rel tol in fr/tutorial/tour_linalg.rst to prevent doctest failures
5110a8aincrease rel tol in en/tutorial/tour_linalg.rst to prevent doctest failures
cad29f8increase abs tol in mpoly.py to prevent doctest failure

comment:4 Changed 7 years ago by strogdon

  • Status changed from new to needs_info

comment:5 Changed 7 years ago by jdemeyer

  • Priority changed from major to blocker

comment:6 in reply to: ↑ 3 Changed 7 years ago by jdemeyer

Replying to strogdon:

Here is a partial push that may not work for everyone. It does work here. I'm not quite sure how to handle the failure

sage -t --long src/sage/rings/polynomial/polynomial_element.pyx

Clearly, the intention of the test is to show that the zeros really are zeros. So I would replace it by

sage: [abs(f(z)) for z in f.roots(multiplicities=False)]  # abs tol 1e-12

Don't forget your Author name.

comment:7 Changed 7 years ago by jpflori

I need a little more fixes on ppc64. I'll push them later.

comment:8 Changed 7 years ago by git

  • Commit changed from cad29f8061f0760a9410e66fe4f5a6c03a8c9404 to 26eeff1d73aaa2cbfed3e73ac8c60f6910737b1f

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

26eeff1use abs to test for zeros

comment:9 Changed 7 years ago by strogdon

  • Authors set to Steven Trogdon
  • Status changed from needs_info to needs_work

Ahh! The nameless author(s).


New commits:

26eeff1use abs to test for zeros

comment:10 Changed 7 years ago by jpflori

Any idea why the test

[f(z) for z in f.roots(multiplicities=False)]

was failing before?

At first sight I see no reason...

comment:11 follow-up: Changed 7 years ago by strogdon

The only thing that jumped out at me was that one of the zeros had no imaginary part. But I don't know why that would cause it to fail. No adjusting of the precision would allow it to pass unless I used abs(f(z)) Maybe something else is up?

comment:12 in reply to: ↑ 11 Changed 7 years ago by jdemeyer

Replying to strogdon:

The only thing that jumped out at me was that one of the zeros had no imaginary part. But I don't know why that would cause it to fail.

Because

<floating point number>

doesn't match

<floating point number><floating point number>*I

no matter what the floating point numbers are.

comment:13 Changed 7 years ago by jpflori

Oh, I see... That's tricky though and could lead to further problems (unless we change every test looking for zeros in CDF to compute norms of elements).

comment:14 Changed 7 years ago by jdemeyer

Same issue with polynomials:

x^3 + 1e-100

doesn't match

x^3

no matter the tolerance.

comment:15 Changed 7 years ago by jpflori

  • Branch changed from u/strogdon/increase_precision to u/jpflori/ticket/17238
  • Commit changed from 26eeff1d73aaa2cbfed3e73ac8c60f6910737b1f to 6566524d37f7f8005b44ff8ce41f098cb1354f7f

Here are a few others tweaks I need on ppc64.


New commits:

9c30abbSome doctests modifs to mitigate numerical noise.
6566524Merge remote-tracking branch 'trac/u/strogdon/increase_precision' into ticket/17238

comment:16 Changed 7 years ago by strogdon

For me there are now missing whitespaces in matrix2.pyx

sage -t --long src/sage/matrix/matrix2.pyx
**********************************************************************
File "src/sage/matrix/matrix2.pyx", line 4941, in sage.matrix.matrix2.Matrix.diagonal.eigenspaces_left
Failed example:
    eigenvalues = em[0]; eigenvalues.dense_matrix().zero_at(2e-15)
Expected:
    [13.348469228349...                0.0                 0.0]
    [               0.0 -1.348469228349...                 0.0]
    [               0.0                0.0                 0.0]
Got:
    [ 13.34846922834953                0.0                0.0]
    [               0.0 -1.348469228349535                0.0]
    [               0.0                0.0                0.0]
**********************************************************************
File "src/sage/matrix/matrix2.pyx", line 5600, in sage.matrix.matrix2.Matrix.diagonal.eigenmatrix_left
Failed example:
    evalues = em[0]; evalues.dense_matrix().zero_at(2e-15)
Expected:
    [13.348469228349...                0.0                 0.0]
    [               0.0 -1.348469228349...                 0.0]
    [               0.0                0.0                 0.0]
Got:
    [ 13.34846922834953                0.0                0.0]
    [               0.0 -1.348469228349535                0.0]
    [               0.0                0.0                0.0]
**********************************************************************

comment:17 Changed 7 years ago by jpflori

Oops, I indeed modified that one. And actually need it for the test to pass.

comment:18 Changed 7 years ago by git

  • Commit changed from 6566524d37f7f8005b44ff8ce41f098cb1354f7f to 807b794c951bfc4bbfe135d1e47629d6f15a5ce9

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

807b794Let doctest with numerical noise in matrix2.pyx pass on different archs.

comment:19 Changed 7 years ago by jpflori

  • Authors changed from Steven Trogdon to Steven Trogdon, Jean-Pierre Flori
  • Status changed from needs_work to needs_review

Different solution using the tol decorator rather than the ... magic. Tests still pass on ppc64.

comment:20 Changed 7 years ago by strogdon

This now works here.

comment:21 Changed 7 years ago by jpflori

Jeroen: would you mind having a final look at this? I basically agree with what Steven did and added minimal changes so that everything is fine on ppc64.

comment:22 Changed 7 years ago by jdemeyer

OK, I'm going to assume that it does indeed fix the problems you are having.

comment:23 Changed 7 years ago by jdemeyer

  • Reviewers set to Jeroen Demeyer
  • Status changed from needs_review to needs_work

Please rebase this on top of #17126.

comment:24 Changed 7 years ago by git

  • Commit changed from 807b794c951bfc4bbfe135d1e47629d6f15a5ce9 to 7efdf3ed90849814d17880579508574de70d1ad3

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

1553f96Additional failing doctest because of numerical noise.
f30a982Fix numerical noise
7efdf3eMerge remote-tracking branch 'trac/u/jdemeyer/ticket/17126' into ticket/17238

comment:25 Changed 7 years ago by jpflori

  • Status changed from needs_work to needs_review

Done.

Note that I also added a forgotten fix for ppc64 (in a separate commit)...

comment:26 follow-up: Changed 7 years ago by jpflori

(As far as #17126 is concerned, the merge slightly increases the tolerance.)

comment:27 in reply to: ↑ 26 Changed 7 years ago by jdemeyer

Replying to jpflori:

the merge slightly increases the tolerance.

Do we need such a large tolerance? Did you check that the tolerance of #17126 is not sufficient?

comment:28 Changed 7 years ago by jpflori

Sure, in fact for all the tolerances I used, I checked it was the minimal one needed on ppc64.

comment:29 Changed 7 years ago by jpflori

And it only goes from 1e-13 to 4e-13.

comment:30 Changed 7 years ago by jdemeyer

In the matrix2.pyx tests, can't you remove the zero_at() part?

comment:31 Changed 7 years ago by jpflori

Yes I think we can.

comment:32 Changed 7 years ago by jpflori

I'm changing the doctest now.

comment:33 Changed 7 years ago by jpflori

But I'll also have to use abs tol rather than rel tol as both zeros and non zeros values are to be checked.

comment:34 Changed 7 years ago by git

  • Commit changed from 7efdf3ed90849814d17880579508574de70d1ad3 to ec64d527939f985f26248800211b72d24fa8a80b

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

ec64d52Use tolerance setting and matrix values from #17126.

comment:35 Changed 7 years ago by jpflori

I've harmonized everything with #17126. It still passes for me.

comment:36 Changed 7 years ago by jdemeyer

  • Status changed from needs_review to positive_review

comment:37 Changed 7 years ago by vbraun

  • Branch changed from u/jpflori/ticket/17238 to ec64d527939f985f26248800211b72d24fa8a80b
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.