Skip to content

Commit

Permalink
Merge pull request #686 from bouthilx/feature/rework_suggest_observe
Browse files Browse the repository at this point in the history
Refactor algorithms observe/suggest to work on trial objects directly
  • Loading branch information
bouthilx committed Nov 16, 2021
2 parents bb80d53 + 63eda39 commit c130ddb
Show file tree
Hide file tree
Showing 42 changed files with 1,726 additions and 1,393 deletions.
1 change: 0 additions & 1 deletion docs/src/code/core/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Utilities
utils/format_trials
utils/format_terminal
utils/singleton
utils/points

.. automodule:: orion.core.utils
:members:
5 changes: 0 additions & 5 deletions docs/src/code/core/utils/points.rst

This file was deleted.

5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"tpe = orion.algo.tpe:TPE",
"EvolutionES = orion.algo.evolution_es:EvolutionES",
],
"Database": [
"ephemeraldb = orion.core.io.database.ephemeraldb:EphemeralDB",
"pickleddb = orion.core.io.database.pickleddb:PickledDB",
"mongodb = orion.core.io.database.mongodb:MongoDB",
],
"BaseStorageProtocol": [
"track = orion.storage.track:Track",
"legacy = orion.storage.legacy:Legacy",
Expand Down
42 changes: 26 additions & 16 deletions src/orion/algo/asha.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,31 +218,37 @@ def sample(self, num):
return self.hyperband.sample_for_bracket(num, self)

def get_candidate(self, rung_id):
"""Get a candidate for promotion"""
"""Get a candidate for promotion
Raises
------
TypeError
If get_candidates is called before the entire rung is completed.
"""
rung = self.rungs[rung_id]["results"]
next_rung = self.rungs[rung_id + 1]["results"]

rung = list(
sorted(
(objective, point)
for objective, point in rung.values()
(objective, trial)
for objective, trial in rung.values()
if objective is not None
)
)
k = len(rung) // self.hyperband.reduction_factor
k = min(k, len(rung))

for i in range(k):
point = rung[i][1]
_id = self.hyperband.get_id(point, ignore_fidelity=True)
trial = rung[i][1]
_id = self.hyperband.get_id(trial, ignore_fidelity=True)
if _id not in next_rung:
return point
return trial

return None

@property
def is_filled(self):
"""ASHA's first rung can always sample new points"""
"""ASHA's first rung can always sample new trials"""
return False

def is_ready(self, rung_id=None):
Expand All @@ -254,7 +260,7 @@ def promote(self, num):
The rungs are iterated over in reversed order, so that high rungs
are prioritised for promotions. When a candidate is promoted, the loop is broken and
the method returns the promoted point.
the method returns the promoted trial.
.. note ::
Expand All @@ -272,21 +278,25 @@ def promote(self, num):

# pylint: disable=logging-format-interpolation
logger.debug(
"Promoting {point} from rung {past_rung} with fidelity {past_fidelity} to "
"Promoting {trial} from rung {past_rung} with fidelity {past_fidelity} to "
"rung {new_rung} with fidelity {new_fidelity}".format(
point=candidate,
trial=candidate,
past_rung=rung_id,
past_fidelity=candidate[self.hyperband.fidelity_index],
past_fidelity=candidate.params[self.hyperband.fidelity_index],
new_rung=rung_id + 1,
new_fidelity=self.rungs[rung_id + 1]["resources"],
)
)

candidate = list(copy.deepcopy(candidate))
candidate[self.hyperband.fidelity_index] = self.rungs[rung_id + 1][
"resources"
]
candidate = candidate.branch(
status="new",
params={
self.hyperband.fidelity_index: self.rungs[rung_id + 1][
"resources"
]
},
)

return [tuple(candidate)]
return [candidate]

return []
Loading

0 comments on commit c130ddb

Please sign in to comment.