iwopy 0.1.8__py3-none-any.whl → 0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of iwopy might be problematic. Click here for more details.

Files changed (43) hide show
  1. iwopy/VERSION +1 -1
  2. iwopy/__init__.py +12 -2
  3. iwopy/benchmarks/branin/__init__.py +1 -0
  4. iwopy/benchmarks/{branin.py → branin/branin.py} +29 -19
  5. iwopy/benchmarks/rosenbrock/__init__.py +1 -0
  6. iwopy/benchmarks/{rosenbrock.py → rosenbrock/rosenbrock.py} +35 -27
  7. iwopy/core/base.py +14 -8
  8. iwopy/core/constraint.py +20 -14
  9. iwopy/core/function.py +66 -60
  10. iwopy/core/function_list.py +51 -45
  11. iwopy/core/function_subset.py +33 -28
  12. iwopy/core/memory.py +43 -35
  13. iwopy/core/objective.py +4 -1
  14. iwopy/core/opt_results.py +79 -68
  15. iwopy/core/optimizer.py +15 -9
  16. iwopy/core/problem.py +116 -104
  17. iwopy/interfaces/pygmo/__init__.py +3 -0
  18. iwopy/interfaces/pygmo/algos.py +5 -2
  19. iwopy/interfaces/pygmo/imports.py +11 -0
  20. iwopy/interfaces/pygmo/optimizer.py +24 -18
  21. iwopy/interfaces/pygmo/problem.py +24 -19
  22. iwopy/interfaces/pymoo/__init__.py +4 -1
  23. iwopy/interfaces/pymoo/factory.py +6 -0
  24. iwopy/interfaces/pymoo/imports.py +11 -0
  25. iwopy/interfaces/pymoo/optimizer.py +75 -48
  26. iwopy/interfaces/pymoo/problem.py +330 -314
  27. iwopy/interfaces/scipy/optimizer.py +26 -20
  28. iwopy/optimizers/gg.py +41 -35
  29. iwopy/utils/discretization.py +107 -101
  30. iwopy/utils/stdout.py +2 -0
  31. iwopy/wrappers/discretize_reg_grid.py +65 -59
  32. iwopy/wrappers/local_fd.py +40 -34
  33. iwopy/wrappers/problem_wrapper.py +43 -37
  34. iwopy/wrappers/simple_constraint.py +47 -41
  35. iwopy/wrappers/simple_objective.py +42 -36
  36. iwopy/wrappers/simple_problem.py +40 -34
  37. {iwopy-0.1.8.dist-info → iwopy-0.2.dist-info}/METADATA +27 -4
  38. iwopy-0.2.dist-info/RECORD +50 -0
  39. iwopy-0.1.8.dist-info/RECORD +0 -48
  40. {iwopy-0.1.8.dist-info → iwopy-0.2.dist-info}/LICENSE +0 -0
  41. {iwopy-0.1.8.dist-info → iwopy-0.2.dist-info}/WHEEL +0 -0
  42. {iwopy-0.1.8.dist-info → iwopy-0.2.dist-info}/top_level.txt +0 -0
  43. {iwopy-0.1.8.dist-info → iwopy-0.2.dist-info}/zip-safe +0 -0
iwopy/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.2
iwopy/__init__.py CHANGED
@@ -1,3 +1,8 @@
1
+ """
2
+ Fraunhofer IWES optimization tools in Python
3
+
4
+ """
5
+
1
6
  from .core import Problem, Objective, Constraint, Memory
2
7
  from .wrappers import (
3
8
  ProblemWrapper,
@@ -13,6 +18,11 @@ from . import interfaces
13
18
  from . import benchmarks
14
19
  from . import optimizers
15
20
 
16
- from importlib.resources import read_text
21
+ try:
22
+ from importlib.resources import files
23
+
24
+ __version__ = files(__package__).joinpath("VERSION").read_text()
25
+ except ImportError:
26
+ from importlib.resources import read_text
17
27
 
18
- __version__ = read_text(__package__, "VERSION")
28
+ __version__ = read_text(__package__, "VERSION")
@@ -0,0 +1 @@
1
+ from .branin import BraninObjective, BraninProblem
@@ -31,21 +31,26 @@ class BraninObjective(SimpleObjective):
31
31
 
32
32
  f(x,y) = 0.397887
33
33
 
34
- Parameters
35
- ----------
36
- problem: iwopy.Problem
37
- The underlying optimization problem
38
- ana_deriv : bool
39
- Switch for analytical derivatives
40
- name: str
41
- The function name
34
+ :group: benchmarks.branin
42
35
 
43
36
  """
44
37
 
45
38
  def __init__(self, problem, ana_deriv=False, name="f"):
39
+ """
40
+ Constructor
41
+
42
+ Parameters
43
+ ----------
44
+ problem: iwopy.Problem
45
+ The underlying optimization problem
46
+ ana_deriv: bool
47
+ Switch for analytical derivatives
48
+ name: str
49
+ The function name
50
+
51
+ """
46
52
  super().__init__(problem, name, n_components=1, has_ana_derivs=ana_deriv)
47
53
 
48
- # Parameters of branin function,
49
54
  # (a, b, c, r, s, t)
50
55
  self._pars = (
51
56
  1,
@@ -82,24 +87,29 @@ class BraninProblem(SimpleProblem):
82
87
  """
83
88
  Problem definition of benchmark function Branin.
84
89
 
85
- Parameters
86
- ----------
87
- name : str
88
- The name of the problem
89
- ana_deriv : bool
90
- Switch for analytical derivatives
91
- initial_values : list of float
92
- The initial values
93
-
94
90
  Attributes
95
91
  ----------
96
- initial_values : list of float
92
+ initial_values: list of float
97
93
  The initial values
98
94
 
95
+ :group: benchmarks.branin
96
+
99
97
  """
100
98
 
101
99
  def __init__(self, name="branin", initial_values=[1.0, 1.0], ana_deriv=False):
100
+ """
101
+ Constructor
102
+
103
+ Parameters
104
+ ----------
105
+ name: str
106
+ The name of the problem
107
+ ana_deriv: bool
108
+ Switch for analytical derivatives
109
+ initial_values: list of float
110
+ The initial values
102
111
 
112
+ """
103
113
  super().__init__(
104
114
  name,
105
115
  float_vars={"x": initial_values[0], "y": initial_values[1]},
@@ -0,0 +1 @@
1
+ from .rosenbrock import RosenbrockObjective, RosenbrockProblem
@@ -1,5 +1,3 @@
1
- import numpy as np
2
-
3
1
  from iwopy import SimpleProblem, SimpleObjective
4
2
 
5
3
 
@@ -25,16 +23,7 @@ class RosenbrockObjective(SimpleObjective):
25
23
 
26
24
  f(x,y) = 0
27
25
 
28
- Parameters
29
- ----------
30
- problem : iwopy.Problem
31
- The underlying optimization problem
32
- pars : tuple
33
- The a, b parameters
34
- ana_deriv : bool
35
- Switch for analytical derivatives
36
- name : str
37
- The function name
26
+ :group: benchmarks.rosenbrock
38
27
 
39
28
  """
40
29
 
@@ -45,9 +34,23 @@ class RosenbrockObjective(SimpleObjective):
45
34
  ana_deriv=False,
46
35
  name="f",
47
36
  ):
37
+ """
38
+ Construtor
39
+
40
+ Parameters
41
+ ----------
42
+ problem: iwopy.Problem
43
+ The underlying optimization problem
44
+ pars: tuple
45
+ The a, b parameters
46
+ ana_deriv: bool
47
+ Switch for analytical derivatives
48
+ name: str
49
+ The function name
50
+
51
+ """
48
52
  super().__init__(problem, name, n_components=1, has_ana_derivs=ana_deriv)
49
53
 
50
- # Parameters of branin function,
51
54
  # (a, b)
52
55
  self._pars = pars
53
56
 
@@ -73,24 +76,13 @@ class RosenbrockProblem(SimpleProblem):
73
76
  """
74
77
  Problem definition of benchmark function Rosenbrock.
75
78
 
76
- Parameters
77
- ----------
78
- lower : list of float
79
- The minimal variable values
80
- upper : list of float
81
- The maximal variable values
82
- initial : list of float
83
- The initial values
84
- ana_deriv : bool
85
- Switch for analytical derivatives
86
- name : str
87
- The name of the problem
88
-
89
79
  Attributes
90
80
  ----------
91
- initial_values : list of float
81
+ initial_values: list of float
92
82
  The initial values
93
83
 
84
+ :group: benchmarks.rosenbrock
85
+
94
86
  """
95
87
 
96
88
  def __init__(
@@ -101,7 +93,23 @@ class RosenbrockProblem(SimpleProblem):
101
93
  ana_deriv=False,
102
94
  name="rosenbrock",
103
95
  ):
96
+ """
97
+ Constructor
98
+
99
+ Parameters
100
+ ----------
101
+ lower: list of float
102
+ The minimal variable values
103
+ upper: list of float
104
+ The maximal variable values
105
+ initial: list of float
106
+ The initial values
107
+ ana_deriv: bool
108
+ Switch for analytical derivatives
109
+ name: str
110
+ The name of the problem
104
111
 
112
+ """
105
113
  super().__init__(
106
114
  name,
107
115
  float_vars={"x": initial[0], "y": initial[1]},
iwopy/core/base.py CHANGED
@@ -2,19 +2,25 @@ class Base:
2
2
  """
3
3
  Generic base for various iwopy objects.
4
4
 
5
- Parameters
6
- ----------
7
- name : str
8
- The name
9
-
10
5
  Attributes
11
6
  ----------
12
- name : str
7
+ name: str
13
8
  The name
14
9
 
10
+ :group: core
11
+
15
12
  """
16
13
 
17
14
  def __init__(self, name):
15
+ """
16
+ Constructor
17
+
18
+ Parameters
19
+ ----------
20
+ name: str
21
+ The name
22
+
23
+ """
18
24
  self.name = name
19
25
  self._initialized = False
20
26
  if name is None:
@@ -53,7 +59,7 @@ class Base:
53
59
 
54
60
  Parameters
55
61
  ----------
56
- verbosity : int
62
+ verbosity: int
57
63
  The verbosity level, 0 = silent
58
64
 
59
65
  """
@@ -65,7 +71,7 @@ class Base:
65
71
 
66
72
  Parameters
67
73
  ----------
68
- verbosity : int
74
+ verbosity: int
69
75
  The verbosity level, 0 = silent
70
76
 
71
77
  """
iwopy/core/constraint.py CHANGED
@@ -8,19 +8,25 @@ class Constraint(OptFunction):
8
8
  Abstract base class for optimization
9
9
  constraints.
10
10
 
11
- Parameters
12
- ----------
13
- tol : float
14
- The tolerance for constraint violations
15
-
16
11
  Attributes
17
12
  ----------
18
- tol : float
13
+ tol: float
19
14
  The tolerance for constraint violations
20
15
 
16
+ :group: core
17
+
21
18
  """
22
19
 
23
20
  def __init__(self, *args, tol=1e-5, **kwargs):
21
+ """
22
+ Constructor
23
+
24
+ Parameters
25
+ ----------
26
+ tol: float
27
+ The tolerance for constraint violations
28
+
29
+ """
24
30
  super().__init__(*args, **kwargs)
25
31
  self.tol = tol
26
32
 
@@ -32,9 +38,9 @@ class Constraint(OptFunction):
32
38
 
33
39
  Returns
34
40
  -------
35
- min : np.array
41
+ min: np.array
36
42
  The lower bounds, shape: (n_components,)
37
- max : np.array
43
+ max: np.array
38
44
  The upper bounds, shape: (n_components,)
39
45
 
40
46
  """
@@ -50,13 +56,13 @@ class Constraint(OptFunction):
50
56
 
51
57
  Parameters
52
58
  ----------
53
- constraint_values : np.array
59
+ constraint_values: np.array
54
60
  The constraint values, shape: (n_components,)
55
- verbosity : int
61
+ verbosity: int
56
62
  The verbosity level, 0 = silent
57
63
 
58
64
  Returns
59
- values : np.array
65
+ values: np.array
60
66
  -------
61
67
  The boolean result, shape: (n_components,)
62
68
 
@@ -82,14 +88,14 @@ class Constraint(OptFunction):
82
88
 
83
89
  Parameters
84
90
  ----------
85
- constraint_values : np.array
91
+ constraint_values: np.array
86
92
  The constraint values, shape: (n_pop, n_components,)
87
- verbosity : int
93
+ verbosity: int
88
94
  The verbosity level, 0 = silent
89
95
 
90
96
  Returns
91
97
  -------
92
- values : np.array
98
+ values: np.array
93
99
  The boolean result, shape: (n_pop, n_components)
94
100
 
95
101
  """
iwopy/core/function.py CHANGED
@@ -10,36 +10,13 @@ class OptFunction(Base, metaclass=ABCMeta):
10
10
  Abstract base class for functions
11
11
  that calculate scalars based on a problem.
12
12
 
13
- Parameters
14
- ----------
15
- problem: iwopy.Problem
16
- The underlying optimization problem
17
- name: str
18
- The function name
19
- n_vars_int : int, optional
20
- The number of integer variables. If not specified
21
- it is assumed that the function depends on all
22
- problem int variables
23
- n_vars_float : int, optional
24
- The number of float variables. If not specified
25
- it is assumed that the function depends on all
26
- problem float variables
27
- vnames_int : list of str, optional
28
- The integer variable names. Useful for mapping
29
- function variables to problem variables, otherwise
30
- map by integer or default name
31
- vnames_float : list of str, optional
32
- The float variable names. Useful for mapping
33
- function variables to problem variables, otherwise
34
- map by integer or default name
35
- cnames : list of str, optional
36
- The names of the components
37
-
38
13
  Attributes
39
14
  ----------
40
15
  problem: iwopy.Problem
41
16
  The underlying optimization problem
42
17
 
18
+ :group: core
19
+
43
20
  """
44
21
 
45
22
  def __init__(
@@ -52,6 +29,35 @@ class OptFunction(Base, metaclass=ABCMeta):
52
29
  vnames_float=None,
53
30
  cnames=None,
54
31
  ):
32
+ """
33
+ Constructor
34
+
35
+ Parameters
36
+ ----------
37
+ problem: iwopy.Problem
38
+ The underlying optimization problem
39
+ name: str
40
+ The function name
41
+ n_vars_int: int, optional
42
+ The number of integer variables. If not specified
43
+ it is assumed that the function depends on all
44
+ problem int variables
45
+ n_vars_float: int, optional
46
+ The number of float variables. If not specified
47
+ it is assumed that the function depends on all
48
+ problem float variables
49
+ vnames_int: list of str, optional
50
+ The integer variable names. Useful for mapping
51
+ function variables to problem variables, otherwise
52
+ map by integer or default name
53
+ vnames_float: list of str, optional
54
+ The float variable names. Useful for mapping
55
+ function variables to problem variables, otherwise
56
+ map by integer or default name
57
+ cnames: list of str, optional
58
+ The names of the components
59
+
60
+ """
55
61
  super().__init__(name)
56
62
 
57
63
  self.problem = problem
@@ -97,7 +103,7 @@ class OptFunction(Base, metaclass=ABCMeta):
97
103
 
98
104
  Parameters
99
105
  ----------
100
- verbosity : int
106
+ verbosity: int
101
107
  The verbosity level, 0 = silent
102
108
 
103
109
  """
@@ -124,7 +130,7 @@ class OptFunction(Base, metaclass=ABCMeta):
124
130
 
125
131
  Returns
126
132
  -------
127
- names : list of str
133
+ names: list of str
128
134
  The component names
129
135
 
130
136
  """
@@ -137,7 +143,7 @@ class OptFunction(Base, metaclass=ABCMeta):
137
143
 
138
144
  Returns
139
145
  -------
140
- names : list of str
146
+ names: list of str
141
147
  The integer variable names
142
148
 
143
149
  """
@@ -150,7 +156,7 @@ class OptFunction(Base, metaclass=ABCMeta):
150
156
 
151
157
  Returns
152
158
  -------
153
- n : int
159
+ n: int
154
160
  The number of int variables
155
161
 
156
162
  """
@@ -163,7 +169,7 @@ class OptFunction(Base, metaclass=ABCMeta):
163
169
 
164
170
  Returns
165
171
  -------
166
- names : list of str
172
+ names: list of str
167
173
  The float variable names
168
174
 
169
175
  """
@@ -176,7 +182,7 @@ class OptFunction(Base, metaclass=ABCMeta):
176
182
 
177
183
  Returns
178
184
  -------
179
- n : int
185
+ n: int
180
186
  The number of float variables
181
187
 
182
188
  """
@@ -189,7 +195,7 @@ class OptFunction(Base, metaclass=ABCMeta):
189
195
 
190
196
  Returns
191
197
  -------
192
- deps : numpy.ndarray of bool
198
+ deps: numpy.ndarray of bool
193
199
  The dependencies of components on function
194
200
  variables, shape: (n_components, n_vars_int)
195
201
 
@@ -203,7 +209,7 @@ class OptFunction(Base, metaclass=ABCMeta):
203
209
 
204
210
  Returns
205
211
  -------
206
- deps : numpy.ndarray of bool
212
+ deps: numpy.ndarray of bool
207
213
  The dependencies of components on function
208
214
  variables, shape: (n_components, n_vars_float)
209
215
 
@@ -248,7 +254,7 @@ class OptFunction(Base, metaclass=ABCMeta):
248
254
 
249
255
  Parameters
250
256
  ----------
251
- varmap : dict
257
+ varmap: dict
252
258
  The name mapping. Key: old name str,
253
259
  Value: new name str
254
260
 
@@ -261,7 +267,7 @@ class OptFunction(Base, metaclass=ABCMeta):
261
267
 
262
268
  Parameters
263
269
  ----------
264
- varmap : dict
270
+ varmap: dict
265
271
  The name mapping. Key: old name str,
266
272
  Value: new name str
267
273
 
@@ -275,19 +281,19 @@ class OptFunction(Base, metaclass=ABCMeta):
275
281
 
276
282
  Parameters
277
283
  ----------
278
- vars_int : np.array
284
+ vars_int: np.array
279
285
  The integer variable values, shape: (n_vars_int,)
280
- vars_float : np.array
286
+ vars_float: np.array
281
287
  The float variable values, shape: (n_vars_float,)
282
- problem_results : Any
288
+ problem_results: Any
283
289
  The results of the variable application
284
290
  to the problem
285
- components : list of int, optional
291
+ components: list of int, optional
286
292
  The selected components or None for all
287
293
 
288
294
  Returns
289
295
  -------
290
- values : np.array
296
+ values: np.array
291
297
  The component values, shape: (n_sel_components,)
292
298
 
293
299
  """
@@ -299,19 +305,19 @@ class OptFunction(Base, metaclass=ABCMeta):
299
305
 
300
306
  Parameters
301
307
  ----------
302
- vars_int : np.array
308
+ vars_int: np.array
303
309
  The integer variable values, shape: (n_pop, n_vars_int)
304
- vars_float : np.array
310
+ vars_float: np.array
305
311
  The float variable values, shape: (n_pop, n_vars_float)
306
- problem_results : Any
312
+ problem_results: Any
307
313
  The results of the variable application
308
314
  to the problem
309
- components : list of int, optional
315
+ components: list of int, optional
310
316
  The selected components or None for all
311
317
 
312
318
  Returns
313
319
  -------
314
- values : np.array
320
+ values: np.array
315
321
  The component values, shape: (n_pop, n_sel_components)
316
322
 
317
323
  """
@@ -340,19 +346,19 @@ class OptFunction(Base, metaclass=ABCMeta):
340
346
 
341
347
  Parameters
342
348
  ----------
343
- vars_int : np.array
349
+ vars_int: np.array
344
350
  The optimal integer variable values, shape: (n_vars_int,)
345
- vars_float : np.array
351
+ vars_float: np.array
346
352
  The optimal float variable values, shape: (n_vars_float,)
347
- problem_results : Any
353
+ problem_results: Any
348
354
  The results of the variable application
349
355
  to the problem
350
- verbosity : int
356
+ verbosity: int
351
357
  The verbosity level, 0 = silent
352
358
 
353
359
  Returns
354
360
  -------
355
- values : np.array
361
+ values: np.array
356
362
  The component values, shape: (n_components,)
357
363
 
358
364
  """
@@ -364,21 +370,21 @@ class OptFunction(Base, metaclass=ABCMeta):
364
370
 
365
371
  Parameters
366
372
  ----------
367
- vars_int : np.array
373
+ vars_int: np.array
368
374
  The integer variable values of the final
369
375
  generation, shape: (n_pop, n_vars_int)
370
- vars_float : np.array
376
+ vars_float: np.array
371
377
  The float variable values of the final
372
378
  generation, shape: (n_pop, n_vars_float)
373
- problem_results : Any
379
+ problem_results: Any
374
380
  The results of the variable application
375
381
  to the problem
376
- verbosity : int
382
+ verbosity: int
377
383
  The verbosity level, 0 = silent
378
384
 
379
385
  Returns
380
386
  -------
381
- values : np.array
387
+ values: np.array
382
388
  The component values, shape: (n_pop, n_components)
383
389
 
384
390
  """
@@ -392,18 +398,18 @@ class OptFunction(Base, metaclass=ABCMeta):
392
398
 
393
399
  Parameters
394
400
  ----------
395
- vars_int : np.array
401
+ vars_int: np.array
396
402
  The integer variable values, shape: (n_vars_int,)
397
- vars_float : np.array
403
+ vars_float: np.array
398
404
  The float variable values, shape: (n_vars_float,)
399
- var : int
405
+ var: int
400
406
  The index of the differentiation float variable
401
- components : list of int
407
+ components: list of int
402
408
  The selected components, or None for all
403
409
 
404
410
  Returns
405
411
  -------
406
- deriv : numpy.ndarray
412
+ deriv: numpy.ndarray
407
413
  The derivative values, shape: (n_sel_components,)
408
414
 
409
415
  """