Skip to content

Commit

Permalink
use future annotations for testing on 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisblake committed Dec 19, 2023
1 parent 4aead8d commit 2b43b46
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/optimparallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- optimparallel: same as `minimize_parallel()`
- fmin_l_bfgs_b_parallel: parallel version of `scipy.optimize.fmin_l_bfgs_b()`
"""
from __future__ import annotations

import warnings
import concurrent.futures
Expand All @@ -24,6 +25,7 @@
from typing import Any, Callable
from numpy.typing import ArrayLike


__all__ = [
"minimize_parallel",
"fmin_l_bfgs_b_parallel",
Expand Down
1 change: 1 addition & 0 deletions test/test_fmin_l_bfgs_b_parallel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# test fmin_l_bfgs_b_parallel()
from __future__ import annotations
import pytest
import itertools
import numpy as np
Expand Down
39 changes: 28 additions & 11 deletions test/test_minimize_parallel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# test minimize_parallel()
from __future__ import annotations
import pytest
import itertools
import concurrent.futures
Expand Down Expand Up @@ -142,7 +143,6 @@ def check_minimize(
TRACEBACKHIDE=True,
ATOL=1e-5,
):

"""Helper function to minimize_parallel() against minimize()."""
__tracebackhide__ = TRACEBACKHIDE

Expand All @@ -158,7 +158,7 @@ def check_minimize(
"verbose": verbose,
"executor": None,
}

options = {
"disp": disp,
"maxcor": maxcor,
Expand All @@ -184,6 +184,7 @@ def check_minimize(
ATOL=ATOL,
)


@pytest.mark.parametrize("fun_id", [0])
@pytest.mark.parametrize("x0", [np.array([1]), np.array([1, 2])])
@pytest.mark.parametrize("approx_grad", [True, False])
Expand All @@ -195,9 +196,22 @@ def check_minimize(
@pytest.mark.parametrize("maxiter", [1, 1500])
@pytest.mark.parametrize("disp", [None])
@pytest.mark.parametrize("maxls", [20, 1])
@pytest.mark.parametrize("executor", [None, concurrent.futures.ThreadPoolExecutor(max_workers=2)])
@pytest.mark.parametrize(
"executor", [None, concurrent.futures.ThreadPoolExecutor(max_workers=2)]
)
def test_minimize_args0(
fun_id, x0, approx_grad, maxcor, ftol, gtol, eps, iprint, maxiter, disp, maxls, executor
fun_id,
x0,
approx_grad,
maxcor,
ftol,
gtol,
eps,
iprint,
maxiter,
disp,
maxls,
executor,
):
check_minimize(
fun_id=fun_id,
Expand All @@ -211,7 +225,7 @@ def test_minimize_args0(
maxiter=maxiter,
disp=disp,
maxls=maxls,
executor=executor
executor=executor,
)


Expand Down Expand Up @@ -247,7 +261,9 @@ def test_minimize_time(x0):
@pytest.mark.parametrize("approx_grad", [True, False])
@pytest.mark.parametrize("max_workers", [2, None])
@pytest.mark.parametrize("forward", [True, False])
@pytest.mark.parametrize("executor", [None, concurrent.futures.ThreadPoolExecutor(max_workers=2)])
@pytest.mark.parametrize(
"executor", [None, concurrent.futures.ThreadPoolExecutor(max_workers=2)]
)
def test_minimize_args1(fun_id, x0, args, approx_grad, max_workers, forward, executor):
check_minimize(
fun_id=fun_id,
Expand All @@ -256,7 +272,7 @@ def test_minimize_args1(fun_id, x0, args, approx_grad, max_workers, forward, exe
approx_grad=approx_grad,
max_workers=max_workers,
forward=forward,
executor=executor
executor=executor,
)


Expand All @@ -267,7 +283,9 @@ def test_minimize_args1(fun_id, x0, args, approx_grad, max_workers, forward, exe
@pytest.mark.parametrize("approx_grad", [True, False])
@pytest.mark.parametrize("max_workers", [2, None])
@pytest.mark.parametrize("forward", [True, False])
@pytest.mark.parametrize("executor", [None, concurrent.futures.ThreadPoolExecutor(max_workers=2)])
@pytest.mark.parametrize(
"executor", [None, concurrent.futures.ThreadPoolExecutor(max_workers=2)]
)
def test_minimize_args2(fun_id, x0, args, approx_grad, max_workers, forward, executor):
check_minimize(
fun_id=fun_id,
Expand All @@ -276,9 +294,10 @@ def test_minimize_args2(fun_id, x0, args, approx_grad, max_workers, forward, exe
approx_grad=approx_grad,
max_workers=max_workers,
forward=forward,
executor=executor
executor=executor,
)


# test bounds upper -------------------------------
@pytest.mark.parametrize("fun_id", ["_upper0"])
@pytest.mark.parametrize("x0", [np.array([-9]), np.array([-9, -99])])
Expand Down Expand Up @@ -334,5 +353,3 @@ def test_minimize_tol(fun_id, approx_grad, x0, tol, options):
fun = globals()["fun" + str(fun_id)]
jac = None if approx_grad else globals()["jac" + str(fun_id)]
compare_minimize(x0=x0, tol=tol, options=options)


0 comments on commit 2b43b46

Please sign in to comment.