Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Oct 30, 2024
1 parent a4f485c commit 6390f15
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions adaptive_scheduler/_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import abc
import asyncio
import functools
import os
import time
import uuid
Expand Down Expand Up @@ -73,7 +74,7 @@ def shutdown(


class TaskID(NamedTuple):
learner_inded: int
learner_index: int
sequence_index: int


Expand All @@ -97,13 +98,13 @@ def __init__(

def _get(self) -> Any | None:
"""Updates the state of the task and returns the result if the task is finished."""
i_learner, index = self.task_id
learner, fname = self._learner_and_fname(load=False)
idx_learner, idx_data = self.task_id
learner, fname = self._learner_and_fname
if self._state == "FINISHED":
return learner.data[index]
return learner.data[idx_data]

assert self.executor._run_manager is not None
last_load_time = self.executor._run_manager._last_load_time.get(i_learner, 0)
last_load_time = self.executor._run_manager._last_load_time.get(idx_learner, 0)
now = time.monotonic()
time_since_last_load = now - last_load_time
if time_since_last_load < self.min_load_interval:
Expand All @@ -119,10 +120,10 @@ def _get(self) -> Any | None:
self._last_size = size

learner.load(fname)
self.executor._run_manager._last_load_time[i_learner] = now
self.executor._run_manager._last_load_time[idx_learner] = now

if index in learner.data:
result = learner.data[index]
if idx_data in learner.data:
result = learner.data[idx_data]
self.set_result(result)
return result
return None
Expand All @@ -135,14 +136,13 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self.__repr__()

def _learner_and_fname(self, *, load: bool = True) -> tuple[SequenceLearner, str | Path]:
i_learner, _ = self.task_id
@functools.cached_property
def _learner_and_fname(self) -> tuple[SequenceLearner, str | Path]:
idx_learner, _ = self.task_id
run_manager = self.executor._run_manager
assert run_manager is not None
learner: SequenceLearner = run_manager.learners[i_learner] # type: ignore[index]
fname = run_manager.fnames[i_learner]
if load and not learner.done():
learner.load(fname)
learner: SequenceLearner = run_manager.learners[idx_learner] # type: ignore[index]
fname = run_manager.fnames[idx_learner]
return learner, fname

def result(self, timeout: float | None = None) -> Any:
Expand Down

0 comments on commit 6390f15

Please sign in to comment.