diff --git a/CHANGES.md b/CHANGES.md index ce3c8a39..c47d132b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -31,6 +31,9 @@ depend on how OpenBLAS was compiled with OpenMP. https://github.com/joblib/threadpoolctl/pull/228 +- Fix OpenBLAS detection for conda package on Windows + https://github.com/joblib/threadpoolctl/pull/240 + 3.6.0 (2025-03-13) ================== diff --git a/tests/test_threadpoolctl.py b/tests/test_threadpoolctl.py index 541662a6..9f60cbba 100644 --- a/tests/test_threadpoolctl.py +++ b/tests/test_threadpoolctl.py @@ -913,3 +913,41 @@ def num_threads_created(limit: int) -> int: nmc_1 = num_threads_created(1) nmc_4 = num_threads_created(4) assert nmc_4 - nmc_1 == 6 + + +@pytest.mark.skipif(os.getenv("CONDA_PREFIX") is None, reason="conda-specific test") +@pytest.mark.parametrize("module", ["numpy", "scipy.linalg"]) +def test_conda_blas_detection_after_import(module): + pytest.importorskip(module) + + info = threadpool_info_from_subprocess(module) + + conda = which("conda") or which("micromamba") or which("mamba") + conda_list_output = subprocess.check_output([conda, "list", "--json"], text=True) + conda_list_items = json.loads(conda_list_output) + blas_names_from_conda = [ + each["name"] + for each in conda_list_items + if any(blas_lib in each["name"] for blas_lib in ["openblas", "mkl"]) + ] + blas_names_from_conda = [each.replace("lib", "") for each in blas_names_from_conda] + + if "accelerate" in conda_list_output: + pytest.skip("threadpoolctl does not know how to inspect Accelerate") + + if not blas_names_from_conda: + pytest.skip( + f"{module} has been installed with pip, this is a conda-specific test" + ) + + blas_info = select(info, user_api="blas") + assert len(blas_info) > 0 + + # Flexiblas is built from source on our CI. At the time of writing, it is not + # available in the conda-forge channel. + blas_names_from_threadpoolctl = [ + each["internal_api"] + for each in blas_info + if each["internal_api"] != "flexiblas" + ] + assert set(blas_names_from_threadpoolctl).issubset(blas_names_from_conda) diff --git a/threadpoolctl.py b/threadpoolctl.py index 72fda34f..15146265 100644 --- a/threadpoolctl.py +++ b/threadpoolctl.py @@ -270,6 +270,7 @@ class OpenBLASController(LibController): "libopenblas", "libblas", # legacy conda-forge Windows shim, see _make_controller_from_path "libscipy_openblas", + "openblas", # Windows conda package use openblas.dll ) _symbol_prefixes = ("", "scipy_")