Skip to content

Commit 9914168

Browse files
committed
Fix timeouts related to metalearnings tests (#1508)
* Add debug statements and 30s timeouts * Fix formatting * Update internal timeout param * +timeout, use allocated tmpdir * +timeout, use allocated tmpdir * Remove another occurence of explicit `tmp` * Increase timelimits once again * Remove incomplete comment
1 parent 4b40d45 commit 9914168

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ env:
2626
pytest-args: >-
2727
--forked
2828
--durations=20
29-
--timeout=300
29+
--timeout=600
3030
--timeout-method=thread
3131
-s
3232

scripts/03_calculate_metafeatures.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77
import unittest.mock
8+
import tempfile
89

910
import arff
1011
import joblib
@@ -82,10 +83,7 @@ def calculate_metafeatures(task_id):
8283

8384
for task_type in ("classification", "regression"):
8485
output_directory = os.path.join(working_directory, "metafeatures", task_type)
85-
try:
86-
os.makedirs(output_directory)
87-
except:
88-
pass
86+
os.makedirs(output_directory, exist_ok=True)
8987

9088
all_metafeatures = {}
9189

@@ -100,13 +98,10 @@ def calculate_metafeatures(task_id):
10098
tasks = copy.deepcopy(tasks)
10199
np.random.shuffle(tasks)
102100

103-
def producer():
104-
for task_id in tasks:
105-
yield task_id
106-
107-
memory = joblib.Memory(location="/tmp/joblib", verbose=10)
101+
tmpdir = os.path.join(tempfile.gettempdir(), "joblib")
102+
memory = joblib.Memory(location=tmpdir, verbose=10)
108103
cached_calculate_metafeatures = memory.cache(calculate_metafeatures)
109-
mfs = [cached_calculate_metafeatures(task_id) for task_id in producer()]
104+
mfs = [cached_calculate_metafeatures(task_id) for task_id in tasks]
110105

111106
for mf in mfs:
112107
if mf is not None:

test/test_scripts/test_metadata_generation.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import socket
66
import subprocess
7+
import tempfile
78

89
import arff
910
import numpy as np
@@ -15,10 +16,12 @@
1516

1617
class TestMetadataGeneration(unittest.TestCase):
1718
def setUp(self):
18-
self.working_directory = "/tmp/autosklearn-unittest-tmp-dir-%s-%d-%d" % (
19-
socket.gethostname(),
20-
os.getpid(),
21-
random.randint(0, 1000000),
19+
host = socket.gethostname()
20+
pid = os.getpid()
21+
rint = random.randint(0, 1000000)
22+
23+
self.working_directory = os.path.join(
24+
tempfile.gettempdir(), f"autosklearn-unittest-tmp-dir-{host}-{pid}-{rint}"
2225
)
2326

2427
def print_files(self):
@@ -27,7 +30,6 @@ def print_files(self):
2730
print(dirpath, dirnames, filenames)
2831

2932
def test_metadata_generation(self):
30-
3133
regression_task_id = 360029
3234
regression_dataset_name = "SWD".lower()
3335
classification_task_id = 245
@@ -52,10 +54,15 @@ def test_metadata_generation(self):
5254
script_filename,
5355
self.working_directory,
5456
)
57+
5558
return_value = subprocess.run(
56-
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
59+
cmd,
60+
shell=True,
61+
stdout=subprocess.PIPE,
62+
stderr=subprocess.PIPE,
63+
timeout=30,
5764
)
58-
self.assertEqual(return_value.returncode, 0, msg=str(return_value))
65+
self.assertEqual(return_value.returncode, 0, msg=f"{cmd}\n{str(return_value)}")
5966

6067
# 4. run one of the commands to get some data
6168
commands_output_file = os.path.join(
@@ -99,8 +106,13 @@ def test_metadata_generation(self):
99106
# for training. In production, it would use twice as much!
100107
cmd = cmd.replace("-s 1", "-s 1 --unittest")
101108
print("COMMAND: %s" % cmd)
109+
102110
return_value = subprocess.run(
103-
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
111+
cmd,
112+
shell=True,
113+
stdout=subprocess.PIPE,
114+
stderr=subprocess.PIPE,
115+
timeout=180,
104116
)
105117
print("STDOUT: %s" % repr(return_value.stdout), flush=True)
106118
print("STDERR: %s" % repr(return_value.stderr), flush=True)
@@ -124,7 +136,9 @@ def test_metadata_generation(self):
124136
with open(smac_log) as fh:
125137
smac_output = fh.read()
126138
self.assertEqual(
127-
return_value.returncode, 0, msg=str(return_value) + "\n" + smac_output
139+
return_value.returncode,
140+
0,
141+
msg=f"{cmd}\n{str(return_value)}" + "\n" + smac_output,
128142
)
129143
expected_validation_output = os.path.join(
130144
expected_output_directory, "..", "validation_trajectory_1.json"
@@ -174,12 +188,17 @@ def test_metadata_generation(self):
174188
self.working_directory,
175189
)
176190
print("COMMAND: %s" % cmd)
191+
177192
return_value = subprocess.run(
178-
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
193+
cmd,
194+
shell=True,
195+
stdout=subprocess.PIPE,
196+
stderr=subprocess.PIPE,
197+
timeout=60,
179198
)
180199
print("STDOUT: %s" % repr(return_value.stdout), flush=True)
181200
print("STDERR: %s" % repr(return_value.stderr), flush=True)
182-
self.assertEqual(return_value.returncode, 0, msg=str(return_value))
201+
self.assertEqual(return_value.returncode, 0, msg=f"{cmd}\n{str(return_value)}")
183202

184203
for file in [
185204
"algorithm_runs.arff",
@@ -218,9 +237,13 @@ def test_metadata_generation(self):
218237
self.working_directory,
219238
)
220239
return_value = subprocess.run(
221-
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
240+
cmd,
241+
shell=True,
242+
stdout=subprocess.PIPE,
243+
stderr=subprocess.PIPE,
244+
timeout=90,
222245
)
223-
self.assertEqual(return_value.returncode, 0, msg=str(return_value))
246+
self.assertEqual(return_value.returncode, 0, msg=f"{cmd}\n{str(return_value)}")
224247
for task_type in ("classification", "regression"):
225248
for file in [
226249
"calculation_times.csv",
@@ -273,10 +296,15 @@ def test_metadata_generation(self):
273296
script_filename,
274297
self.working_directory,
275298
)
299+
276300
return_value = subprocess.run(
277-
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
301+
cmd,
302+
shell=True,
303+
stdout=subprocess.PIPE,
304+
stderr=subprocess.PIPE,
305+
timeout=45,
278306
)
279-
self.assertEqual(return_value.returncode, 0, msg=str(return_value))
307+
self.assertEqual(return_value.returncode, 0, msg=f"{cmd}\n{str(return_value)}")
280308

281309
for metric_, combination in (
282310
(metric, "%s_binary.classification_dense" % metric),

0 commit comments

Comments
 (0)