Skip to content

Commit

Permalink
Changing experiment.algorithms to experiment.algorithm (#1014)
Browse files Browse the repository at this point in the history
* changing experiment.algorithms to experiment.algorithm

* fixing building_experiment

* changing some more algorithms to algorithm

* fixing experiments variable name forgotten

* sending algorithms in benchmark creation of experiment

* changing algorithms in config files for tests

* change algorithm_name for experiment in benchmark

* exp.configuration had algorithms keys

* study test with algorithms

* add warning and make algorithms still work but deprecated

* Add backward compatibility

* disable too-many-locals for pylint

* fixing line too long

* stop sending None algorithm when there isnt one

* adding algorithms to test

* backward python_api algorithms

* Fixing upgrade for algorithms

* Adding check for setting algorithm or algorithms to None

* setting up instantiated_algorithms if both algorithms are None

* sending only algorithm to Experiment

* instanciated algorithms cannot be None by default

* fixing comment, restarting pipeline

* changing algorithms in docs

* adding check on upgrade algorithm

* verifying pre-commit

* removing algorithms that was added with rebase

* Empty commit to spawn github-actions...

* calling orion db upgrade directly instead of execute

* good import

* rebasing for tests

* fixing some rebased algorithms + rebase

Co-authored-by: Xavier Bouthillier <xavier.bouthillier@umontreal.ca>
Co-authored-by: Simnol <simon-olivier.duguay.1@ens.etsmtl.ca>
  • Loading branch information
3 people authored Jan 20, 2023
1 parent d75c254 commit 47a83fa
Show file tree
Hide file tree
Showing 62 changed files with 350 additions and 313 deletions.
2 changes: 1 addition & 1 deletion docs/src/plugins/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Next we define the file ``bayes.yaml`` as this
experiment:
name: orion-with-bayes
algorithms: BayesianOptimizer
algorithm: BayesianOptimizer
Then call ``orion hunt`` with the configuration file.

Expand Down
32 changes: 16 additions & 16 deletions docs/src/user/algorithms.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _Setup Algorithms:
.. _Setup algorithm:

**********
Algorithms
Expand All @@ -19,7 +19,7 @@ In a Oríon configuration YAML, define:
.. code-block:: yaml
experiment:
algorithms:
algorithm:
gradient_descent:
learning_rate: 0.1
Expand Down Expand Up @@ -51,7 +51,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
random:
seed: null
Expand Down Expand Up @@ -91,7 +91,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
gridsearch:
n_values: 100
Expand Down Expand Up @@ -140,7 +140,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
hyperband:
seed: null
repetitions: 1
Expand Down Expand Up @@ -196,7 +196,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
asha:
seed: null
num_rungs: null
Expand Down Expand Up @@ -235,7 +235,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
bohb:
min_points_in_model: 20
top_n_percent: 15
Expand Down Expand Up @@ -285,7 +285,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
dehb:
seed: null
mutation_factor: 0.5
Expand Down Expand Up @@ -330,7 +330,7 @@ Configuration
experiment:
algorithms:
algorithm:
pbt:
population_size: 50
generations: 10
Expand Down Expand Up @@ -400,7 +400,7 @@ Configuration
experiment:
algorithms:
algorithm:
pb2:
population_size: 50
generations: 10
Expand Down Expand Up @@ -459,7 +459,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
tpe:
seed: null
n_initial_points: 20
Expand Down Expand Up @@ -503,7 +503,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
ax:
seed: 1234
n_initial_trials: 5,
Expand Down Expand Up @@ -573,7 +573,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
EvolutionES:
seed: null
repetitions: 1
Expand Down Expand Up @@ -626,7 +626,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
MOFA:
seed: null
index: 1
Expand Down Expand Up @@ -654,7 +654,7 @@ a library of algorithms for hyperparameter search.
.. code-block:: yaml
experiment:
algorithms:
algorithm:
nevergrad:
seed: null
budget: 1000
Expand Down Expand Up @@ -692,7 +692,7 @@ Configuration
.. code-block:: yaml
experiment:
algorithms:
algorithm:
hebo:
seed: 1234
parameters:
Expand Down
8 changes: 4 additions & 4 deletions docs/src/user/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Full Example of Global Configuration
type: pickleddb
experiment:
algorithms:
algorithm:
random:
seed: None
max_broken: 3
Expand Down Expand Up @@ -205,7 +205,7 @@ Experiment
.. code-block:: yaml
experiment:
algorithms:
algorithm:
random:
seed: None
max_broken: 3
Expand Down Expand Up @@ -320,7 +320,7 @@ working_dir

.. _config_experiment_algorithms:

algorithms
algorithm
~~~~~~~~~~

:Type: dict
Expand All @@ -346,7 +346,7 @@ strategy
:Env var:
:Description:
(DEPRECATED) This argument will be removed in v0.4. Parallel strategies are now handled by
algorithms directly and should be set in algorithm configuration when they support it.
algorithm directly and should be set in algorithm configuration when they support it.

----

Expand Down
2 changes: 1 addition & 1 deletion examples/dask_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def hpo(n_workers=16):
"tol": "loguniform(1e-4, 1e-1, precision=None)",
"class_weight": "choices([None, 'balanced'])",
},
algorithms={"random": {"seed": 1}},
algorithm={"random": {"seed": 1}},
)

with experiment.tmp_executor("dask", n_workers=n_workers):
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/code_1_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def rosenbrock(x, noise=None):
experiment = build_experiment(
"tpe-rosenbrock",
space=space,
algorithms={"tpe": {"n_initial_points": 5}},
algorithm={"tpe": {"n_initial_points": 5}},
storage=storage,
)

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/code_2_hyperband_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def run_hpo():
"weight_decay": "loguniform(1e-10, 1e-2)",
"gamma": "loguniform(0.97, 1)",
},
algorithms={
algorithm={
"hyperband": {
"seed": 1,
"repetitions": 5,
Expand Down
10 changes: 4 additions & 6 deletions src/orion/benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ def get_experiments(self, silent=True):
for _, exp in study.get_experiments():
exp_column = dict()
stats = exp.stats
exp_column["Algorithm"] = list(exp.configuration["algorithms"].keys())[
0
]
exp_column["Algorithm"] = list(exp.configuration["algorithm"].keys())[0]
exp_column["Experiment Name"] = exp.name
exp_column["Number Trial"] = len(exp.fetch_trials())
exp_column["Best Evaluation"] = stats.best_evaluation
Expand Down Expand Up @@ -405,7 +403,7 @@ def setup_experiments(self):
experiment = create_experiment(
experiment_name,
space=space,
algorithms=algorithm.experiment_algorithm,
algorithm=algorithm.experiment_algorithm,
max_trials=max_trials,
storage=self.benchmark.storage,
executor=executor,
Expand All @@ -430,7 +428,7 @@ def status(self):
for _, experiment in self.get_experiments():
trials = experiment.fetch_trials()

algorithm_name = list(experiment.configuration["algorithms"].keys())[0]
algorithm_name = list(experiment.configuration["algorithm"].keys())[0]

if algorithm_tasks.get(algorithm_name, None) is None:
task_state = {
Expand Down Expand Up @@ -482,7 +480,7 @@ def get_experiments(self, algorithms=None):
for repetition_index, experiment in self.experiments_info:
if (
algorithms is None
or list(experiment.algorithms.configuration.keys())[0] in algorithms
or list(experiment.algorithm.configuration.keys())[0] in algorithms
):
exps.append((repetition_index, experiment))
return exps
Expand Down
2 changes: 1 addition & 1 deletion src/orion/benchmark/assessment/averagerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def analysis(self, task, experiments):
algorithm_groups = defaultdict(list)

for _, exp in experiments:
algorithm_name = list(exp.configuration["algorithms"].keys())[0]
algorithm_name = list(exp.configuration["algorithm"].keys())[0]
algorithm_groups[algorithm_name].append(exp)

return {rankings.__name__: rankings(algorithm_groups)}
2 changes: 1 addition & 1 deletion src/orion/benchmark/assessment/averageresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def analysis(self, task, experiments):
algorithm_groups = defaultdict(list)

for _, exp in experiments:
algorithm_name = list(exp.configuration["algorithms"].keys())[0]
algorithm_name = list(exp.configuration["algorithm"].keys())[0]
algorithm_groups[algorithm_name].append(exp)

return {regrets.__name__: regrets(algorithm_groups)}
2 changes: 1 addition & 1 deletion src/orion/benchmark/assessment/parallelassessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def analysis(self, task, experiments):
algorithm_groups = defaultdict(list)
algorithm_worker_groups = defaultdict(list)
for repetition_index, exp in experiments:
algorithm_name = list(exp.configuration["algorithms"].keys())[0]
algorithm_name = list(exp.configuration["algorithm"].keys())[0]
algorithm_groups[algorithm_name].append(exp)

n_worker = self.workers[repetition_index]
Expand Down
13 changes: 9 additions & 4 deletions src/orion/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def build_experiment(
name: str,
version: int | None = None,
space: dict[str, Any] | None = None,
algorithm: type[BaseAlgorithm] | dict | None = None,
algorithms: type[BaseAlgorithm] | dict | None = None,
strategy: str | dict | None = None,
max_trials: int | None = None,
Expand All @@ -81,7 +82,7 @@ def build_experiment(
``name`` and ``space`` arguments are required, otherwise ``NoConfigurationError`` will be
raised.
All other arguments (``algorithms``, ``strategy``, ``max_trials``, ``storage``, ``branching``
All other arguments (``algorithm``, ``strategy``, ``max_trials``, ``storage``, ``branching``
and ``working_dir``) will be replaced by system's defaults if omitted. The system's defaults can
also be overridden in global configuration file as described for the database in
:ref:`Database Configuration`. We do not recommend overriding the algorithm configuration using
Expand Down Expand Up @@ -133,7 +134,7 @@ def build_experiment(
or 1 for new experiment.
space: dict, optional
Optimization space of the algorithm. Should have the form ``dict(name='<prior>(args)')``.
algorithms: str or dict, optional
algorithm: str or dict, optional
Algorithm used for optimization.
strategy: str or dict, optional
Deprecated and will be remove in v0.4. It should now be set in algorithm configuration
Expand Down Expand Up @@ -220,6 +221,7 @@ def build_experiment(
name,
version=version,
space=space,
algorithm=algorithm,
algorithms=algorithms,
max_trials=max_trials,
max_broken=max_broken,
Expand All @@ -235,6 +237,7 @@ def build_experiment(
name,
version=version,
space=space,
algorithm=algorithm,
algorithms=algorithms,
strategy=strategy,
max_trials=max_trials,
Expand Down Expand Up @@ -293,6 +296,7 @@ def workon(
function: Callable,
space: dict,
name: str = "loop",
algorithm: type[BaseAlgorithm] | str | dict | None = None,
algorithms: type[BaseAlgorithm] | str | dict | None = None,
max_trials: int | None = None,
max_broken: int | None = None,
Expand All @@ -302,7 +306,7 @@ def workon(
This will create a new experiment with an in-memory storage and optimize the given function
until `max_trials` is reached or the `algorithm` is done
(some algorithms like random search are never done).
(some algorithm like random search are never done).
For information on how to fetch results, see
:py:class:`orion.client.experiment.ExperimentClient`.
Expand All @@ -320,7 +324,7 @@ def workon(
or 1 for new experiment.
space: dict, optional
Optimization space of the algorithm. Should have the form `dict(name='<prior>(args)')`.
algorithms: str or dict, optional
algorithm: str or dict, optional
Algorithm used for optimization.
max_trials: int, optional
Maximum number or trials before the experiment is considered done.
Expand All @@ -337,6 +341,7 @@ def workon(
name,
version=1,
space=space,
algorithm=algorithm,
algorithms=algorithms,
max_trials=max_trials,
max_broken=max_broken,
Expand Down
10 changes: 5 additions & 5 deletions src/orion/client/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def space(self) -> Space:
return space

@property
def algorithms(self):
"""Algorithms of the experiment."""
return self._experiment.algorithms
def algorithm(self):
"""Algorithm of the experiment."""
return self._experiment.algorithm

@property
def refers(self):
Expand Down Expand Up @@ -807,8 +807,8 @@ def workon(

if self.max_trials > max_trials:
self._experiment.max_trials = max_trials
assert self._experiment.algorithms is not None
self._experiment.algorithms.max_trials = max_trials
assert self._experiment.algorithm is not None
self._experiment.algorithm.max_trials = max_trials

with SetupWorkingDir(self):
runner = Runner(
Expand Down
Loading

0 comments on commit 47a83fa

Please sign in to comment.