Skip to content

Commit 8b67af6

Browse files
committed
Drop lockfile requirement
The lockfile requirement is no longer necessary since the drop of pSMAC for parallel SMAC/Auto-sklearn as all parallelism is now controlled by a central Auto-sklearn instance which saves the datamanager and the ensemble targets to disk. As a positive side-effect this removes a potential deadlock in the ensemble builder.
1 parent 61154d6 commit 8b67af6

File tree

3 files changed

+24
-40
lines changed

3 files changed

+24
-40
lines changed

autosklearn/ensemble_builder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def __call__(
148148
result: RunValue,
149149
time_left: float,
150150
):
151-
if result.status in (StatusType.STOP, StatusType.ABORT):
151+
if result.status in (StatusType.STOP, StatusType.ABORT) or smbo._stop:
152152
return
153153
self.build_ensemble(smbo.tae_runner.client)
154154

@@ -598,12 +598,13 @@ def run(
598598
else:
599599
time_left = end_at - current_time
600600

601-
if time_left - time_buffer < 1:
601+
wall_time_in_s = int(time_left - time_buffer)
602+
if wall_time_in_s < 1:
602603
break
603604
context = multiprocessing.get_context(pynisher_context)
604605

605606
safe_ensemble_script = pynisher.enforce_limits(
606-
wall_time_in_s=int(time_left - time_buffer),
607+
wall_time_in_s=wall_time_in_s,
607608
mem_in_mb=self.memory_limit,
608609
logger=self.logger,
609610
context=context,

autosklearn/util/backend.py

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import uuid
88
from typing import Dict, List, Optional, Tuple, Union
99

10-
import lockfile
11-
1210
import numpy as np
1311

1412
from sklearn.pipeline import Pipeline
@@ -258,30 +256,20 @@ def save_targets_ensemble(self, targets: np.ndarray) -> str:
258256
except Exception:
259257
pass
260258

261-
with lockfile.LockFile(filepath):
262-
if os.path.exists(filepath):
263-
with open(filepath, 'rb') as fh:
264-
existing_targets = np.load(fh, allow_pickle=True)
265-
if existing_targets.shape[0] > targets.shape[0] or \
266-
(existing_targets.shape == targets.shape and
267-
np.allclose(existing_targets, targets)):
268-
return filepath
269-
270-
with tempfile.NamedTemporaryFile('wb', dir=os.path.dirname(
271-
filepath), delete=False) as fh_w:
272-
np.save(fh_w, targets.astype(np.float32))
273-
tempname = fh_w.name
259+
with tempfile.NamedTemporaryFile('wb', dir=os.path.dirname(
260+
filepath), delete=False) as fh_w:
261+
np.save(fh_w, targets.astype(np.float32))
262+
tempname = fh_w.name
274263

275-
os.rename(tempname, filepath)
264+
os.rename(tempname, filepath)
276265

277266
return filepath
278267

279268
def load_targets_ensemble(self) -> np.ndarray:
280269
filepath = self._get_targets_ensemble_filename()
281270

282-
with lockfile.LockFile(filepath):
283-
with open(filepath, 'rb') as fh:
284-
targets = np.load(fh, allow_pickle=True)
271+
with open(filepath, 'rb') as fh:
272+
targets = np.load(fh, allow_pickle=True)
285273

286274
return targets
287275

@@ -292,21 +280,18 @@ def save_datamanager(self, datamanager: AbstractDataManager) -> str:
292280
self._make_internals_directory()
293281
filepath = self._get_datamanager_pickle_filename()
294282

295-
with lockfile.LockFile(filepath):
296-
if not os.path.exists(filepath):
297-
with tempfile.NamedTemporaryFile('wb', dir=os.path.dirname(
298-
filepath), delete=False) as fh:
299-
pickle.dump(datamanager, fh, -1)
300-
tempname = fh.name
301-
os.rename(tempname, filepath)
283+
with tempfile.NamedTemporaryFile('wb', dir=os.path.dirname(
284+
filepath), delete=False) as fh:
285+
pickle.dump(datamanager, fh, -1)
286+
tempname = fh.name
287+
os.rename(tempname, filepath)
302288

303289
return filepath
304290

305291
def load_datamanager(self) -> AbstractDataManager:
306292
filepath = self._get_datamanager_pickle_filename()
307-
with lockfile.LockFile(filepath):
308-
with open(filepath, 'rb') as fh:
309-
return pickle.load(fh)
293+
with open(filepath, 'rb') as fh:
294+
return pickle.load(fh)
310295

311296
def get_runs_directory(self) -> str:
312297
return os.path.join(self.internals_directory, 'runs')
@@ -484,10 +469,9 @@ def save_predictions_as_txt(self,
484469
os.rename(tempname, filepath)
485470

486471
def write_txt_file(self, filepath: str, data: str, name: str) -> None:
487-
with lockfile.LockFile(filepath):
488-
with tempfile.NamedTemporaryFile('w', dir=os.path.dirname(
489-
filepath), delete=False) as fh:
490-
fh.write(data)
491-
tempname = fh.name
492-
os.rename(tempname, filepath)
493-
self.logger.debug('Created %s file %s' % (name, filepath))
472+
with tempfile.NamedTemporaryFile('w', dir=os.path.dirname(
473+
filepath), delete=False) as fh:
474+
fh.write(data)
475+
tempname = fh.name
476+
os.rename(tempname, filepath)
477+
self.logger.debug('Created %s file %s' % (name, filepath))

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ scikit-learn>=0.23.0,<0.24
88

99
dask
1010
distributed>=2.2.0
11-
lockfile
1211
pyyaml
1312
pandas>=1.0
1413
liac-arff

0 commit comments

Comments
 (0)