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

Use CPU time for --warn-long #36226

Merged
merged 37 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9b419f5
src/sage/doctest: use CPU time for --warn-long
orlitzky Sep 9, 2023
4ab2c28
src/doc/en/developer/doctesting.rst: we use CPU time now
orlitzky Sep 9, 2023
3701d9d
src/bin/sage{,-runtests}: mention CPU time in --warn-long
orlitzky Sep 9, 2023
2c62590
src/sage/doctest/control.py: decrease standard --warn-long limit
orlitzky Dec 8, 2021
c460a5a
src/sage/doctest/forker.py: report verbose doctest success in CPU time
orlitzky Feb 9, 2022
fce17d7
src/sage/doctest/util.py: cputime for pexpect interfaces on Linux/BSD
orlitzky Sep 8, 2023
1334027
src/sage/doctest/forker.py: report both cpu/wall times for long tests
orlitzky Sep 8, 2023
945665c
src/sage/doctest: specify walltime in per-file doctest report
orlitzky Sep 8, 2023
eb9f36d
src/sage/doctest/forker.py: specify walltime in sage -t --verbose output
orlitzky Mar 12, 2022
ff19804
src/sage/doctest/control.py: further reduce the --warn-long limit
orlitzky Sep 13, 2023
42e51fe
src/sage/doctest/util.py: update a comment
orlitzky Sep 13, 2023
f949101
src/sage/doctest/util.py: refactor exception handling
orlitzky Sep 13, 2023
db1eba0
src/sage/doctest/control.py: update _init_warn_long() docstring
orlitzky Sep 22, 2023
6120b12
src/sage/doctest/util.py: delete a wandering "and"
orlitzky Sep 29, 2023
a79c88f
src/sage/doctest/util.py: add doctests for Timer._quick_cputime()
orlitzky Sep 29, 2023
6d118a7
src/sage/doctest/util.py: improve docstring for Timer._pid_cpu_seconds()
orlitzky Sep 29, 2023
738f59c
src/sage/doctest/util.py: reword docstring to make flake8 happy
orlitzky Apr 16, 2024
9b59fa5
src/sage/doctest/control.py: update the output from one more test
orlitzky Apr 16, 2024
ec866e0
src/sage/doctest/reporting.py: spaces around % for pycodestyle
orlitzky Apr 16, 2024
711abfa
src/sage/doctest/util.py: fix _pid_cpu_seconds doctest on macOS
orlitzky Apr 23, 2024
7f9d32f
pkgs/sagemath-repl/MANIFEST.in: include sage.interfaces.{cleaner,quit}
orlitzky Oct 15, 2024
6bc91b5
sage/interfaces/{cleaner,quit}.py: tag as distribution = sagemath-repl
orlitzky Oct 15, 2024
f3b90c1
pkgs/sagemath-repl/pyproject.toml.m4: add package sage.interfaces
orlitzky Oct 15, 2024
d4d8b22
src/sage/doctest/util.py: add error messages and test one of them
orlitzky Oct 15, 2024
2bdd10c
src/sage/doctest/util.py: improve a comment
orlitzky Oct 15, 2024
4a9fdf2
src/sage/doctest/util.py: refactor _quick_cputime() for testability
orlitzky Oct 15, 2024
f2cf28c
src/sage/doctest/util.py: refactor for testability
orlitzky Oct 15, 2024
b7f0631
src/sage/doctest/util.py: test _proc_stat_cpu_seconds() error paths
orlitzky Oct 15, 2024
63db6ab
src/sage/doctest/util.py: support macOS if psutil is installed
orlitzky Oct 15, 2024
0c58518
src/sage/doctest/util.py: ignore ZombieProcess errors from psutil
orlitzky Oct 15, 2024
db01308
src/sage/doctest/util.py: avoid dependency on sage.misc.timing.walltime
orlitzky Oct 16, 2024
832c792
src/sage/doctest/forker.py: remove old python 2 workaround
orlitzky Oct 16, 2024
993327b
src/sage/doctest/util.py: handle NoSuchProcess from psutil, too
orlitzky Oct 16, 2024
7aa6be8
src/sage/doctest/util.py: put "import" inside the "try"
orlitzky Oct 16, 2024
cf55b38
src/sage/doctest/forker.py: re-raise SignalErrors
orlitzky Oct 16, 2024
660e8ca
sage/doctest/control.py: deprecate second_on_modern_computer()
orlitzky Oct 20, 2024
efa14c3
src/sage/doctest/forker.py: change the slow doctest warning punctuation
orlitzky Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkgs/sagemath-repl/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ include sage/misc/sagedoc.py
include sage/misc/sage_input.py
include sage/misc/sage_eval.py

# expect_objects from sage.interfaces.quit is needed to compute the
# CPU time used by each doctest. We include sage.interfaces.cleaner
# because it is conditionally imported by sage.interfaces.quit.
include sage/interfaces/quit.py
include sage/interfaces/cleaner.py

include VERSION.txt

global-exclude all__*.py
Expand Down
1 change: 1 addition & 0 deletions pkgs/sagemath-repl/pyproject.toml.m4
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ py-modules = [
]
packages = [
"sage.doctest",
"sage.interfaces",
"sage.repl",
"sage.repl.display",
"sage.repl.ipython_kernel",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ usage_advanced() {
echo " --initial -- only show the first failure per block"
echo " --debug -- drop into PDB after an unexpected error"
echo " --failed -- only test files that failed last test"
echo " --warn-long [timeout] -- warning if doctest is slow"
echo " --warn-long [timeout] -- warn if tests take too much CPU time"
echo " --only-errors -- only output failures, not successes"
echo " --gc=GC -- control garbarge collection (ALWAYS:"
echo " collect garbage before every test; NEVER:"
Expand Down
20 changes: 10 additions & 10 deletions src/doc/en/developer/doctesting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,10 @@ In order to run the long tests as well, do the following::
cpu time: 25.2 seconds
cumulative wall time: 34.7 seconds

To find tests that take longer than the allowed time use the
``--warn-long`` flag. Without any options it will cause tests to
print a warning if they take longer than 1.0 second. Note that this is
a warning, not an error::
To find tests that take longer than a specified amount of CPU time,
use the ``--warn-long`` flag. Without any options, it will cause a
warning to be printed if any tests take longer than one
cpu-second. Note that this is a warning, not an error::

[roed@localhost sage]$ ./sage -t --warn-long src/sage/rings/factorint.pyx
Running doctests with ID 2012-07-14-03-27-03-2c952ac1.
Expand All @@ -758,22 +758,22 @@ a warning, not an error::
File "src/sage/rings/factorint.pyx", line 125, in sage.rings.factorint.base_exponent
Failed example:
base_exponent(-4)
Test ran for 4.09 s
Test ran for 4.09 cpu seconds
**********************************************************************
File "src/sage/rings/factorint.pyx", line 153, in sage.rings.factorint.factor_aurifeuillian
Failed example:
fa(2^6+1)
Test ran for 2.22 s
Test ran for 2.22 cpu seconds
**********************************************************************
File "src/sage/rings/factorint.pyx", line 155, in sage.rings.factorint.factor_aurifeuillian
Failed example:
fa(2^58+1)
Test ran for 2.22 s
Test ran for 2.22 cpu seconds
**********************************************************************
File "src/sage/rings/factorint.pyx", line 163, in sage.rings.factorint.factor_aurifeuillian
Failed example:
fa(2^4+1)
Test ran for 2.25 s
Test ran for 2.25 cpu seconds
**********************************************************************
----------------------------------------------------------------------
All tests passed!
Expand All @@ -792,12 +792,12 @@ You can also pass in an explicit amount of time::
File "tests.py", line 240, in sage.rings.tests.test_random_elements
Failed example:
sage.rings.tests.test_random_elements(trials=1000) # long time (5 seconds)
Test ran for 13.36 s
Test ran for 13.36 cpu seconds
**********************************************************************
File "tests.py", line 283, in sage.rings.tests.test_random_arith
Failed example:
sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?)
Test ran for 12.42 s
Test ran for 12.42 cpu seconds
**********************************************************************
----------------------------------------------------------------------
All tests passed!
Expand Down
2 changes: 1 addition & 1 deletion src/sage/doctest/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _make_parser():
help="run as many doctests as possible in about 300 seconds (or the number of seconds given as an optional argument)")
parser.add_argument("--warn-long", dest="warn_long", nargs='?',
type=float, default=-1.0, const=1.0, metavar="SECONDS",
help="warn if tests take more time than SECONDS")
help="warn if tests take more CPU time than SECONDS")
# By default, include all tests marked 'sagemath_doc_html' -- see
# https://github.com/sagemath/sage/issues/25345 and
# https://github.com/sagemath/sage/issues/26110:
Expand Down
46 changes: 24 additions & 22 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,36 +588,38 @@ def __del__(self):

def _init_warn_long(self):
"""
Pick a suitable default for the ``--warn-long`` option if not specified.
Pick a suitable default for the ``--warn-long`` option if not
specified.

It is desirable to have all tests (even ``# long`` ones)
finish in less than about 5 seconds. Longer tests typically
don't add coverage, they just make testing slow.

The default used here is 60 seconds on a modern computer. It
should eventually be lowered to 5 seconds, but its best to
boil the frog slowly.
The default used here is 5 seconds, unless `--long` was used,
in which case it is 30 seconds.

The stored timings are used to adjust this limit according to
the machine running the tests.
TESTS:

EXAMPLES::
Ensure that the user's command-line options are not changed::

sage: from sage.doctest.control import DocTestDefaults, DocTestController
sage: from sage.doctest.control import (DocTestDefaults,
....: DocTestController)
sage: DC = DocTestController(DocTestDefaults(), [])
sage: DC.options.warn_long = 5.0
sage: DC._init_warn_long()
sage: DC.options.warn_long # existing command-line options are not changed
sage: DC.options.warn_long
5.00000000000000
"""
# default is -1.0
if self.options.warn_long >= 0: # Specified on the command line
return
try:
self.options.warn_long = 60.0 * self.second_on_modern_computer()
except RuntimeError as err:
if not sage.doctest.DOCTEST_MODE:
print(err) # No usable timing information

# The developer's guide says that even a "long time" test
# should ideally complete in under five seconds, so we're
# being rather generous here.
self.options.warn_long = 5.0
if self.options.long:
self.options.warn_long = 30.0

def second_on_modern_computer(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can now be deleted, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it's a "public" function, so I didn't want to start an argument over the deprecation policy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is safe to consider everything in doctest as private. But as a compromise, at least add a deprecation warning so that this can be removed in 1year?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""
Expand Down Expand Up @@ -1152,7 +1154,7 @@ def run_doctests(self):
sage: DC.run_doctests()
Doctesting 1 file.
sage -t .../sage/rings/homset.py
[... tests, ... s]
[... tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand Down Expand Up @@ -1229,7 +1231,7 @@ def cleanup(self, final=True):
Running doctests with ID ...
Doctesting 1 file.
sage -t .../rings/all.py
[... tests, ... s]
[... tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand Down Expand Up @@ -1433,7 +1435,7 @@ def run(self):
Running doctests with ID ...
Doctesting 1 file.
sage -t .../sage/sets/non_negative_integers.py
[... tests, ... s]
[... tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand All @@ -1457,7 +1459,7 @@ def run(self):
Features to be detected: ...
Doctesting 1 file.
sage -t ....py
[0 tests, ... s]
[0 tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand All @@ -1483,7 +1485,7 @@ def run(self):
Features to be detected: ...
Doctesting 1 file.
sage -t ....py
[4 tests, ... s]
[4 tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand All @@ -1501,7 +1503,7 @@ def run(self):
Features to be detected: ...
Doctesting 1 file.
sage -t ....py
[4 tests, ... s]
[4 tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand All @@ -1519,7 +1521,7 @@ def run(self):
Features to be detected: ...
Doctesting 1 file.
sage -t ....py
[4 tests, ... s]
[4 tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand Down Expand Up @@ -1627,7 +1629,7 @@ def run_doctests(module, options=None):
Running doctests with ID ...
Doctesting 1 file.
sage -t .../sage/rings/all.py
[... tests, ... s]
[... tests, ...s wall]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Expand Down
Loading
Loading