-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #631 from bouthilx/hotfix/reserve_parent_trials
Duplicate pending trials from parent/child for exc
- Loading branch information
Showing
10 changed files
with
349 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import contextlib | ||
import copy | ||
|
||
from orion.client import build_experiment, get_experiment | ||
|
||
|
||
@contextlib.contextmanager | ||
def disable_duplication(monkeypatch): | ||
def stub(self): | ||
pass | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr( | ||
"orion.core.worker.experiment.Experiment.duplicate_pending_trials", stub | ||
) | ||
|
||
yield | ||
|
||
|
||
def generate_trials(exp, trials): | ||
"""Generate trials for each item in trials. | ||
Items of trials can be either dictionary of valid hyperparameters based on exp.space and status | ||
or `None`. | ||
If status not provided, 'new' is used by default. | ||
For items that are `None`, trials are suggested with exp.suggest(). | ||
""" | ||
for trial_config in trials: | ||
trial_config = copy.deepcopy(trial_config) | ||
status = trial_config.pop("status", None) if trial_config else None | ||
if trial_config: | ||
trial = exp.insert(params=trial_config) | ||
else: | ||
with exp.suggest() as trial: | ||
# Releases suggested trial when leaving with-clause. | ||
pass | ||
|
||
if status is not None: | ||
print(status) | ||
exp._experiment._storage.set_trial_status(trial, status) | ||
|
||
print([trial.status for trial in exp.fetch_trials()]) | ||
|
||
|
||
def build_root_experiment(space=None, trials=None): | ||
"""Build a root experiment and generate trials.""" | ||
if space is None: | ||
space = {"x": "uniform(0, 100)", "y": "uniform(0, 100)", "z": "uniform(0, 100)"} | ||
if trials is None: | ||
trials = [{"x": i, "y": i * 2, "z": i ** 2} for i in range(4)] | ||
|
||
root = build_experiment(name="root", max_trials=len(trials), space=space) | ||
|
||
generate_trials(root, trials) | ||
|
||
|
||
def build_child_experiment(space=None, trials=None, name="child", parent="root"): | ||
"""Build a child experiment by branching from `parent` and generate trials.""" | ||
if trials is None: | ||
trials = [None for i in range(6)] | ||
|
||
max_trials = get_experiment(parent).max_trials + len(trials) | ||
|
||
child = build_experiment( | ||
name=name, | ||
space=space, | ||
max_trials=max_trials, | ||
branching={"branch_from": parent, "enable": True}, | ||
) | ||
assert child.name == name | ||
assert child.version == 1 | ||
|
||
generate_trials(child, trials) | ||
|
||
|
||
def build_grand_child_experiment(space=None, trials=None): | ||
"""Build a grand-child experiment by branching from `child` and generate trials.""" | ||
if trials is None: | ||
trials = [None for i in range(5)] | ||
|
||
build_child_experiment( | ||
space=space, trials=trials, name="grand-child", parent="child" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.