|
16 | 16 | from scipy.optimize import shgo, differential_evolution |
17 | 17 | import numpy as np |
18 | 18 | import pandas as pd |
19 | | -from chaospy import distributions as shape |
20 | 19 | from ._indicator import Indicator |
21 | 20 | from ._feature import MockFeature |
22 | 21 | from ._utils import var_indices, var_columns, indices_to_multiindex |
|
30 | 29 | from ._parameter import Parameter |
31 | 30 | from .evaluation_tools import load_default_parameters |
32 | 31 | import pickle |
| 32 | +try: |
| 33 | + from chaospy import distributions as shape |
| 34 | + import chaospy as cp |
| 35 | + Distribution = shape.baseclass.Distribution |
| 36 | +except: |
| 37 | + Distribution = None |
33 | 38 |
|
34 | 39 | __all__ = ('Model', 'EasyInputModel') |
35 | 40 |
|
@@ -60,35 +65,6 @@ def f(x): |
60 | 65 | function = wrapper_fn(code) |
61 | 66 | return function |
62 | 67 |
|
63 | | -# %% Fix compatibility with new chaospy version |
64 | | - |
65 | | -import chaospy as cp |
66 | | -version_components = cp.__version__.split('.') |
67 | | -CP_MAJOR, CP_MINOR = int(version_components[0]), int(version_components[1]) |
68 | | -CP4 = (CP_MAJOR, CP_MINOR) >= (4, 0) |
69 | | -if CP4: |
70 | | - from inspect import signature |
71 | | - def save_repr_init(f): |
72 | | - defaults = list(signature(f).parameters.values())[1:] |
73 | | - defaults = {i.name: i.default for i in defaults} |
74 | | - def init(self, *args, **kwargs): |
75 | | - if not hasattr(self, '_repr'): |
76 | | - self._repr = params = defaults.copy() |
77 | | - for i, j in zip(params, args): params[i] = j |
78 | | - params.update(kwargs) |
79 | | - f(self, *args, **kwargs) |
80 | | - return init |
81 | | - |
82 | | - shapes = cp.distributions |
83 | | - Distribution = cp.distributions.Distribution |
84 | | - baseshapes = set([i for i in cp.distributions.baseclass.__dict__.values() |
85 | | - if isinstance(i, type) and issubclass(i, Distribution)]) |
86 | | - for i in shapes.__dict__.values(): |
87 | | - if isinstance(i, type) and issubclass(i, Distribution) and i not in baseshapes: |
88 | | - i.__init__ = save_repr_init(i.__init__) |
89 | | - del signature, save_repr_init, shapes, baseshapes, Distribution, i |
90 | | -del version_components, CP_MAJOR, CP_MINOR, CP4 |
91 | | - |
92 | 68 | # %% Simulation of process systems |
93 | 69 |
|
94 | 70 | class Model: |
@@ -324,7 +300,7 @@ def parameter(self, |
324 | 300 | element: Optional[Unit]=None, |
325 | 301 | coupled: Optional[bool]=None, |
326 | 302 | name: Optional[str]=None, |
327 | | - distribution: Optional[str|shape.baseclass.Distribution]=None, |
| 303 | + distribution: Optional[str|Distribution]=None, |
328 | 304 | units: Optional[str]=None, |
329 | 305 | baseline: Optional[float]=None, |
330 | 306 | bounds: Optional[tuple[float, float]]=None, |
|
0 commit comments