-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
implicitly fuzz RNG-dependent doctests with a random random seed #29935
Comments
This comment has been minimized.
This comment has been minimized.
comment:3
Just so that we don't forget that we will have to update https://doc.sagemath.org/html/en/developer/coding_basics.html |
Work Issues: modify coding conventions |
Dependencies: #29904 |
comment:5
There is also #29904. Other than that the Edit: And there is some place where you need to add |
comment:6
Replying to @kliem:
this is a great example of fuzzing catching an apparent error, it seems.
|
Branch: public/29935 |
Commit: |
comment:8
Even in the developer guide there is an example, where it is confusing:
There is no mentioning there that only one particular matrix is tested. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed work issues from modify coding conventions to none |
comment:11
Replying to @kliem:
indeed it assumes (?) that the entries of the random matrix are small in abs value |
comment:12
Nothing to assume there. |
comment:14
How about making the random seed an option to |
comment:15
Will people do that? Especially enough to find incorrect claims. If you look into #29936 we have been claiming a preciseness that is far from true. Even if you consider the relative error instead of the absolute error. fuzzed doctests would have easily detected that. Even worse. Maybe the situation was better at some point and we never caught on about the regression. |
comment:16
it is not a "real" (time-consuming) fuzzing, it is making the main random seed nondeterministic in tests. making it optional is akin to making tests optional. we already found a couple of examples which show usefulness of this change in detecting bugs in Sage. |
comment:17
The option that I propose to add needs to be added in any case, so that when a failure is revealed by a random random seeds, we can reproduce the failure with that seed. |
comment:18
it is a good point - and the non-det. seed needs to be logged - if this is not yet in the branch it should get there. |
comment:19
So I would suggest to use this ticket to introduce the option, not change the default. |
comment:20
no, I don't agree, it makes no sense to test less if one can test more, and also not having it default would not force people to make their tests robust. |
comment:21
By the way I don't think most doctests have the ambition to demonstrate correctness of mathematical claims. In my opinion, if a doctest intends to do that, it should run an explicit loop of several tests. Still deterministically. |
comment:22
Why would creating the option and changing the default have to be done on the same ticket? I think it's best practices to separate the two steps on two tickets. |
comment:23
Feel free to do with the branch whatever you think is reasonable. |
comment:175
Thank you. |
comment:176
No problem, you'll have to rebase this onto the typo-fix too I think. |
Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. This was a forced push. Last 10 new commits:
|
comment:179
Replying to @orlitzky:
I don't know, if this is necessary, but it sure doesn't hurt. |
comment:180
Merge conflict |
comment:181
This is the merge conflict, which permits a trivial solution (at least trivial for a human being): diff --cc src/bin/sage-runtests
index d1fe6567e7,4fc2062b15..0000000000
--- a/src/bin/sage-runtests
+++ b/src/bin/sage-runtests
@@@ -64,59 -55,60 +55,97 @@@ if __name__ == "__main__"
'if "external" is listed, will also run tests for available external software; '
'if "build" is listed, will also run tests specific to Sage\'s build/packaging system; '
'if set to "all", then all tests will be run')
++<<<<<<< HEAD
+ parser.add_option("--randorder", type=int, metavar="SEED", help="randomize order of tests")
+ parser.add_option("--random-seed", dest="random_seed", type=int, metavar="SEED", help="random seed (integer) for fuzzing doctests")
+ parser.add_option("--global-iterations", "--global_iterations", type=int, default=0, help="repeat the whole testing process this many times")
+ parser.add_option("--file-iterations", "--file_iterations", type=int, default=0, help="repeat each file this many times, stopping on the first failure")
+ parser.add_option("--environment", type=str, default="sage.repl.ipython_kernel.all_jupyter", help="name of a module that provides the global environment for tests")
+
+ parser.add_option("-i", "--initial", action="store_true", default=False, help="only show the first failure in each file")
+ parser.add_option("--exitfirst", action="store_true", default=False, help="end the test run immediately after the first failure or unexpected exception")
+ parser.add_option("--force_lib", "--force-lib", action="store_true", default=False, help="do not import anything from the tested file(s)")
+ parser.add_option("--abspath", action="store_true", default=False, help="print absolute paths rather than relative paths")
+ parser.add_option("--verbose", action="store_true", default=False, help="print debugging output during the test")
+ parser.add_option("-d", "--debug", action="store_true", default=False, help="drop into a python debugger when an unexpected error is raised")
+ parser.add_option("--only-errors", action="store_true", default=False, help="only output failures, not test successes")
+
+ parser.add_option("--gdb", action="store_true", default=False, help="run doctests under the control of gdb")
+ parser.add_option("--valgrind", "--memcheck", action="store_true", default=False,
+ help="run doctests using Valgrind's memcheck tool. The log "
+ "files are named sage-memcheck.PID and can be found in " +
+ os.path.join(DOT_SAGE, "valgrind"))
+ parser.add_option("--massif", action="store_true", default=False,
+ help="run doctests using Valgrind's massif tool. The log "
+ "files are named sage-massif.PID and can be found in " +
+ os.path.join(DOT_SAGE, "valgrind"))
+ parser.add_option("--cachegrind", action="store_true", default=False,
+ help="run doctests using Valgrind's cachegrind tool. The log "
+ "files are named sage-cachegrind.PID and can be found in " +
+ os.path.join(DOT_SAGE, "valgrind"))
+ parser.add_option("--omega", action="store_true", default=False,
+ help="run doctests using Valgrind's omega tool. The log "
+ "files are named sage-omega.PID and can be found in " +
+ os.path.join(DOT_SAGE, "valgrind"))
+
+ parser.add_option("-f", "--failed", action="store_true", default=False,
++=======
+ parser.add_argument("--randorder", type=int, metavar="SEED", help="randomize order of tests")
+ parser.add_argument("--random-seed", dest="random_seed", type=int, metavar="SEED", help="random seed for fuzzing doctests")
+ parser.add_argument("--global-iterations", "--global_iterations", type=int, default=0, help="repeat the whole testing process this many times")
+ parser.add_argument("--file-iterations", "--file_iterations", type=int, default=0, help="repeat each file this many times, stopping on the first failure")
+ parser.add_argument("--environment", type=str, default="sage.repl.ipython_kernel.all_jupyter", help="name of a module that provides the global environment for tests")
+
+ parser.add_argument("-i", "--initial", action="store_true", default=False, help="only show the first failure in each file")
+ parser.add_argument("--exitfirst", action="store_true", default=False, help="end the test run immediately after the first failure or unexpected exception")
+ parser.add_argument("--force_lib", "--force-lib", action="store_true", default=False, help="do not import anything from the test
... |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed branch from public/29935-reb to |
Our documentation and tests include a variety of
examples and tests involving randomness.
Those depend on a randomness seed, and up to Sage 9.1
they always used the same one: 0. Thus every run
of
sage -t
ormake [p]test[all][long]
would runthose "random" doctests deterministically.
In many cases, the output of those tests even relied
on that. As a result, random examples and tests
were actually testing that they were run non-randomly!
This is reminiscent of
an xkcd comic illustration of random number generators.
Based on these considerations and the
related sage-devel discussion,
we propose to:
test mathematical functionality independent of
the randomness seed used to run them (see roadmap),
(present ticket),
thus making those tests more robust and more useful,
by becoming more likely to reveal bugs in a variety
of cases including corner cases.
The first step (see #29962, merged in Sage 9.2)
adds a
--random-seed
flag tosage -t
, allowing:Still, when no randomness seed is specified,
the default seed 0 is used. This means most testers
test with the same randomness seed, making "random"
doctests still mostly deterministic in practice.
Here is a way to pick a random randomness seed
and run tests with it (can be used to work on
the tickets in the roadmap):
Once examples and tests involving randomness
have been adapted, the present ticket puts
the final touch by making it so that
when running tests with no seed specified,
a random one will be used:
Being displayed in the output, the seed used
can be used again if needed:
allowing to explore any problematic case
revealed by running the tests with that seed.
Roadmap:
Follow-up:
set_random_seed
in doctests where possible.Errors discovered by this ticket:
src/sage/coding/linear_code.py
(just a wrong doctest, will be fixed here)
KlyachkoBundle_class.random_deformation
ContinuedFraction
roundingZeroDivisonError
when creating polynomial system_nth_root_naive
fails for integer mod #32084_nth_root_naive
fails for integer modplot_vector_field
unstable #32657:plot_vector_field
unstableDepends on #32667
CC: @kliem @orlitzky @DaveWitteMorris @slel @mantepse
Component: doctest framework
Keywords: fuzz, random, seed
Author: Jonathan Kliem
Branch/Commit:
047379c
Reviewer: Michael Orlitzky
Issue created by migration from https://trac.sagemath.org/ticket/29935
The text was updated successfully, but these errors were encountered: