pymoo 0.6.1.1__cp39-cp39-win_amd64.whl → 0.6.1.2__cp39-cp39-win_amd64.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 pymoo might be problematic. Click here for more details.

Files changed (36) hide show
  1. pymoo/algorithms/moo/age.py +3 -2
  2. pymoo/algorithms/moo/nsga3.py +1 -2
  3. pymoo/algorithms/moo/sms.py +3 -0
  4. pymoo/algorithms/soo/nonconvex/cmaes.py +1 -1
  5. pymoo/algorithms/soo/nonconvex/es.py +1 -1
  6. pymoo/algorithms/soo/nonconvex/optuna.py +1 -4
  7. pymoo/algorithms/soo/nonconvex/pattern.py +1 -1
  8. pymoo/constraints/adaptive.py +2 -2
  9. pymoo/constraints/eps.py +1 -1
  10. pymoo/core/algorithm.py +1 -0
  11. pymoo/core/individual.py +512 -49
  12. pymoo/core/plot.py +1 -1
  13. pymoo/core/result.py +3 -0
  14. pymoo/core/variable.py +310 -16
  15. pymoo/cython/calc_perpendicular_distance.cp39-win_amd64.pyd +0 -0
  16. pymoo/cython/decomposition.cp39-win_amd64.pyd +0 -0
  17. pymoo/cython/hv.cp39-win_amd64.pyd +0 -0
  18. pymoo/cython/info.cp39-win_amd64.pyd +0 -0
  19. pymoo/cython/mnn.cp39-win_amd64.pyd +0 -0
  20. pymoo/cython/non_dominated_sorting.cp39-win_amd64.pyd +0 -0
  21. pymoo/cython/pruning_cd.cp39-win_amd64.pyd +0 -0
  22. pymoo/cython/stochastic_ranking.cp39-win_amd64.pyd +0 -0
  23. pymoo/gradient/__init__.py +3 -1
  24. pymoo/gradient/grad_autograd.py +28 -4
  25. pymoo/util/function_loader.py +31 -21
  26. pymoo/util/nds/dominance_degree_non_dominated_sort.py +159 -0
  27. pymoo/util/ref_dirs/__init__.py +2 -0
  28. pymoo/util/ref_dirs/energy.py +4 -5
  29. pymoo/util/ref_dirs/energy_layer.py +5 -4
  30. pymoo/util/ref_dirs/incremental.py +68 -0
  31. pymoo/version.py +1 -1
  32. {pymoo-0.6.1.1.dist-info → pymoo-0.6.1.2.dist-info}/METADATA +2 -3
  33. {pymoo-0.6.1.1.dist-info → pymoo-0.6.1.2.dist-info}/RECORD +36 -34
  34. {pymoo-0.6.1.1.dist-info → pymoo-0.6.1.2.dist-info}/WHEEL +1 -1
  35. {pymoo-0.6.1.1.dist-info → pymoo-0.6.1.2.dist-info}/LICENSE +0 -0
  36. {pymoo-0.6.1.1.dist-info → pymoo-0.6.1.2.dist-info}/top_level.txt +0 -0
pymoo/core/plot.py CHANGED
@@ -74,7 +74,7 @@ class Plot:
74
74
 
75
75
  # the colormap or the color lists to use
76
76
  if isinstance(cmap, str):
77
- self.cmap = matplotlib.cm.get_cmap(cmap)
77
+ self.cmap = matplotlib.pyplot.get_cmap(cmap)
78
78
  else:
79
79
  self.cmap = cmap
80
80
  if isinstance(self.cmap, ListedColormap):
pymoo/core/result.py CHANGED
@@ -36,6 +36,9 @@ class Result:
36
36
  # the history of the optimization run is they were saved
37
37
  self.history = []
38
38
 
39
+ # data stored within the algorithm
40
+ self.data = None
41
+
39
42
  @property
40
43
  def cv(self):
41
44
  return self.CV[0]
pymoo/core/variable.py CHANGED
@@ -1,88 +1,382 @@
1
+ """
2
+ Module containing infrastructure for representing decision variable classes.
3
+ """
4
+
5
+ # public API for when using ``from pymoo.core.variable import *``
6
+ __all__ = [
7
+ "Variable",
8
+ "BoundedVariable",
9
+ "Real",
10
+ "Integer",
11
+ "Binary",
12
+ "Choice",
13
+ "get",
14
+ ]
15
+
16
+ from typing import Optional, Tuple
17
+ from typing import Union
1
18
  import numpy as np
19
+ from numpy.typing import ArrayLike
2
20
 
3
21
 
4
22
  class Variable(object):
5
-
6
- def __init__(self, value=None, active=True, flag="default") -> None:
23
+ """
24
+ Semi-abstract base class for the representation of a decision variable.
25
+ """
26
+
27
+ def __init__(
28
+ self,
29
+ value: Optional[object] = None,
30
+ active: bool = True,
31
+ flag: str = "default",
32
+ ) -> None:
33
+ """
34
+ Constructor for the ``Variable`` class.
35
+
36
+ Parameters
37
+ ----------
38
+ value : object, None
39
+ Value the decision variable is to take.
40
+ active : bool
41
+ Whether the variable is active (``True``) or inactive (``False``).
42
+ flag : str
43
+ Flag to bind to the decision variable.
44
+ """
7
45
  super().__init__()
8
46
  self.value = value
9
47
  self.flag = flag
10
48
  self.active = active
11
49
 
12
- def sample(self, n=None):
50
+ def sample(
51
+ self,
52
+ n: Optional[int] = None,
53
+ ) -> Union[object,np.ndarray]:
54
+ """
55
+ Randomly sample ``n`` instances of a decision variable.
56
+
57
+ Parameters
58
+ ----------
59
+ n : int, None
60
+ Number of decision variable samples which to draw.
61
+ If ``int``, sample ``n`` decision variables.
62
+ If ``None``, sample a single decision variables.
63
+
64
+ Returns
65
+ -------
66
+ out : object, np.ndarray
67
+ If ``n`` is ``int``, return a ``np.ndarray`` of shape ``(n,)``
68
+ containing sampled decision variables.
69
+ If ``n`` is ``None``, return an ``object`` of a sampled decision
70
+ variable.
71
+ """
13
72
  if n is None:
14
73
  return self._sample(1)[0]
15
74
  else:
16
75
  return self._sample(n)
17
76
 
18
- def _sample(self, n):
77
+ def _sample(
78
+ self,
79
+ n: int,
80
+ ) -> np.ndarray:
81
+ """
82
+ Randomly sample ``n`` instances of a decision variable.
83
+ This is an abstract private method governing the behavior of the
84
+ ``sample`` method.
85
+
86
+ Parameters
87
+ ----------
88
+ n : int
89
+ Number of decision variable samples which to draw.
90
+
91
+ Returns
92
+ -------
93
+ out : np.ndarray
94
+ An array of shape ``(n,)`` containing sampled decision variables.
95
+ """
19
96
  pass
20
97
 
21
- def set(self, value):
98
+ def set(
99
+ self,
100
+ value: object,
101
+ ) -> None:
102
+ """
103
+ Set the value of a decision variable.
104
+
105
+ Parameters
106
+ ----------
107
+ value : object
108
+ Value to assign to the decision variable.
109
+ """
22
110
  self.value = value
23
111
 
24
- def get(self, **kwargs):
112
+ def get(
113
+ self,
114
+ **kwargs: dict
115
+ ) -> object:
116
+ """
117
+ Get the value of a decision variable.
118
+
119
+ Parameters
120
+ ----------
121
+ kwargs : dict
122
+ Additional keyword arguments.
123
+
124
+ Returns
125
+ -------
126
+ out : object
127
+ The value of the decision variable.
128
+ """
25
129
  return self.value
26
130
 
27
131
 
28
132
  class BoundedVariable(Variable):
29
-
30
- def __init__(self, value=None, bounds=(None, None), strict=None, **kwargs) -> None:
133
+ """
134
+ Semi-abstract class for the representation of a bounded decision variable.
135
+ """
136
+
137
+ def __init__(
138
+ self,
139
+ value: Optional[object] = None,
140
+ bounds: Tuple[Optional[object],Optional[object]] = (None, None),
141
+ strict: Optional[Tuple[Optional[object],Optional[object]]] = None,
142
+ **kwargs: dict,
143
+ ) -> None:
144
+ """
145
+ Constructor for the ``BoundedVariable`` class.
146
+
147
+ Parameters
148
+ ----------
149
+ value : object
150
+ Value the decision variable is to take.
151
+ bounds : tuple
152
+ A tuple of length 2 containing upper and lower limits for the
153
+ decision variable.
154
+ strict : tuple, None
155
+ Strict boundaries for the decision variable.
156
+ If ``None``, the value of ``bounds`` is copied to ``strict``.
157
+ kwargs : dict
158
+ Additional keyword arguments for ``active`` and ``flag``.
159
+ """
160
+ # call the Variable constructor
31
161
  super().__init__(value=value, **kwargs)
32
162
  self.bounds = bounds
33
163
 
164
+ # if no strict boundaries were provided, consider ``bounds`` as
165
+ # strict boundaries
34
166
  if strict is None:
35
167
  strict = bounds
36
168
  self.strict = strict
37
169
 
38
170
  @property
39
- def lb(self):
171
+ def lb(self) -> object:
172
+ """
173
+ Lower bound of the decision variable.
174
+
175
+ Returns
176
+ -------
177
+ out : object
178
+ The decision variable lower bound.
179
+ """
40
180
  return self.bounds[0]
41
181
 
42
182
  @property
43
- def ub(self):
183
+ def ub(self) -> object:
184
+ """
185
+ Upper bound of the decision variable.
186
+
187
+ Returns
188
+ -------
189
+ out : object
190
+ The decision variable upper bound.
191
+ """
44
192
  return self.bounds[1]
45
193
 
46
194
 
47
195
  class Real(BoundedVariable):
196
+ """
197
+ Class for the representation of bounded, real decision variables.
198
+ """
199
+ # variable type represented by this object class
48
200
  vtype = float
49
201
 
50
- def _sample(self, n):
202
+ def _sample(
203
+ self,
204
+ n: int,
205
+ ) -> np.ndarray:
206
+ """
207
+ Randomly sample ``n`` instances of a real, bounded decision variable.
208
+ Decision variables are sampled from a uniform distribution.
209
+
210
+ This is a private method governing the behavior of the ``sample``
211
+ method.
212
+
213
+ Parameters
214
+ ----------
215
+ n : int
216
+ Number of decision variable samples which to draw.
217
+
218
+ Returns
219
+ -------
220
+ out : np.ndarray
221
+ An array of shape ``(n,)`` containing sampled real, bounded
222
+ decision variables.
223
+ """
51
224
  low, high = self.bounds
52
225
  return np.random.uniform(low=low, high=high, size=n)
53
226
 
54
227
 
55
228
  class Integer(BoundedVariable):
229
+ """
230
+ Class for the representation of bounded, integer decision variables.
231
+ """
232
+ # variable type represented by this object class
56
233
  vtype = int
57
234
 
58
- def _sample(self, n):
235
+ def _sample(
236
+ self,
237
+ n: int,
238
+ ) -> np.ndarray:
239
+ """
240
+ Randomly sample ``n`` instances of a bounded, integer decision variable.
241
+ Decision variables are sampled from a uniform distribution.
242
+
243
+ This is a private method governing the behavior of the ``sample``
244
+ method.
245
+
246
+ Parameters
247
+ ----------
248
+ n : int
249
+ Number of decision variable samples which to draw.
250
+
251
+ Returns
252
+ -------
253
+ out : np.ndarray
254
+ An array of shape ``(n,)`` containing sampled bounded, integer
255
+ decision variables.
256
+ """
59
257
  low, high = self.bounds
60
258
  return np.random.randint(low, high=high + 1, size=n)
61
259
 
62
260
 
63
261
  class Binary(BoundedVariable):
262
+ """
263
+ Class for the representation of a binary, bounded decision variable.
264
+ """
265
+ # variable type represented by this object class
64
266
  vtype = bool
65
267
 
66
- def _sample(self, n):
268
+ def _sample(
269
+ self,
270
+ n: int,
271
+ ) -> np.ndarray:
272
+ """
273
+ Randomly sample ``n`` instances of a bounded, binary decision variable.
274
+ Decision variables are sampled from a uniform distribution.
275
+
276
+ This is a private method governing the behavior of the ``sample``
277
+ method.
278
+
279
+ Parameters
280
+ ----------
281
+ n : int
282
+ Number of decision variable samples which to draw.
283
+
284
+ Returns
285
+ -------
286
+ out : np.ndarray
287
+ An array of shape ``(n,)`` containing sampled bounded, binary
288
+ decision variables.
289
+ """
67
290
  return np.random.random(size=n) < 0.5
68
291
 
69
292
 
70
293
  class Choice(Variable):
294
+ """
295
+ Class for the representation of a discrete, subset decision variable.
296
+ """
297
+ # variable type represented by this object class
71
298
  vtype = object
72
299
 
73
- def __init__(self, value=None, options=None, all=None, **kwargs) -> None:
300
+ def __init__(
301
+ self,
302
+ value: Optional[object] = None,
303
+ options: Optional[ArrayLike] = None,
304
+ all: Optional[ArrayLike] = None,
305
+ **kwargs: dict,
306
+ ) -> None:
307
+ """
308
+ Constructor for the ``Choice`` class.
309
+
310
+ Parameters
311
+ ----------
312
+ value : object
313
+ Value the decision variable is to take.
314
+ options : ArrayLike, None
315
+ A list of decision variable options from which to choose.
316
+ all : ArrayLike, None
317
+ A strict list of decision variable options from which to choose.
318
+ If ``None``, the value of ``options`` is copied to ``all``.
319
+ kwargs : dict
320
+ Additional keyword arguments for ``active`` and ``flag``.
321
+ """
322
+ # all super constructor
74
323
  super().__init__(value=value, **kwargs)
75
324
  self.options = options
76
325
 
326
+ # if strict list not provided, set to ``options``
77
327
  if all is None:
78
328
  all = options
79
329
  self.all = all
80
330
 
81
- def _sample(self, n):
331
+ def _sample(
332
+ self,
333
+ n: int,
334
+ ) -> np.ndarray:
335
+ """
336
+ Randomly sample ``n`` instances of a discrete, subset decision variable.
337
+ Decision variables are sampled with replacement from a uniform
338
+ distribution.
339
+
340
+ This is a private method governing the behavior of the ``sample``
341
+ method.
342
+
343
+ Parameters
344
+ ----------
345
+ n : int
346
+ Number of decision variable samples which to draw.
347
+
348
+ Returns
349
+ -------
350
+ out : np.ndarray
351
+ An array of shape ``(n,)`` containing sampled bounded, integer
352
+ decision variables.
353
+ """
82
354
  return np.random.choice(self.options, size=n)
83
355
 
84
356
 
85
- def get(*args, size=None, **kwargs):
357
+ def get(
358
+ *args: Tuple[Union[Variable,object],...],
359
+ size: Optional[Union[tuple,int]] = None,
360
+ **kwargs: dict
361
+ ) -> Union[tuple,object,None]:
362
+ """
363
+ Get decision variable values from a tuple of ``Variable`` objects.
364
+
365
+ Parameters
366
+ ----------
367
+ args : tuple
368
+ A tuple of ``Variable`` or ``object``s.
369
+ size : tuple, int, None
370
+ Size to reshape decision variables.
371
+ kwargs : dict
372
+ Additional keyword arguments to pass to the ``get`` method of the
373
+ ``Variable`` class when getting decision variable values.
374
+
375
+ Returns
376
+ -------
377
+ out : tuple, object, None
378
+ Decision variable value(s).
379
+ """
86
380
  if len(args) == 0:
87
381
  return
88
382
 
Binary file
Binary file
Binary file
Binary file
@@ -3,7 +3,7 @@ import importlib
3
3
 
4
4
  GRADIENT_MODULE = "pymoo.gradient.toolbox"
5
5
 
6
- TOOLBOX = "autograd.numpy"
6
+ TOOLBOX = "numpy"
7
7
 
8
8
 
9
9
  def activate(name):
@@ -17,3 +17,5 @@ def activate(name):
17
17
 
18
18
  def deactivate():
19
19
  activate("numpy")
20
+
21
+
@@ -1,9 +1,33 @@
1
1
  import warnings
2
-
3
- import autograd.numpy as anp
4
2
  import numpy as np
5
- from autograd.core import VJPNode, vspace, backward_pass
6
- from autograd.tracer import new_box, isbox
3
+
4
+ try:
5
+ import autograd.numpy as anp
6
+ from autograd import value_and_grad
7
+ from autograd.core import VJPNode, backward_pass
8
+ from autograd.tracer import new_box, isbox
9
+ except:
10
+ print("autograd only supports numpy < 2.0.0 versions.")
11
+
12
+
13
+ def value_and_grad(*args, **kwargs):
14
+ return value_and_grad(*args, **kwargs)
15
+
16
+
17
+ def log(*args, **kwargs):
18
+ return anp.log(*args, **kwargs)
19
+
20
+
21
+ def sqrt(*args, **kwargs):
22
+ return anp.sqrt(*args, **kwargs)
23
+
24
+
25
+ def row_stack(*args, **kwargs):
26
+ return anp.row_stack(*args, **kwargs)
27
+
28
+
29
+ def triu_indices(*args, **kwargs):
30
+ return anp.triu_indices(*args, **kwargs)
7
31
 
8
32
 
9
33
  def run_and_trace(f, x):
@@ -4,10 +4,14 @@ from pymoo.config import Config
4
4
 
5
5
 
6
6
  def get_functions():
7
-
8
7
  from pymoo.util.nds.fast_non_dominated_sort import fast_non_dominated_sort
9
8
  from pymoo.util.nds.efficient_non_dominated_sort import efficient_non_dominated_sort
10
- from pymoo.util.nds.tree_based_non_dominated_sort import tree_based_non_dominated_sort
9
+ from pymoo.util.nds.tree_based_non_dominated_sort import (
10
+ tree_based_non_dominated_sort,
11
+ )
12
+ from pymoo.util.nds.dominance_degree_non_dominated_sort import (
13
+ dominance_degree_non_dominated_sort,
14
+ )
11
15
  from pymoo.decomposition.util import calc_distance_to_weights
12
16
  from pymoo.util.misc import calc_perpendicular_distance
13
17
  from pymoo.util.hv import hv
@@ -17,36 +21,41 @@ def get_functions():
17
21
 
18
22
  FUNCTIONS = {
19
23
  "fast_non_dominated_sort": {
20
- "python": fast_non_dominated_sort, "cython": "pymoo.cython.non_dominated_sorting"
24
+ "python": fast_non_dominated_sort,
25
+ "cython": "pymoo.cython.non_dominated_sorting",
21
26
  },
22
27
  "efficient_non_dominated_sort": {
23
- "python": efficient_non_dominated_sort, "cython": "pymoo.cython.non_dominated_sorting"
28
+ "python": efficient_non_dominated_sort,
29
+ "cython": "pymoo.cython.non_dominated_sorting",
30
+ },
31
+ "fast_best_order_sort": {
32
+ "python": None,
33
+ "cython": "pymoo.cython.non_dominated_sorting",
24
34
  },
25
35
  "tree_based_non_dominated_sort": {
26
- "python": tree_based_non_dominated_sort, "cython": "pymoo.cython.non_dominated_sorting"
36
+ "python": tree_based_non_dominated_sort,
37
+ "cython": "pymoo.cython.non_dominated_sorting",
38
+ },
39
+ "dominance_degree_non_dominated_sort": {
40
+ "python": dominance_degree_non_dominated_sort,
41
+ "cython": "pymoo.cython.non_dominated_sorting",
27
42
  },
28
43
  "calc_distance_to_weights": {
29
- "python": calc_distance_to_weights, "cython": "pymoo.cython.decomposition"
44
+ "python": calc_distance_to_weights,
45
+ "cython": "pymoo.cython.decomposition",
30
46
  },
31
47
  "calc_perpendicular_distance": {
32
- "python": calc_perpendicular_distance, "cython": "pymoo.cython.calc_perpendicular_distance"
48
+ "python": calc_perpendicular_distance,
49
+ "cython": "pymoo.cython.calc_perpendicular_distance",
33
50
  },
34
51
  "stochastic_ranking": {
35
- "python": stochastic_ranking, "cython": "pymoo.cython.stochastic_ranking"
36
- },
37
- "hv": {
38
- "python": hv, "cython": "pymoo.cython.hv"
39
- },
40
- "calc_mnn": {
41
- "python": calc_mnn, "cython": "pymoo.cython.mnn"
52
+ "python": stochastic_ranking,
53
+ "cython": "pymoo.cython.stochastic_ranking",
42
54
  },
43
- "calc_2nn": {
44
- "python": calc_2nn, "cython": "pymoo.cython.mnn"
45
- },
46
- "calc_pcd": {
47
- "python": calc_pcd, "cython": "pymoo.cython.pruning_cd"
48
- },
49
-
55
+ "hv": {"python": hv, "cython": "pymoo.cython.hv"},
56
+ "calc_mnn": {"python": calc_mnn, "cython": "pymoo.cython.mnn"},
57
+ "calc_2nn": {"python": calc_2nn, "cython": "pymoo.cython.mnn"},
58
+ "calc_pcd": {"python": calc_pcd, "cython": "pymoo.cython.pruning_cd"},
50
59
  }
51
60
 
52
61
  return FUNCTIONS
@@ -111,6 +120,7 @@ def load_function(func_name=None, _type="auto"):
111
120
  def is_compiled():
112
121
  try:
113
122
  from pymoo.cython.info import info
123
+
114
124
  if info() == "yes":
115
125
  return True
116
126
  else: