Skip to content

Tests fail on NumPy 2 #17

@gchqdev227

Description

@gchqdev227

Upgrading the version of numpy to >=2 results in the following failures to the tests:

Test output
pytest .               
================================================================================= test session starts ==================================================================================
platform darwin -- Python 3.9.7, pytest-8.4.1, pluggy-1.6.0
rootdir: ***/annchor
configfile: pyproject.toml
collected 16 items                                                                                                                                                                     

annchor/tests/test_annchor.py .....F.                                                                                                                                            [ 43%]
annchor/tests/test_datasets.py ....                                                                                                                                              [ 68%]
annchor/tests/test_distances.py ..                                                                                                                                               [ 81%]
annchor/tests/test_examples.py .F.                                                                                                                                               [100%]

======================================================================================= FAILURES =======================================================================================
_________________________________________________________________________________ test_function_input __________________________________________________________________________________

get_exact_ijs = <function get_exact_ijs_.<locals>.get_exact at 0x127c3bdc0>, f = <function test_function_input.<locals>.wasserstein1 at 0x128681b80>
X = array([[ 0.,  0.,  5., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ..., 10.,  0.,  0.],
       [ 0.,  0.,  0., ..., 16... 0.,  1., ...,  6.,  0.,  0.],
       [ 0.,  0.,  2., ..., 12.,  0.,  0.],
       [ 0.,  0., 10., ..., 12.,  1.,  0.]])
nx = 1797, backend = 'loky', s = 20

    def test_parallelisation(get_exact_ijs, f, X, nx, backend, s=20):
        try:
>           get_exact_ijs(f, X, np.random.randint(nx, size=(s, 2)))

.venv/lib/python3.9/site-packages/annchor/utils.py:250: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.9/site-packages/annchor/utils.py:170: in get_exact
    Parallel(n_jobs=CPU_COUNT, backend=backend, timeout=30)(
.venv/lib/python3.9/site-packages/joblib/parallel.py:2072: in __call__
    return output if self.return_generator else list(output)
.venv/lib/python3.9/site-packages/joblib/parallel.py:1682: in _get_outputs
    yield from self._retrieve()
.venv/lib/python3.9/site-packages/joblib/parallel.py:1841: in _retrieve
    batched_results = batched_results.get_result(self.timeout)
.venv/lib/python3.9/site-packages/joblib/parallel.py:758: in get_result
    return self._return_or_raise()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <joblib.parallel.BatchCompletionCallBack object at 0x12aa81190>

    def _return_or_raise(self):
        try:
            if self.status == TASK_ERROR:
>               raise self._result
E               multiprocessing.context.TimeoutError

.venv/lib/python3.9/site-packages/joblib/parallel.py:773: TimeoutError

During handling of the above exception, another exception occurred:

    def test_function_input():
    
        # Load digits
        data = load_digits()
        X = data["X"]
        M = data["cost_matrix"]
        nx = len(X)
    
        # not njit, no kwargs
        def wasserstein1(x, y):
            return kantorovich(x, y, cost=M)
    
        # not njit, kwargs
        def wasserstein2(x, y, cost=M):
            return kantorovich(x, y, cost=M)
    
        # njit, no kwargs
        @njit()
        def wasserstein3(x, y):
            return kantorovich(x, y, cost=M)
    
        # njit, kwargs
        @njit()
        def wasserstein4(x, y, cost=M):
            return kantorovich(x, y, cost=M)
    
>       ann1 = Annchor(X, wasserstein1)

annchor/tests/test_annchor.py:189: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.9/site-packages/annchor/annchor.py:185: in __init__
    test_parallelisation(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

get_exact_ijs = <function get_exact_ijs_.<locals>.get_exact at 0x127c3bdc0>, f = <function test_function_input.<locals>.wasserstein1 at 0x128681b80>
X = array([[ 0.,  0.,  5., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ..., 10.,  0.,  0.],
       [ 0.,  0.,  0., ..., 16... 0.,  1., ...,  6.,  0.,  0.],
       [ 0.,  0.,  2., ..., 12.,  0.,  0.],
       [ 0.,  0., 10., ..., 12.,  1.,  0.]])
nx = 1797, backend = 'loky', s = 20

    def test_parallelisation(get_exact_ijs, f, X, nx, backend, s=20):
        try:
            get_exact_ijs(f, X, np.random.randint(nx, size=(s, 2)))
        except TimeoutError:
            print("TimeoutError: Parallelisation failed.")
            if isinstance(f, CPUDispatcher):
                print(
                    "Currently using numba parallelisation, try"
                    + " specifying custom parallelistation with"
                    + " get_exact_ijs keyword argument."
                )
            elif backend == "loky":
                print(
                    "Current backend is 'loky', try backend='multiprocessing',"
                    + " or specifying custom parallelistation with"
                    + " get_exact_ijs keyword argument."
                )
            elif backend == "multiprocessing":
                print(
                    "Current backend is 'multiprocessing', try backend='loky',"
                    + " or specifying custom parallelistation with"
                    + " get_exact_ijs keyword argument."
                )
>           raise TimeoutError()
E           multiprocessing.context.TimeoutError

.venv/lib/python3.9/site-packages/annchor/utils.py:271: TimeoutError
--------------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------------
TimeoutError: Parallelisation failed.
Current backend is 'loky', try backend='multiprocessing', or specifying custom parallelistation with get_exact_ijs keyword argument.
____________________________________________________________________________ test_annchor_selective_subset _____________________________________________________________________________

    def test_annchor_selective_subset():
        np.random.seed(1)
        X, y = make_blobs(n_samples=1000, centers=5)  # First data set X,y
        U, v = make_moons(n_samples=1000, noise=0.1)  # Second data set U,v
        U = np.fliplr(U)
    
        # First data set
        knn = 15
        annX = Annchor(X, "euclidean", n_neighbors=knn, p_work=0.2)
    
        annX.fit()
    
        # Second data set
        knn = 15
        annU = Annchor(U, "euclidean", n_neighbors=knn, p_work=0.2)
    
        annU.fit()
    
        # First data set
        ssx = annX.annchor_selective_subset(y=y, alpha=0)
>       assert len(ssx) == 90
E       assert 89 == 90
E        +  where 89 = len(array([  8,  22,  61, 104, 140, 168, 200, 207, 224, 265, 277, 287, 298,\n       303, 307, 314, 317, 338, 397, 420, 467,...,  35, 174, 195, 253, 324, 365, 529, 572,  26,  28,  41,\n        46,  95,  97, 118, 142, 326, 502, 516, 565, 582, 691]))

annchor/tests/test_examples.py:81: AssertionError
--------------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------------
100%|██████████| 1000/1000 [00:00<00:00, 5203.17it/s]
100%|██████████| 1000/1000 [00:00<00:00, 10529.88it/s]
100%|██████████| 138/138 [00:00<00:00, 236.23it/s]
=============================================================================== short test summary info ================================================================================
FAILED annchor/tests/test_annchor.py::test_function_input - multiprocessing.context.TimeoutError
FAILED annchor/tests/test_examples.py::test_annchor_selective_subset - assert 89 == 90
======================================================================= 2 failed, 14 passed in 482.82s (0:08:02) =======================================================================

The second test (annchor/tests/test_examples.py::test_annchor_selective_subset) might just be due to "new random", but the timeout error will need addressing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions