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

Increase Precision in Failing Doctests #17238

Closed
strogdon opened this issue Oct 27, 2014 · 44 comments
Closed

Increase Precision in Failing Doctests #17238

strogdon opened this issue Oct 27, 2014 · 44 comments

Comments

@strogdon
Copy link

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

CC: @jpflori

Component: doctest coverage

Author: Steven Trogdon, Jean-Pierre Flori

Branch/Commit: ec64d52

Reviewer: Jeroen Demeyer

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

@strogdon strogdon added this to the sage-6.4 milestone Oct 27, 2014
@strogdon
Copy link
Author

comment:1

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.

@strogdon
Copy link
Author

Branch: u/strogdon/increase_precision

@strogdon
Copy link
Author

Commit: cad29f8

@strogdon
Copy link
Author

comment:3

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

@jdemeyer
Copy link

comment:6

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.

@jpflori
Copy link

jpflori commented Oct 28, 2014

comment:7

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

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 28, 2014

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

26eeff1use abs to test for zeros

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 28, 2014

Changed commit from cad29f8 to 26eeff1

@strogdon
Copy link
Author

comment:9

Ahh! The nameless author(s).


New commits:

26eeff1use abs to test for zeros

@strogdon
Copy link
Author

Author: Steven Trogdon

@jpflori
Copy link

jpflori commented Oct 28, 2014

comment:10

Any idea why the test

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

was failing before?

At first sight I see no reason...

@strogdon
Copy link
Author

comment:11

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?

@jdemeyer
Copy link

comment:12

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.

@jpflori
Copy link

jpflori commented Oct 28, 2014

comment:13

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).

@jdemeyer
Copy link

comment:14

Same issue with polynomials:

x^3 + 1e-100

doesn't match

x^3

no matter the tolerance.

@jpflori
Copy link

jpflori commented Oct 28, 2014

Changed commit from 26eeff1 to 6566524

@jpflori
Copy link

jpflori commented Oct 28, 2014

comment:15

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

@jpflori
Copy link

jpflori commented Oct 28, 2014

Changed branch from u/strogdon/increase_precision to u/jpflori/ticket/17238

@strogdon
Copy link
Author

comment:16

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]
**********************************************************************

@jpflori
Copy link

jpflori commented Oct 28, 2014

comment:17

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

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 28, 2014

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

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

@strogdon
Copy link
Author

comment:20

This now works here.

@jpflori
Copy link

jpflori commented Oct 28, 2014

comment:21

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.

@jdemeyer
Copy link

comment:22

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

@jdemeyer
Copy link

comment:23

Please rebase this on top of #17126.

@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 29, 2014

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

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 29, 2014

Changed commit from 807b794 to 7efdf3e

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:25

Done.

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

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:26

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

@jdemeyer
Copy link

comment:27

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?

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:28

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

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:29

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

@jdemeyer
Copy link

comment:30

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

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:31

Yes I think we can.

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:32

I'm changing the doctest now.

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:33

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

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 29, 2014

Changed commit from 7efdf3e to ec64d52

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 29, 2014

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

ec64d52Use tolerance setting and matrix values from #17126.

@jpflori
Copy link

jpflori commented Oct 29, 2014

comment:35

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

@vbraun
Copy link
Member

vbraun commented Oct 30, 2014

Changed branch from u/jpflori/ticket/17238 to ec64d52

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

4 participants