Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Epistimio/orion into issue_845
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Delaunay committed Jan 11, 2023
2 parents b0b1798 + 9c81a61 commit ec4e6d2
Show file tree
Hide file tree
Showing 53 changed files with 337 additions and 135 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox (and all extra dependencies)
run: tox -e py-all
run: tox -e py-all -- --color=no
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
pip install tox tox-gh-actions
- name: Test long algorithms with tox
run: tox -e algo -- tests/unittests/algo/long/${{ matrix.algo }}
run: tox -e algo -- tests/unittests/algo/long/${{ matrix.algo }} --color=no

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand All @@ -160,7 +160,7 @@ jobs:
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox -e py
run: tox -e py -- --color=no
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox -e mongodb
run: tox -e mongodb -- --color=no
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down Expand Up @@ -244,7 +244,7 @@ jobs:
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox -e backward-compatibility
run: tox -e backward-compatibility -- --color=no
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ docstring-min-length=-1
function-rgx=^(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,v,ex,Run,_,f,e
good-names=i,j,k,v,ex,Run,_,f,e,X,y,a,b,rv

# Include a hint for the correct naming format with invalid-name
include-naming-hint=no
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ recursive-include dashboard/build *
include tests/requirements.txt
include .pre-commit-config.yaml
include CITATION.bib
include docs/src/_static/logos/orion_logo.ai

# Include examples
recursive-include examples *.md *.py *.pkl *.yaml *.ipynb */requirements.txt
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10340,13 +10340,13 @@ __metadata:
linkType: hard

"json5@npm:^1.0.1":
version: 1.0.1
resolution: "json5@npm:1.0.1"
version: 1.0.2
resolution: "json5@npm:1.0.2"
dependencies:
minimist: ^1.2.0
bin:
json5: lib/cli.js
checksum: e76ea23dbb8fc1348c143da628134a98adf4c5a4e8ea2adaa74a80c455fc2cdf0e2e13e6398ef819bfe92306b610ebb2002668ed9fc1af386d593691ef346fc3
checksum: 866458a8c58a95a49bef3adba929c625e82532bcff1fe93f01d29cb02cac7c3fe1f4b79951b7792c2da9de0b32871a8401a6e3c5b36778ad852bf5b8a61165d7
languageName: node
linkType: hard

Expand Down
Binary file added docs/src/_static/par_dep_thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@
extlinks = {
"scipy.stats": (
"https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.%s.html",
"scipy.stats",
"scipy.stats %s",
),
"plotly": (
"https://plotly.com/python-api-reference/generated/plotly.%s",
"plotly.",
"plotly %s",
),
}

Expand Down
3 changes: 2 additions & 1 deletion docs/src/user/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ Full Example of Global Configuration

.. code-block:: yaml
database:
storage:
database:
host: orion_db.pkl
type: pickleddb
Expand Down
Binary file modified examples/db.pkl
Binary file not shown.
31 changes: 26 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,27 @@
with open("tests/requirements.txt") as f:
tests_require = f.readlines()

packages = [ # Packages must be sorted alphabetically to ease maintenance and merges.
"orion.algo",
"orion.algo.mofa",

# Builtin algo plugins that are built-in
algos = [
"orion.algo.asha",
"orion.algo.axoptimizer",
"orion.algo.bohb",
"orion.algo.dehb",
"orion.algo.evolution_es",
"orion.algo.gridsearch",
"orion.algo.hebo",
"orion.algo.hyperband",
"orion.algo.mofa",
"orion.algo.nevergradoptimizer",
"orion.algo.pbt",
"orion.algo.random",
"orion.algo.tpe",
]

packages = [ # Packages must be sorted alphabetically to ease maintenance and merges.
"orion.algo.base",
"orion.algo.space",
"orion.analysis",
"orion.benchmark",
"orion.client",
Expand Down Expand Up @@ -85,7 +101,11 @@
author="Epistímio",
author_email="xavier.bouthillier@umontreal.ca",
url="/~https://github.com/epistimio/orion",
packages=packages,
packages=packages + algos,
namespace_packages=[
"orion",
"orion.algo",
],
package_dir={"": "src"},
data_files=dashboard_files,
include_package_data=True,
Expand Down Expand Up @@ -128,7 +148,8 @@
"cloudpickle",
"PyYAML",
"pymongo>=3",
"numpy>=1.17",
# Issue #1061 Pending update of hebo
"numpy>=1.17,<1.24",
"scipy",
"gitpython",
"filelock",
Expand Down
9 changes: 9 additions & 0 deletions src/orion/algo/asha/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""ASHA hyperparameter"""

from .asha import ASHA, ASHABracket, compute_budgets

__all__ = [
"ASHA",
"ASHABracket",
"compute_budgets",
]
25 changes: 13 additions & 12 deletions src/orion/algo/asha.py → src/orion/algo/asha/asha.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections import defaultdict
from typing import Sequence

import numpy
import numpy as np

from orion.algo.hyperband import (
Expand Down Expand Up @@ -61,9 +60,9 @@ def compute_budgets(
)
num_brackets = num_rungs

budgets = numpy.logspace(
numpy.log(min_resources) / numpy.log(reduction_factor),
numpy.log(max_resources) / numpy.log(reduction_factor),
budgets = np.logspace(
np.log(min_resources) / np.log(reduction_factor),
np.log(max_resources) / np.log(reduction_factor),
num_rungs,
base=reduction_factor,
)
Expand Down Expand Up @@ -122,7 +121,7 @@ class ASHA(Hyperband):
resource required for optimisation but decreases the bias towards stragglers.
Default: 1
repetitions: int
Number of execution of ASHA. Default is numpy.inf which means to
Number of execution of ASHA. Default is np.inf which means to
run ASHA until no new trials can be suggested.
"""
Expand All @@ -133,7 +132,7 @@ def __init__(
seed: int | Sequence[int] | None = None,
num_rungs: int | None = None,
num_brackets: int = 1,
repetitions: int | float = numpy.inf,
repetitions: int | float = np.inf,
):
super().__init__(space, seed=seed, repetitions=repetitions)

Expand All @@ -147,8 +146,8 @@ def __init__(

if num_rungs is None:
num_rungs = int(
numpy.log(self.max_resources / self.min_resources)
/ numpy.log(self.reduction_factor)
np.log(self.max_resources / self.min_resources)
/ np.log(self.reduction_factor)
+ 1
)

Expand All @@ -166,16 +165,18 @@ def __init__(

self.seed_rng(seed)

# pylint: disable=missing-function-docstring
def compute_bracket_idx(self, num: int) -> np.ndarray:
# pylint: disable=invalid-name
def assign_resources(
n: int, remainings: np.ndarray, totals: np.ndarray
) -> np.ndarray:
if n == 0 or remainings.sum() == 0:
return remainings

ratios = remainings / totals
fractions = numpy.nan_to_num(ratios / ratios.sum(), nan=0)
index = numpy.argmax(fractions)
fractions = np.nan_to_num(ratios / ratios.sum(), nan=0)
index = np.argmax(fractions)
remainings[index] -= 1
n -= 1
if n > 0:
Expand All @@ -184,10 +185,10 @@ def assign_resources(
return remainings

assert self.brackets is not None
remainings = numpy.asarray(
remainings = np.asarray(
[bracket.remainings for bracket in self.brackets], dtype=np.int64
)
totals = numpy.asarray(
totals = np.asarray(
[bracket.rungs[0]["n_trials"] for bracket in self.brackets], dtype=np.int64
)
remainings_after = copy.deepcopy(remainings)
Expand Down
8 changes: 8 additions & 0 deletions src/orion/algo/axoptimizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""AxOptimizer hyperparameter"""

from .axoptimizer import AxOptimizer, import_optional

__all__ = [
"AxOptimizer",
"import_optional",
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ax.service.utils.instantiation import ObjectiveProperties

if import_optional.failed:
# pylint: disable=invalid-name
AxClient = None # noqa: F811
ObjectiveProperties = None # noqa: F811

Expand Down
6 changes: 6 additions & 0 deletions src/orion/algo/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Base module to create new algorithm a instantiate them"""

from .base import BaseAlgorithm, algo_factory
from .registry import Registry

__all__ = ["BaseAlgorithm", "algo_factory", "Registry"]
16 changes: 9 additions & 7 deletions src/orion/algo/base.py → src/orion/algo/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from abc import abstractmethod
from typing import Any

from orion.algo.registry import Registry
from orion.algo.base.registry import Registry
from orion.algo.space import Space
from orion.core.utils import GenericFactory
from orion.core.worker.trial import Trial
Expand Down Expand Up @@ -55,9 +55,9 @@ class BaseAlgorithm:
must declare an algorithm's own parameters (tunable elements which could be set by
configuration). This is done by passing them to `BaseAlgorithm.__init__()` by calling Python's
super with a `Space` object as a positional argument plus algorithm's own parameters as keyword
arguments. The keys of the keyword arguments passed to `BaseAlgorithm.__init__()` are interpreted
as the algorithm's parameter names. So for example, a subclass could be as simple as this
(regarding the logistics, not an actual algorithm's implementation):
arguments. The keys of the keyword arguments passed to `BaseAlgorithm.__init__()` are
interpreted as the algorithm's parameter names. So for example, a subclass could be as simple
as this (regarding the logistics, not an actual algorithm's implementation):
Examples
--------
Expand Down Expand Up @@ -292,6 +292,7 @@ def is_done(self) -> bool:
"""
return self.has_completed_max_trials or self.has_suggested_all_possible_values()

# pylint: disable=invalid-name
def has_suggested_all_possible_values(self) -> bool:
"""Returns True if the algorithm has more trials in its registry than the number of possible
values in the search space.
Expand Down Expand Up @@ -336,7 +337,7 @@ def _is_completed(trial: Trial) -> bool:

return sum(map(_is_completed, self.registry)) >= self.max_trials

# pylint:disable=no-self-use,unused-argument
# pylint: disable=unused-argument
def score(self, trial: Trial) -> float:
"""Allow algorithm to evaluate `trial` based on a prediction about
this parameter set's performance.
Expand All @@ -355,7 +356,7 @@ def score(self, trial: Trial) -> float:
"""
return 0

# pylint:disable=no-self-use,unused-argument
# pylint: disable=unused-argument
def judge(self, trial: Trial, measurements: Any) -> dict | None:
"""Inform an algorithm about online `measurements` of a running trial.
Expand Down Expand Up @@ -400,7 +401,7 @@ def configuration(self) -> dict[str, Any]:
By default, returns a dictionary containing the attributes of `self` which are also
constructor arguments.
"""
dict_form = dict()
dict_form = {}
for attrname in self._param_names:
if attrname.startswith("_"): # Do not log _space or others in conf
continue
Expand All @@ -415,6 +416,7 @@ def space(self) -> Space:

@property
def unwrapped(self):
"""Return the algorithm without transforms"""
return self


Expand Down
Loading

0 comments on commit ec4e6d2

Please sign in to comment.