Coverage for src/pymlbenchmark/context/machine.py: 100%
40 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-08 00:27 +0100
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-08 00:27 +0100
1"""
2@file
3@brief Helpers which returns more information about the system.
4"""
5import sys
6import io
7import platform
8import contextlib
9from datetime import datetime
10import numpy
11from cpuinfo import get_cpu_info # pylint: disable=E0401
14def get_numpy_info():
15 """
16 Retrieves information about numpy compilation.
17 """
18 s = io.StringIO()
19 with contextlib.redirect_stdout(s):
20 numpy.show_config()
21 return s.getvalue()
24def machine_information(pkgs=None):
25 """
26 Returns information about the machine.
28 @param pkgs if not None, adds version information for the
29 listed packages
30 @return list of dictionaries
32 .. runpython::
33 :showcode:
35 from pymlbenchmark.context import machine_information
36 for row in machine_information():
37 print(row)
39 .. runpython::
40 :showcode:
42 from pymlbenchmark.context import machine_information
43 import numpy
44 import pandas
45 print(pandas.DataFrame(machine_information(['numpy'])))
46 """
47 res = [
48 {"name": "date", "version": str(datetime.now()).split()[0]},
49 {"name": "python", "value": sys.version},
50 {"name": "platform", "value": sys.platform},
51 {"name": "OS", "value": platform.platform()},
52 {"name": "machine", "value": platform.machine()},
53 {"name": "processor", "value": platform.processor()},
54 {"name": "release", "value": platform.release()},
55 {"name": "architecture", "value": platform.architecture()},
56 ]
57 info = get_cpu_info()
58 for k, v in sorted(info.items()):
59 if k in {'brand_raw', 'count', 'arch', 'processor_type',
60 'hz_advertised', 'stepping',
61 'l1_cache_size', 'l2_cache_size',
62 'l3_cache_size', 'l1_data_cache_size',
63 'l1_instruction_cache_size', 'l2_cache_line_size',
64 'l2_cache_associativity'}:
65 res.append(dict(name=k, value=v))
66 if k == 'flags':
67 res.append(dict(name=k, value=' '.join(v)))
68 if pkgs is not None:
69 for name in sorted(pkgs):
70 if name in sys.modules:
71 mod = sys.modules[name]
72 obs = dict(name=name, version=getattr(
73 mod, '__version__', 'not-found'))
74 if name == "onnxruntime":
75 obs['value'] = mod.get_device()
76 elif name == 'numpy':
77 sinfo = get_numpy_info()
78 info = []
79 for sub in ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'openblas',
80 "language = c"]:
81 if sub in sinfo:
82 info.append(sub.replace(' ', ''))
83 obs['value'] = ", ".join(info)
84 elif name == "onnx":
85 from mlprodict import __max_supported_opset__ # pylint: disable=C0415
86 obs['value'] = "opset={}".format(
87 __max_supported_opset__)
88 res.append(obs)
89 else:
90 res.append(dict(name=name, version='not-imported'))
91 return res