Skip to content

Commit be7cbd7

Browse files
authored
Print host_info in CI without needing NumPy (#9274)
1 parent d8fabe2 commit be7cbd7

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,8 @@ jobs:
221221
run: echo "DASK_DISTRIBUTED__SCHEDULER__WORKER_SATURATION=inf" >> $GITHUB_ENV
222222

223223
- name: Print host info
224-
# host_info.py imports numpy, which isn't a direct dependency of distributed
225-
if: matrix.environment != 'mindeps'
226224
shell: bash -l {0}
227-
run: |
228-
python continuous_integration/scripts/host_info.py
225+
run: python continuous_integration/scripts/host_info.py
229226

230227
- name: Test
231228
id: run_tests

continuous_integration/scripts/host_info.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
1-
from __future__ import annotations
1+
import decimal
22

3-
import numpy
43
import psutil
54

65
from dask.utils import format_bytes
76

8-
from distributed.utils import get_ip, get_ipv6, time
7+
from distributed.metrics import monotonic
8+
from distributed.utils import get_ip, get_ipv6
99
from distributed.utils_test import has_ipv6
1010

1111

12-
def bench() -> float:
13-
t0 = time()
14-
i = 0
12+
def bench(deadline: float = 0.1) -> float:
13+
"""Very crude CPU benchmark.
14+
Calculate as many digits of pi as possible within deadline seconds.
15+
Return how many digits were calculated per second.
16+
"""
17+
t0 = monotonic()
18+
digits = 0
19+
precision = 16
1520
while True:
16-
a = numpy.random.random((1000, 1000))
17-
(a @ a.T).sum()
21+
decimal.getcontext().prec = precision
22+
c = decimal.Decimal(426880) * decimal.Decimal(10005).sqrt()
23+
m = 1
24+
l = 13591409
25+
x = 1
26+
k = 6
27+
s = decimal.Decimal(l)
28+
for i in range(1, precision // 14 + 2):
29+
m = (m * (k**3 - 16 * k)) // (i**3)
30+
l += 545140134
31+
x *= -262537412640768000
32+
s += decimal.Decimal(m * l) / x
33+
k += 12
1834

19-
i += 1
20-
t1 = time()
21-
if t1 - t0 > 1:
22-
return i / (t1 - t0)
35+
pi = c / s
36+
digits = max(digits, len(str(pi).replace(".", "")) - 1)
37+
38+
t1 = monotonic()
39+
if t1 - t0 > deadline:
40+
return digits / (t1 - t0)
41+
precision += 10
2342

2443

2544
def main() -> None:

0 commit comments

Comments
 (0)