Skip to content

Commit eef30dc

Browse files
committed
stuff
1 parent 78ddafe commit eef30dc

57 files changed

Lines changed: 1497 additions & 797 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/source/conf.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
#
1313
import os
1414
import sys
15-
sys.path.insert(0, os.path.abspath('../..'))
15+
16+
sys.path.insert(0, os.path.abspath("../.."))
1617

1718
# -- Project information -----------------------------------------------------
1819

19-
project = 'modcma'
20-
copyright = '2020, Jacob de Nobel'
21-
author = 'Jacob de Nobel'
20+
project = "modcma"
21+
copyright = "2020, Jacob de Nobel"
22+
author = "Jacob de Nobel"
2223

2324

2425
# -- General configuration ---------------------------------------------------
@@ -27,21 +28,21 @@
2728
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2829
# ones.
2930
extensions = [
30-
'sphinx.ext.autodoc',
31-
'sphinx.ext.coverage',
32-
'sphinx.ext.napoleon',
33-
'sphinx.ext.autosummary',
34-
'sphinx_automodapi.automodapi',
35-
'sphinx.ext.graphviz',
36-
'sphinx_automodapi.smart_resolver',
37-
'sphinx.ext.intersphinx',
38-
'sphinx_rtd_theme',
31+
"sphinx.ext.autodoc",
32+
"sphinx.ext.coverage",
33+
"sphinx.ext.napoleon",
34+
"sphinx.ext.autosummary",
35+
"sphinx_automodapi.automodapi",
36+
"sphinx.ext.graphviz",
37+
"sphinx_automodapi.smart_resolver",
38+
"sphinx.ext.intersphinx",
39+
"sphinx_rtd_theme",
3940
]
4041
# numpydoc_show_class_members = False
41-
master_doc = 'index'
42+
master_doc = "index"
4243

4344
# Add any paths that contain templates here, relative to this directory.
44-
templates_path = ['_templates']
45+
templates_path = ["_templates"]
4546

4647
# List of patterns, relative to source directory, that match files and
4748
# directories to ignore when looking for source files.
@@ -54,28 +55,27 @@
5455
# The theme to use for HTML and HTML Help pages. See the documentation for
5556
# a list of builtin themes.
5657
#
57-
html_theme = 'sphinx_rtd_theme'
58+
html_theme = "sphinx_rtd_theme"
5859

5960
# Add any paths that contain custom static files (such as style sheets) here,
6061
# relative to this directory. They are copied after the builtin static files,
6162
# so a file named "default.css" will overwrite the builtin "default.css".
6263
# html_static_path = ['_static']
6364

64-
github_url= 'https://github.com/IOHprofiler/ModularCMAES'
65+
github_url = "https://github.com/IOHprofiler/ModularCMAES"
6566
html_theme_options = {
66-
'canonical_url': '',
67-
67+
"canonical_url": "",
6868
# 'analytics_id': 'UA-XXXXXXX-1', # Provided by Google in your dashboard
69-
'logo_only': False,
70-
'display_version': True,
71-
'prev_next_buttons_location': 'bottom',
72-
'style_external_links': False,
69+
"logo_only": False,
70+
"display_version": True,
71+
"prev_next_buttons_location": "bottom",
72+
"style_external_links": False,
7373
# 'vcs_pageview_mode': '',
7474
# 'style_nav_header_background': 'white',
7575
# Toc options
76-
'collapse_navigation': False,
77-
'sticky_navigation': False,
78-
'navigation_depth': 4,
79-
'includehidden': True,
80-
'titles_only': False
76+
"collapse_navigation": False,
77+
"sticky_navigation": False,
78+
"navigation_depth": 4,
79+
"includehidden": True,
80+
"titles_only": False,
8181
}

modcma/__main__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from .modularcmaes import evaluate_bbob
66

7-
87
parser = ArgumentParser(description="Run single function CMAES")
98
parser.add_argument(
109
"-f", "--fid", type=int, help="bbob function id", required=False, default=5
@@ -27,12 +26,8 @@
2726
parser.add_argument("-s", "--seed", type=int, required=False, default=42)
2827
parser.add_argument("-p", "--data_folder", type=str, required=False)
2928
parser.add_argument("-a", "--arguments", nargs="+", required=False)
30-
parser.add_argument(
31-
"-c", "--cpp", required=False, action="store_true", default=False
32-
)
33-
parser.add_argument(
34-
"--plot", required=False, action="store_true", default=False
35-
)
29+
parser.add_argument("-c", "--cpp", required=False, action="store_true", default=False)
30+
parser.add_argument("--plot", required=False, action="store_true", default=False)
3631

3732
args = vars(parser.parse_args())
3833
for arg in args.pop("arguments") or []:

modcma/asktellcmaes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Ask and tell interface to the Modular CMA-ES."""
2+
23
import warnings
34
import typing
45
from collections import deque
@@ -23,6 +24,7 @@ def check_break_conditions(f: typing.Callable) -> typing.Callable:
2324
When any(~AskTellCMAES.break_conditions) == True
2425
2526
"""
27+
2628
@wraps(f)
2729
def inner(self, *args, **kwargs) -> typing.Any:
2830
if any(self.break_conditions):
@@ -140,7 +142,7 @@ def tell(self, xi: np.ndarray, fi: float) -> None:
140142
When the same xi is provided more than once
141143
142144
"""
143-
#pylint: disable=singleton-comparison
145+
# pylint: disable=singleton-comparison
144146
if not self.parameters.population:
145147
raise RuntimeError("Call to tell without calling ask first is prohibited")
146148

@@ -149,15 +151,17 @@ def tell(self, xi: np.ndarray, fi: float) -> None:
149151
raise ValueError("Unkown xi provided")
150152

151153
for index in indices:
152-
if self.parameters.population.f[index] == None: # noqa
154+
if self.parameters.population.f[index] == None: # noqa
153155
self.parameters.population.f[index] = fi
154156
break
155157
else:
156158
warnings.warn("Repeated call to tell with same xi", UserWarning)
157159
self.parameters.population.f[index] = fi
158160

159161
self.parameters.used_budget += 1
160-
if len(self.ask_queue) == 0 and (self.parameters.population.f != None).all(): # noqa
162+
if (
163+
len(self.ask_queue) == 0 and (self.parameters.population.f != None).all()
164+
): # noqa
161165
self.select()
162166
self.recombine()
163167
self.parameters.adapt()

modcma/c_maes/__init__.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
es, # pyright: ignore[reportMissingModuleSource]
3131
)
3232

33-
from .cmaescpp.parameters import ( # pyright: ignore[reportMissingModuleSource]
33+
from .cmaescpp.parameters import ( # pyright: ignore[reportMissingModuleSource]
3434
Settings,
3535
Modules,
3636
) # pyright: ignore[reportMissingModuleSource]
@@ -47,8 +47,7 @@ def _get_module_options(name: str) -> tuple:
4747
module_class = default_value.__class__
4848
if issubclass(module_class, Enum):
4949
other_values = [
50-
x.name for x in module_class.__members__.values()
51-
if x is not default_value
50+
x.name for x in module_class.__members__.values() if x is not default_value
5251
]
5352
return tuple([default_value.name] + other_values)
5453
raise TypeError(f"{name} has a unparsable type {type(default_value)}")
@@ -85,10 +84,10 @@ def _make_numeric_parameter(
8584

8685

8786
def get_configspace(
88-
dim: int = None,
89-
add_popsize: bool = True,
90-
add_sigma: bool = True,
91-
add_learning_rates: bool = True
87+
dim: int = None,
88+
add_popsize: bool = True,
89+
add_sigma: bool = True,
90+
add_learning_rates: bool = True,
9291
) -> ConfigurationSpace:
9392
cspace = ConfigurationSpace()
9493
for name, options in get_all_module_options().items():
@@ -105,17 +104,17 @@ def get_configspace(
105104
cspace.add(_make_numeric_parameter("lambda0", dim, 1, 50 * dim))
106105
cspace.add(_make_numeric_parameter("mu0", dim, 1, 50 * dim))
107106
cspace.add(ForbiddenGreaterThanRelation(cspace["mu0"], cspace["lambda0"]))
108-
107+
109108
if add_sigma:
110109
cspace.add(_make_numeric_parameter("sigma0", dim, 1e-15, 1e15))
111-
110+
112111
if add_learning_rates:
113112
cspace.add(_make_numeric_parameter("cs", dim, 0, 1.0))
114113
cspace.add(_make_numeric_parameter("cc", dim, 0, 1.0))
115114
cspace.add(_make_numeric_parameter("cmu", dim, 0, 1.0))
116115
cspace.add(_make_numeric_parameter("c1", dim, 0, 1.0))
117116
cspace.add(_make_numeric_parameter("damps", dim, 0, 10.0))
118-
117+
119118
return cspace
120119

121120

@@ -126,7 +125,7 @@ def set_module(modules: Modules, name: str, value: Enum) -> bool:
126125
value = getattr(attr_class, value)
127126
setattr(modules, name, value)
128127
return True
129-
return False
128+
return False
130129

131130

132131
def settings_from_dict(dim: int, **config: dict) -> Settings:
@@ -140,11 +139,7 @@ def settings_from_dict(dim: int, **config: dict) -> Settings:
140139
return settings
141140

142141

143-
def settings_from_config(
144-
dim: int,
145-
config: Configuration,
146-
**kwargs
147-
) -> Settings:
142+
def settings_from_config(dim: int, config: Configuration, **kwargs) -> Settings:
148143
via_settings = kwargs
149144
default_config = get_configspace(dim).get_default_configuration()
150145
modules = Modules()
@@ -157,14 +152,15 @@ def settings_from_config(
157152
settings = Settings(dim, modules, **via_settings)
158153
return settings
159154

155+
160156
def fmin(func: callable, x0: np.ndarray, sigma0: float, budget: int, **kwargs):
161157
"""Minimize a function using the modular CMA-ES.
162158
163159
Parameters
164160
----------
165161
func: callable
166162
The objective function to be minimized.
167-
x0 np.ndarray:
163+
x0 np.ndarray:
168164
The first solution estimate
169165
sigma0: float
170166
The estimate of the stepsize (rule of thumb: 0.3 * (ub - lb))
@@ -187,9 +183,15 @@ def fmin(func: callable, x0: np.ndarray, sigma0: float, budget: int, **kwargs):
187183
settings = settings_from_dict(len(x0), sigma0=sigma0, budget=budget, **kwargs)
188184
es = ModularCMAES(settings)
189185
es(func)
190-
191-
return es.p.stats.global_best.x, es.p.stats.global_best.y, es.p.stats.evaluations, es
192-
186+
187+
return (
188+
es.p.stats.global_best.x,
189+
es.p.stats.global_best.y,
190+
es.p.stats.evaluations,
191+
es,
192+
)
193+
194+
193195
__all__ = (
194196
"settings_from_config",
195197
"get_configspace",

modcma/c_maes/cmaescpp/__init__.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class constants:
2424
clip_sigma: ClassVar[bool] = ...
2525
def __init__(self, *args, **kwargs) -> None: ...
2626

27-
28-
2927
class Population:
3028
X: numpy.ndarray
3129
Y: numpy.ndarray
@@ -89,7 +87,7 @@ class Parameters:
8987
def start(
9088
self, objective: Callable[[numpy.ndarray[numpy.float64[m, 1]]], float]
9189
) -> None: ...
92-
90+
9391
class ModularCMAES:
9492
@overload
9593
def __init__(self, parameters: Parameters) -> None: ...

modcma/c_maes/cmaescpp/es.pyi

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ class MuCommaLambdaES:
2626
tau: float
2727
tau_i: float
2828
x_min: numpy.ndarray
29-
def __init__(self, d: int, x0: numpy.ndarray, sigma0: float = ..., budget: int = ..., target: float = ..., modules: modcma.c_maes.cmaescpp.parameters.Modules = ...) -> None: ...
29+
def __init__(
30+
self,
31+
d: int,
32+
x0: numpy.ndarray,
33+
sigma0: float = ...,
34+
budget: int = ...,
35+
target: float = ...,
36+
modules: modcma.c_maes.cmaescpp.parameters.Modules = ...,
37+
) -> None: ...
3038
def sample(self, arg0: numpy.ndarray) -> numpy.ndarray: ...
3139
def step(self, arg0: Callable[[numpy.ndarray], float]) -> None: ...
3240
def __call__(self, arg0: Callable[[numpy.ndarray], float]) -> None: ...
@@ -43,7 +51,16 @@ class OnePlusOneES:
4351
t: int
4452
target: float
4553
x: numpy.ndarray
46-
def __init__(self, d: int, x0: numpy.ndarray, f0: float, sigma0: float = ..., budget: int = ..., target: float = ..., modules: modcma.c_maes.cmaescpp.parameters.Modules = ...) -> None: ...
54+
def __init__(
55+
self,
56+
d: int,
57+
x0: numpy.ndarray,
58+
f0: float,
59+
sigma0: float = ...,
60+
budget: int = ...,
61+
target: float = ...,
62+
modules: modcma.c_maes.cmaescpp.parameters.Modules = ...,
63+
) -> None: ...
4764
def sample(self) -> numpy.ndarray: ...
4865
def step(self, arg0: Callable[[numpy.ndarray], float]) -> None: ...
4966
def __call__(self, arg0: Callable[[numpy.ndarray], float]) -> None: ...

0 commit comments

Comments
 (0)