iwopy 0.1.9__py3-none-any.whl → 0.2.3__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.
Files changed (43) hide show
  1. iwopy/VERSION +1 -1
  2. iwopy/__init__.py +6 -1
  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 +106 -100
  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.9.dist-info → iwopy-0.2.3.dist-info}/METADATA +108 -21
  38. iwopy-0.2.3.dist-info/RECORD +50 -0
  39. {iwopy-0.1.9.dist-info → iwopy-0.2.3.dist-info}/WHEEL +1 -1
  40. iwopy-0.1.9.dist-info/RECORD +0 -48
  41. {iwopy-0.1.9.dist-info → iwopy-0.2.3.dist-info}/LICENSE +0 -0
  42. {iwopy-0.1.9.dist-info → iwopy-0.2.3.dist-info}/top_level.txt +0 -0
  43. {iwopy-0.1.9.dist-info → iwopy-0.2.3.dist-info}/zip-safe +0 -0
@@ -7,34 +7,25 @@ class UDP:
7
7
  """
8
8
  Generic Problem to Pygmo UserDefinedProblem adapter
9
9
 
10
- Parameters
11
- ----------
12
- problem : iwopy.Problem
13
- The problem to optimize
14
- c_tol : float
15
- Constraint tolerance
16
- pop : bool
17
- Vectorized fitness computation
18
- verbosity : int
19
- The verbosity level, 0 = silent
20
-
21
10
  Attributes
22
11
  ----------
23
- problem : iwopy.Problem
12
+ problem: iwopy.Problem
24
13
  The problem to optimize
25
- n_vars_all : int
14
+ n_vars_all: int
26
15
  The sum of int and float variable counts
27
- n_fitness : int
16
+ n_fitness: int
28
17
  The sum of objective and constraint counts
29
- c_tol : list of float
18
+ c_tol: list of float
30
19
  Constraint tolerances
31
- values : numpy.ndarray
20
+ values: numpy.ndarray
32
21
  The function values, shape: (n_fitness,)
33
- pop : bool
22
+ pop: bool
34
23
  Vectorized fitness computation
35
- verbosity : int
24
+ verbosity: int
36
25
  The verbosity level, 0 = silent
37
26
 
27
+ :group: interfaces.pygmo
28
+
38
29
  """
39
30
 
40
31
  def __init__(
@@ -43,7 +34,21 @@ class UDP:
43
34
  pop=False,
44
35
  verbosity=0,
45
36
  ):
37
+ """
38
+ Constructor
39
+
40
+ Parameters
41
+ ----------
42
+ problem: iwopy.Problem
43
+ The problem to optimize
44
+ c_tol: float
45
+ Constraint tolerance
46
+ pop: bool
47
+ Vectorized fitness computation
48
+ verbosity: int
49
+ The verbosity level, 0 = silent
46
50
 
51
+ """
47
52
  self.problem = problem
48
53
  self.n_vars_all = problem.n_vars_float + problem.n_vars_int
49
54
  self.n_fitness = problem.n_objectives + problem.n_constraints
@@ -215,7 +220,7 @@ class UDP:
215
220
  ----------
216
221
  pygmo_pop: pygmo.Population
217
222
  The results from the solver
218
- verbosity : int
223
+ verbosity: int
219
224
  The verbosity level, 0 = silent
220
225
 
221
226
  Returns
@@ -1 +1,4 @@
1
- from .optimizer import Optimizer_pymoo
1
+ from .imports import load
2
+ from .factory import Factory
3
+ from .optimizer import Optimizer_pymoo, DefaultCallbackTemplate
4
+ from .optimizer import SingleObjProblemTemplate, MultiObjProblemTemplate
@@ -4,6 +4,9 @@ from . import imports
4
4
  class Factory:
5
5
  """
6
6
  A factory for pymoo components
7
+
8
+ :group: interfaces.pymoo
9
+
7
10
  """
8
11
 
9
12
  def __init__(self, pymoo_problem, verbosity):
@@ -182,6 +185,9 @@ class Factory:
182
185
  return out
183
186
 
184
187
  def get_termination(self, term_pars):
188
+ """
189
+ Termination factory function
190
+ """
185
191
 
186
192
  if isinstance(term_pars, tuple):
187
193
  return term_pars
@@ -27,6 +27,17 @@ loaded = False
27
27
 
28
28
 
29
29
  def load(verbosity=1):
30
+ """
31
+ Loads the pymoo package dynamically
32
+
33
+ Parameters
34
+ ----------
35
+ verbosity: int
36
+ The verbosity level, 0 = silent
37
+
38
+ :group: interfaces.pymoo
39
+
40
+ """
30
41
 
31
42
  global Callback, Problem, Real, Integer, IntegerRandomSampling, FloatRandomSampling
32
43
  global BinaryRandomSampling, PermutationRandomSampling, LatinHypercubeSampling, SBX
@@ -2,74 +2,101 @@ import numpy as np
2
2
  import matplotlib.pyplot as plt
3
3
 
4
4
  from iwopy.core import Optimizer
5
- from .problem import get_single_obj_class, get_multi_obj_class
5
+ from .problem import SingleObjProblemTemplate, MultiObjProblemTemplate
6
6
  from .factory import Factory
7
7
  from . import imports
8
8
 
9
9
 
10
- def get_default_callback_class(verbosity=1):
10
+ class DefaultCallbackTemplate:
11
+ """
12
+ Template for the default callback
11
13
 
12
- imports.load(verbosity)
14
+ :group: interfaces.pymoo
13
15
 
14
- class DefaultCallback(imports.Callback):
15
- def __init__(self):
16
- super().__init__()
17
- self.data["f_best"] = None
18
- self.data["cv_best"] = None
16
+ """
19
17
 
20
- def notify(self, algorithm):
21
- fvals = algorithm.pop.get("F")
22
- cvals = algorithm.pop.get("CV")
23
- n_obj = fvals.shape[1]
24
- n_con = cvals.shape[1]
25
- i = np.argmin(fvals, axis=0)
26
- if self.data["f_best"] is None:
27
- self.data["f_best"] = fvals[None, i, range(n_obj)]
28
- self.data["cv_best"] = cvals[None, i, range(n_con)]
29
- else:
30
- self.data["f_best"] = np.append(
31
- self.data["f_best"], fvals[None, i, range(n_obj)], axis=0
32
- )
33
- self.data["cv_best"] = np.append(
34
- self.data["cv_best"], cvals[None, i, range(n_con)], axis=0
35
- )
18
+ def __init__(self):
19
+ """
20
+ Constructor
21
+ """
22
+ self.data["f_best"] = None
23
+ self.data["cv_best"] = None
24
+
25
+ def notify(self, algorithm):
26
+ fvals = algorithm.pop.get("F")
27
+ cvals = algorithm.pop.get("CV")
28
+ n_obj = fvals.shape[1]
29
+ n_con = cvals.shape[1]
30
+ i = np.argmin(fvals, axis=0)
31
+ if self.data["f_best"] is None:
32
+ self.data["f_best"] = fvals[None, i, range(n_obj)]
33
+ self.data["cv_best"] = cvals[None, i, range(n_con)]
34
+ else:
35
+ self.data["f_best"] = np.append(
36
+ self.data["f_best"], fvals[None, i, range(n_obj)], axis=0
37
+ )
38
+ self.data["cv_best"] = np.append(
39
+ self.data["cv_best"], cvals[None, i, range(n_con)], axis=0
40
+ )
41
+
42
+ @classmethod
43
+ def get_class(cls):
44
+ """
45
+ Creates the class, dynamically derived from pymoo.Callback
46
+ """
47
+ imports.load()
48
+ attrb = {v: d for v, d in cls.__dict__.items()}
49
+ init0 = cls.__init__
50
+
51
+ def init1(self):
52
+ imports.Callback.__init__(self)
53
+ init0(self)
36
54
 
37
- return DefaultCallback
55
+ attrb["__init__"] = init1
56
+ attrb["__doc__"] = "The default callback"
57
+ del attrb["get_class"]
58
+ return type("DefaultCallback", (imports.Callback,), attrb)()
38
59
 
39
60
 
40
61
  class Optimizer_pymoo(Optimizer):
41
62
  """
42
63
  Interface to the pymoo optimization solver.
43
64
 
44
- Parameters
45
- ----------
46
- problem : iwopy.Problem
47
- The problem to optimize
48
- problem_pars : dict
49
- Parameters for the problem
50
- algo_pars : dict
51
- Parameters for the alorithm
52
- setup_pars : dict
53
- Parameters for the calculation setup
54
-
55
65
  Attributes
56
66
  ----------
57
- problem_pars : dict
67
+ problem_pars: dict
58
68
  Parameters for the problem
59
- algo_pars : dict
69
+ algo_pars: dict
60
70
  Parameters for the alorithm
61
- setup_pars : dict
71
+ setup_pars: dict
62
72
  Parameters for the calculation setup
63
- term_pars : dict
73
+ term_pars: dict
64
74
  Parameters for the termination conditions
65
- pymoo_problem : iwopy.interfaces.pymoo.SingleObjProblem
75
+ pymoo_problem: iwopy.interfaces.pymoo.SingleObjProblem
66
76
  The pygmo problem
67
- algo : pygmo.algo
77
+ algo: pygmo.algo
68
78
  The pygmo algorithm
69
79
 
80
+ :group: interfaces.pymoo
81
+
70
82
  """
71
83
 
72
84
  def __init__(self, problem, problem_pars, algo_pars, setup_pars={}, term_pars={}):
85
+ """
86
+ Constructor
87
+
88
+ Parameters
89
+ ----------
90
+ problem: iwopy.Problem
91
+ The problem to optimize
92
+ problem_pars: dict
93
+ Parameters for the problem
94
+ algo_pars: dict
95
+ Parameters for the alorithm
96
+ setup_pars: dict
97
+ Parameters for the calculation setup
98
+
99
+ """
73
100
  super().__init__(problem)
74
101
 
75
102
  self.problem_pars = problem_pars
@@ -124,16 +151,16 @@ class Optimizer_pymoo(Optimizer):
124
151
 
125
152
  Parameters
126
153
  ----------
127
- verbosity : int
154
+ verbosity: int
128
155
  The verbosity level, 0 = silent
129
156
 
130
157
  """
131
158
  if self.problem.n_objectives <= 1:
132
- self.pymoo_problem = get_single_obj_class(verbosity)(
159
+ self.pymoo_problem = SingleObjProblemTemplate.get_class()(
133
160
  self.problem, **self.problem_pars
134
161
  )
135
162
  else:
136
- self.pymoo_problem = get_multi_obj_class(verbosity)(
163
+ self.pymoo_problem = MultiObjProblemTemplate.get_class()(
137
164
  self.problem, **self.problem_pars
138
165
  )
139
166
 
@@ -152,9 +179,9 @@ class Optimizer_pymoo(Optimizer):
152
179
 
153
180
  Parameters
154
181
  ----------
155
- callback : pymoo.Callback, optional
182
+ callback: pymoo.Callback, optional
156
183
  The callback
157
- verbosity : int
184
+ verbosity: int
158
185
  The verbosity level, 0 = silent
159
186
 
160
187
  Returns
@@ -164,7 +191,7 @@ class Optimizer_pymoo(Optimizer):
164
191
 
165
192
  """
166
193
  if callback == "default":
167
- callback = get_default_callback_class(verbosity)()
194
+ callback = DefaultCallbackTemplate.get_class()
168
195
 
169
196
  # check problem initialization:
170
197
  super().solve()