Skip to content

Commit

Permalink
Add HOST_INFO.INCLUDE_CPU_INFO setting (#889)
Browse files Browse the repository at this point in the history
* Add HOST_INFO.INCLUDE_CPU_INFO setting

On my machine, py-cpuinfo is quite slow. Seems it's a known issue:
workhorsy/py-cpuinfo#155

This setting cuts the time it takes me to run the test suite in half.

* Add documentation

Co-authored-by: chris.grace <[email protected]>
  • Loading branch information
Gracecr and chris-grace-mastodon authored Oct 17, 2022
1 parent 940ac81 commit e7bc7a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Here is a brief list of all currently available options.
* ``INCLUDE_GPU_INFO`` *(default: True)*
Try to collect information about GPUs using the nvidia-smi tool.
Deactivating this can cut the start-up time of a Sacred run by about 1 sec.
* ``INCLUDE_CPU_INFO`` *(default: True)*
Try to collect information about the CPU using py-cpuinfo.
Deactivating this can cut the start-up time of a Sacred run by about 3 sec.
* ``CAPTURED_ENV`` *(default: [])*
List of ENVIRONMENT variable names to store in the host-info.

Expand Down
3 changes: 3 additions & 0 deletions sacred/host_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def _python_version():

@host_info_gatherer(name="cpu")
def _cpu():
if not SETTINGS.HOST_INFO.INCLUDE_CPU_INFO:
return

if platform.system() == "Windows":
return _get_cpu_by_pycpuinfo()
try:
Expand Down
2 changes: 2 additions & 0 deletions sacred/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def __deepcopy__(self, memodict=None):
"HOST_INFO": {
# Collect information about GPUs using the nvidia-smi tool
"INCLUDE_GPU_INFO": True,
# Collect information about CPUs using py-cpuinfo
"INCLUDE_CPU_INFO": True,
# List of ENVIRONMENT variables to store in host-info
"CAPTURED_ENV": [],
},
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ def tmpfile():
os.remove(f.name)


# Deactivate GPU info to speed up tests
# Deactivate GPU and CPU info to speed up tests
SETTINGS.HOST_INFO.INCLUDE_GPU_INFO = False
SETTINGS.HOST_INFO.INCLUDE_CPU_INFO = False
7 changes: 5 additions & 2 deletions tests/test_host_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from sacred.host_info import get_host_info, host_info_getter, host_info_gatherers


def test_get_host_info():
host_info = get_host_info()
def test_get_host_info(monkeypatch: pytest.MonkeyPatch):
with monkeypatch.context() as cntx:
cntx.setattr("sacred.settings.SETTINGS.HOST_INFO.INCLUDE_CPU_INFO", True)
host_info = get_host_info()
assert isinstance(host_info["hostname"], str)
assert isinstance(host_info["cpu"], str)
assert host_info["cpu"] != "Unknown"
assert isinstance(host_info["os"], (tuple, list))
assert isinstance(host_info["python_version"], str)

Expand Down

0 comments on commit e7bc7a7

Please sign in to comment.