Skip to content

Commit

Permalink
ENH Adds threadpoolctl info into show_versions (#21457)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
  • Loading branch information
thomasjpfan and ogrisel committed Nov 2, 2021
1 parent f449af8 commit fe62250
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/wheels.yml
Expand Up @@ -84,6 +84,8 @@ jobs:

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9' # update once build dependencies are available

- name: Build and test wheels
env:
Expand Down
1 change: 0 additions & 1 deletion build_tools/azure/test_script.sh
Expand Up @@ -17,7 +17,6 @@ cp setup.cfg $TEST_DIR
cd $TEST_DIR

python -c "import sklearn; sklearn.show_versions()"
python -m threadpoolctl -i sklearn

if ! command -v conda &> /dev/null
then
Expand Down
6 changes: 3 additions & 3 deletions build_tools/github/test_wheels.sh
Expand Up @@ -9,7 +9,7 @@ if [[ "$OSTYPE" != "linux-gnu" ]]; then
cp $CONFTEST_PATH $CONFTEST_NAME
fi

# Test that there are no links to system libraries in the
# threadpoolctl output section of the show_versions output:
python -c "import sklearn; sklearn.show_versions()"
pytest --pyargs sklearn

# Test that there are no links to system libraries
python -m threadpoolctl -i sklearn
18 changes: 10 additions & 8 deletions build_tools/github/test_windows_wheels.sh
Expand Up @@ -10,15 +10,17 @@ if [[ "$BITNESS" == "32" ]]; then
# 32-bit architectures use the regular
# test command (outside of the minimal Docker container)
cp $CONFTEST_PATH $CONFTEST_NAME
python -c "import sklearn; sklearn.show_versions()"
pytest --pyargs sklearn
python -m threadpoolctl -i sklearn
else
docker container run -e SKLEARN_SKIP_NETWORK_TESTS=1 \
-e OMP_NUM_THREADS=2 \
-e OPENBLAS_NUM_THREADS=2 \
--rm scikit-learn/minimal-windows \
powershell -Command "pytest --pyargs sklearn"
docker container run \
--rm scikit-learn/minimal-windows \
powershell -Command "python -c 'import sklearn; sklearn.show_versions()'"

docker container run --rm scikit-learn/minimal-windows \
powershell -Command "python -m threadpoolctl -i sklearn"
docker container run \
-e SKLEARN_SKIP_NETWORK_TESTS=1 \
-e OMP_NUM_THREADS=2 \
-e OPENBLAS_NUM_THREADS=2 \
--rm scikit-learn/minimal-windows \
powershell -Command "pytest --pyargs sklearn"
fi
6 changes: 3 additions & 3 deletions build_tools/travis/test_wheels.sh
Expand Up @@ -3,7 +3,7 @@
pip install --upgrade pip || travis_terminate $?
pip install pytest pytest-xdist || travis_terminate $?

# Test that there are no links to system libraries in the threadpoolctl
# section of the show_versions output.
python -c "import sklearn; sklearn.show_versions()" || travis_terminate $?
python -m pytest -n $CPU_COUNT --pyargs sklearn || travis_terminate $?

# Test that there are no links to system libraries
python -m threadpoolctl -i sklearn || travis_terminate $?
14 changes: 14 additions & 0 deletions sklearn/utils/_show_versions.py
Expand Up @@ -8,6 +8,8 @@
import platform
import sys
import importlib
from ..utils.fixes import threadpool_info


from ._openmp_helpers import _openmp_parallelism_enabled

Expand Down Expand Up @@ -95,3 +97,15 @@ def show_versions():
k="Built with OpenMP", stat=_openmp_parallelism_enabled()
)
)

# show threadpoolctl results
threadpool_results = threadpool_info()
if threadpool_results:
print()
print("threadpoolctl info:")

for i, result in enumerate(threadpool_results):
for key, val in result.items():
print(f"{key:>15}: {val}")
if i != len(threadpool_results) - 1:
print()
5 changes: 5 additions & 0 deletions sklearn/utils/tests/test_show_versions.py
@@ -1,3 +1,4 @@
from sklearn.utils.fixes import threadpool_info
from sklearn.utils._show_versions import _get_sys_info
from sklearn.utils._show_versions import _get_deps_info
from sklearn.utils._show_versions import show_versions
Expand Down Expand Up @@ -34,3 +35,7 @@ def test_show_versions(capsys):

assert "python" in out
assert "numpy" in out

info = threadpool_info()
if info:
assert "threadpoolctl info:" in out

0 comments on commit fe62250

Please sign in to comment.