Skip to content

Commit

Permalink
move pid logic to _ask
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Apr 22, 2020
1 parent 2f71937 commit 62e9a41
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions adaptive/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ def do_log(self):

def _ask(self, n):
points = []
for i, _id in enumerate(self._to_retry.keys()):
for i, pid in enumerate(self._to_retry.keys()):
if i == n:
break
point = self._id_to_point[_id]
point = self._id_to_point[pid]
if point not in self.pending_points.values():
points.append(point)

Expand All @@ -187,6 +187,8 @@ def _ask(self, n):
new_points, new_losses = self.learner.ask(n - len(points))
points += new_points
loss_improvements += new_losses
for p in new_points:
self._id_to_point[self._next_id()] = p
return points, loss_improvements

def overhead(self):
Expand Down Expand Up @@ -251,11 +253,6 @@ def _get_futures(self):
fut = self._submit(x)
fut.start_time = start_time
self.pending_points[fut] = x
try:
_id = _key_by_value(self._id_to_point, x) # O(N)
except StopIteration: # `x` is not a value in `self._id_to_point`
_id = self._next_id()
self._id_to_point[_id] = x

# Collect and results and add them to the learner
futures = list(self.pending_points.keys())
Expand Down

0 comments on commit 62e9a41

Please sign in to comment.