Skip to content

Commit 713bce9

Browse files
authored
TST: adjust other very slow tests (scipy#20487)
1 parent 5fc8d03 commit 713bce9

File tree

8 files changed

+79
-76
lines changed

8 files changed

+79
-76
lines changed

scipy/_lib/tests/test_import_cycles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import sys
23
import subprocess
34

@@ -7,6 +8,7 @@
78
# Check that all modules are importable in a new Python process.
89
# This is not necessarily true if there are import cycles present.
910

11+
@pytest.mark.slow
1012
def test_public_modules_importable():
1113
pids = [subprocess.Popen([sys.executable, '-c', f'import {module}'])
1214
for module in PUBLIC_MODULES]

scipy/integrate/tests/test_quadpack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def simpfunc(z, y, x, t): # Note order of arguments.
342342
(2.,)),
343343
2*8/3.0 * (b**4.0 - a**4.0))
344344

345+
@pytest.mark.xslow
345346
@pytest.mark.parametrize(
346347
"x_lower, x_upper, y_lower, y_upper, z_lower, z_upper, expected",
347348
[

scipy/interpolate/tests/test_gil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run(self):
2828

2929
return WorkerThread()
3030

31-
@pytest.mark.slow
31+
@pytest.mark.xslow
3232
@pytest.mark.xfail(reason='race conditions, may depend on system load')
3333
def test_rectbivariatespline(self):
3434
def generate_params(n_points):

scipy/interpolate/tests/test_rgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def f(x, y):
476476
])
477477
def test_descending_points_nd(self, method, ndims, func):
478478

479-
if ndims == 5 and method in {"cubic", "quintic"}:
479+
if ndims >= 4 and method in {"cubic", "quintic"}:
480480
pytest.skip("too slow; OOM (quintic); or nearly so (cubic)")
481481

482482
rng = np.random.default_rng(42)

scipy/optimize/tests/test__differential_evolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ def c1(x):
13391339
assert_(np.all(res.x >= np.array(bounds)[:, 0]))
13401340
assert_(np.all(res.x <= np.array(bounds)[:, 1]))
13411341

1342-
@pytest.mark.slow
1342+
@pytest.mark.xslow
13431343
@pytest.mark.xfail(platform.machine() == 'ppc64le',
13441344
reason="fails on ppc64le")
13451345
def test_L8(self):

scipy/optimize/tests/test_minimize_constrained.py

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
from scipy.linalg import block_diag
44
from scipy.sparse import csc_matrix
5-
from numpy.testing import (TestCase, assert_array_almost_equal,
5+
from numpy.testing import (assert_array_almost_equal,
66
assert_array_less, assert_, assert_allclose,
77
suppress_warnings)
88
from scipy.optimize import (NonlinearConstraint,
@@ -443,67 +443,70 @@ def hess(x, v):
443443
return NonlinearConstraint(fun, -np.inf, 0, jac, hess)
444444

445445

446-
class TestTrustRegionConstr(TestCase):
447-
448-
@pytest.mark.slow
449-
def test_list_of_problems(self):
450-
list_of_problems = [Maratos(),
451-
Maratos(constr_hess='2-point'),
452-
Maratos(constr_hess=SR1()),
453-
Maratos(constr_jac='2-point', constr_hess=SR1()),
454-
MaratosGradInFunc(),
455-
HyperbolicIneq(),
456-
HyperbolicIneq(constr_hess='3-point'),
457-
HyperbolicIneq(constr_hess=BFGS()),
458-
HyperbolicIneq(constr_jac='3-point',
459-
constr_hess=BFGS()),
460-
Rosenbrock(),
461-
IneqRosenbrock(),
462-
EqIneqRosenbrock(),
463-
BoundedRosenbrock(),
464-
Elec(n_electrons=2),
465-
Elec(n_electrons=2, constr_hess='2-point'),
466-
Elec(n_electrons=2, constr_hess=SR1()),
467-
Elec(n_electrons=2, constr_jac='3-point',
468-
constr_hess=SR1())]
469-
470-
for prob in list_of_problems:
471-
for grad in (prob.grad, '3-point', False):
472-
for hess in (prob.hess,
473-
'3-point',
474-
SR1(),
475-
BFGS(exception_strategy='damp_update'),
476-
BFGS(exception_strategy='skip_update')):
477-
478-
# Remove exceptions
479-
if grad in ('2-point', '3-point', 'cs', False) and \
480-
hess in ('2-point', '3-point', 'cs'):
481-
continue
482-
if prob.grad is True and grad in ('3-point', False):
483-
continue
484-
with suppress_warnings() as sup:
485-
sup.filter(UserWarning, "delta_grad == 0.0")
486-
result = minimize(prob.fun, prob.x0,
487-
method='trust-constr',
488-
jac=grad, hess=hess,
489-
bounds=prob.bounds,
490-
constraints=prob.constr)
491-
492-
if prob.x_opt is not None:
493-
assert_array_almost_equal(result.x, prob.x_opt,
494-
decimal=5)
495-
# gtol
496-
if result.status == 1:
497-
assert_array_less(result.optimality, 1e-8)
498-
# xtol
499-
if result.status == 2:
500-
assert_array_less(result.tr_radius, 1e-8)
501-
502-
if result.method == "tr_interior_point":
503-
assert_array_less(result.barrier_parameter, 1e-8)
504-
# max iter
505-
if result.status in (0, 3):
506-
raise RuntimeError("Invalid termination condition.")
446+
class TestTrustRegionConstr:
447+
list_of_problems = [Maratos(),
448+
Maratos(constr_hess='2-point'),
449+
Maratos(constr_hess=SR1()),
450+
Maratos(constr_jac='2-point', constr_hess=SR1()),
451+
MaratosGradInFunc(),
452+
HyperbolicIneq(),
453+
HyperbolicIneq(constr_hess='3-point'),
454+
HyperbolicIneq(constr_hess=BFGS()),
455+
HyperbolicIneq(constr_jac='3-point',
456+
constr_hess=BFGS()),
457+
Rosenbrock(),
458+
IneqRosenbrock(),
459+
EqIneqRosenbrock(),
460+
BoundedRosenbrock(),
461+
Elec(n_electrons=2),
462+
Elec(n_electrons=2, constr_hess='2-point'),
463+
Elec(n_electrons=2, constr_hess=SR1()),
464+
Elec(n_electrons=2, constr_jac='3-point',
465+
constr_hess=SR1())]
466+
467+
@pytest.mark.parametrize('prob', list_of_problems)
468+
@pytest.mark.parametrize('grad', ('prob.grad', '3-point', False))
469+
@pytest.mark.parametrize('hess', ("prob.hess", '3-point', SR1(),
470+
BFGS(exception_strategy='damp_update'),
471+
BFGS(exception_strategy='skip_update')))
472+
def test_list_of_problems(self, prob, grad, hess):
473+
grad = prob.grad if grad == "prob.grad" else grad
474+
hess = prob.hess if hess == "prob.hess" else hess
475+
# Remove exceptions
476+
if (grad in {'2-point', '3-point', 'cs', False} and
477+
hess in {'2-point', '3-point', 'cs'}):
478+
pytest.skip("Numerical Hessian needs analytical gradient")
479+
if prob.grad is True and grad in {'3-point', False}:
480+
pytest.skip("prob.grad incompatible with grad in {'3-point', False}")
481+
sensitive = (isinstance(prob, BoundedRosenbrock) and grad == '3-point'
482+
and isinstance(hess, BFGS))
483+
if sensitive:
484+
pytest.xfail("Seems sensitive to initial conditions w/ Accelerate")
485+
with suppress_warnings() as sup:
486+
sup.filter(UserWarning, "delta_grad == 0.0")
487+
result = minimize(prob.fun, prob.x0,
488+
method='trust-constr',
489+
jac=grad, hess=hess,
490+
bounds=prob.bounds,
491+
constraints=prob.constr)
492+
493+
if prob.x_opt is not None:
494+
assert_array_almost_equal(result.x, prob.x_opt,
495+
decimal=5)
496+
# gtol
497+
if result.status == 1:
498+
assert_array_less(result.optimality, 1e-8)
499+
# xtol
500+
if result.status == 2:
501+
assert_array_less(result.tr_radius, 1e-8)
502+
503+
if result.method == "tr_interior_point":
504+
assert_array_less(result.barrier_parameter, 1e-8)
505+
506+
# check for max iter
507+
message = f"Invalid termination condition: {result.status}."
508+
assert result.status not in {0, 3}, message
509+
507510

508511
def test_default_jac_and_hess(self):
509512
def fun(x):
@@ -641,7 +644,7 @@ def obj(x):
641644

642645
assert result['success']
643646

644-
class TestEmptyConstraint(TestCase):
647+
class TestEmptyConstraint:
645648
"""
646649
Here we minimize x^2+y^2 subject to x^2-y^2>1.
647650
The actual minimum is at (0, 0) which fails the constraint.

scipy/sparse/linalg/_eigen/lobpcg/tests/test_lobpcg.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,7 @@ def test_diagonal_data_types(n, m):
548548
# and where we choose A and B to be diagonal.
549549
vals = np.arange(1, n + 1)
550550

551-
# list_sparse_format = ['bsr', 'coo', 'csc', 'csr', 'dia', 'dok', 'lil']
552-
list_sparse_format = ['coo']
553-
sparse_formats = len(list_sparse_format)
551+
list_sparse_format = ['bsr', 'coo', 'csc', 'csr', 'dia', 'dok', 'lil']
554552
for s_f_i, s_f in enumerate(list_sparse_format):
555553

556554
As64 = diags([vals * vals], [0], (n, n), format=s_f)
@@ -629,15 +627,13 @@ def Mf32precond(x):
629627
listY = [Yf64, Yf32]
630628

631629
tests = list(itertools.product(listA, listB, listM, listX, listY))
632-
# This is one of the slower tests because there are >1,000 configs
633-
# to test here, instead of checking product of all input, output types
634-
# test each configuration for the first sparse format, and then
635-
# for one additional sparse format. this takes 2/7=30% as long as
636-
# testing all configurations for all sparse formats.
637-
if s_f_i > 0:
638-
tests = tests[s_f_i - 1::sparse_formats-1]
639630

640631
for A, B, M, X, Y in tests:
632+
# This is one of the slower tests because there are >1,000 configs
633+
# to test here. Flip a biased coin to decide whether to run each
634+
# test to get decent coverage in less time.
635+
if rnd.random() < 0.95:
636+
continue # too many tests
641637
eigvals, _ = lobpcg(A, X, B=B, M=M, Y=Y, tol=1e-4,
642638
maxiter=100, largest=False)
643639
assert_allclose(eigvals,

scipy/sparse/linalg/tests/test_propack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_svdp(ctor, dtype, irl, which):
8989
check_svdp(n, m, ctor, dtype, k, irl, which)
9090

9191

92+
@pytest.mark.xslow
9293
@pytest.mark.parametrize('dtype', _dtypes)
9394
@pytest.mark.parametrize('irl', (False, True))
9495
@pytest.mark.timeout(120) # True, complex64 > 60 s: prerel deps cov 64bit blas

0 commit comments

Comments
 (0)