surrogates_interface 4.0.1__tar.gz

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.
@@ -0,0 +1,25 @@
1
+ The MIT License
2
+
3
+ Copyright 2023 DTU Wind and Energy Systems
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is furnished
10
+ to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+
24
+ A few lines in transformers.py are taken from the scikit-learn project,
25
+ which is licensed under the BSD 3-Clause license.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.1
2
+ Name: surrogates_interface
3
+ Version: 4.0.1
4
+ Summary: Interface for surrogate models.
5
+ Home-page: https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface
6
+ License: MIT
7
+ Author: DTU Wind and Energy Systems
8
+ Maintainer: Riccardo Riva
9
+ Maintainer-email: ricriv@dtu.dk
10
+ Requires-Python: >=3.9,<3.12
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Provides-Extra: all
17
+ Provides-Extra: code-style
18
+ Provides-Extra: docs
19
+ Provides-Extra: om
20
+ Provides-Extra: smt
21
+ Provides-Extra: test
22
+ Provides-Extra: tf
23
+ Requires-Dist: black ; extra == "all" or extra == "code-style"
24
+ Requires-Dist: codespell ; extra == "all" or extra == "code-style"
25
+ Requires-Dist: flake8 ; extra == "all" or extra == "code-style"
26
+ Requires-Dist: h5py
27
+ Requires-Dist: isort ; extra == "all" or extra == "code-style"
28
+ Requires-Dist: matplotlib ; extra == "all" or extra == "test" or extra == "smt"
29
+ Requires-Dist: numpy (>=1.10.0)
30
+ Requires-Dist: numpydoc ; extra == "all" or extra == "docs"
31
+ Requires-Dist: openmdao (>=3.25,<4.0) ; extra == "all" or extra == "docs" or extra == "test" or extra == "om"
32
+ Requires-Dist: pydata-sphinx-theme ; extra == "all" or extra == "docs"
33
+ Requires-Dist: pytest ; extra == "all" or extra == "test"
34
+ Requires-Dist: pytest-cov ; extra == "all" or extra == "test"
35
+ Requires-Dist: pytest-testmon ; extra == "all" or extra == "test"
36
+ Requires-Dist: scikit-learn ; extra == "all" or extra == "test" or extra == "smt" or extra == "tf"
37
+ Requires-Dist: smt (>=2.0.1,<3.0.0) ; extra == "all" or extra == "test" or extra == "smt"
38
+ Requires-Dist: sphinx ; extra == "all" or extra == "docs"
39
+ Requires-Dist: sphinx-copybutton ; extra == "all" or extra == "docs"
40
+ Requires-Dist: sphinx-sitemap ; extra == "all" or extra == "docs"
41
+ Requires-Dist: tensorflow (>=2.10.0,<2.11) ; (platform_system == "Windows") and (extra == "all" or extra == "test" or extra == "tf")
42
+ Requires-Dist: tensorflow (>=2.10.0,<3.0.0) ; (platform_system != "Windows") and (extra == "all" or extra == "test" or extra == "tf")
43
+ Requires-Dist: tensorflow-cpu (>=2.10.0,<3.0.0) ; (platform_machine != "arm64" and platform_machine != "aarch64") and sys_platform == "darwin"
44
+ Requires-Dist: tensorflow-cpu (>=2.10.0,<3.0.0) ; (platform_machine != "arm64" and platform_machine != "aarch64") and sys_platform == "linux"
45
+ Requires-Dist: tensorflow-cpu-aws (>=2.10.0,<3.0.0) ; (platform_machine == "arm64" or platform_machine == "aarch64") and sys_platform == "linux"
46
+ Requires-Dist: tensorflow-intel (>=2.10.0,<3.0.0) ; sys_platform == "win32"
47
+ Requires-Dist: tensorflow-io-gcs-filesystem (<0.32.0) ; platform_system == "Windows"
48
+ Requires-Dist: tensorflow-io-gcs-filesystem (>=0.23.1) ; platform_machine != "arm64" or platform_system != "Darwin"
49
+ Requires-Dist: tensorflow-macos (>=2.10.0,<3.0.0) ; platform_machine == "arm64" and sys_platform == "darwin"
50
+ Requires-Dist: tomli (>=2.0.1,<3.0.0) ; (python_version < "3.11") and (extra == "all" or extra == "test")
51
+ Project-URL: Repository, https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface
52
+ Description-Content-Type: text/markdown
53
+
54
+ # Surrogate Models Interface
55
+
56
+ [![pipeline status](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/badges/main/pipeline.svg)](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/-/commits/main)
57
+ [![coverage report](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/badges/main/coverage.svg)](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/-/commits/main)
58
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
59
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
60
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
61
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8282614.svg)](https://doi.org/10.5281/10.5281/zenodo.8282614)
62
+
63
+ Provides a common interface to several surrogate models, including an OpenMDAO wrapper.
64
+
65
+ The documentation is available at: https://surrogate-models.pages.windenergy.dtu.dk/surrogate-models-interface
66
+
@@ -0,0 +1,12 @@
1
+ # Surrogate Models Interface
2
+
3
+ [![pipeline status](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/badges/main/pipeline.svg)](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/-/commits/main)
4
+ [![coverage report](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/badges/main/coverage.svg)](https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface/-/commits/main)
5
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
6
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
8
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8282614.svg)](https://doi.org/10.5281/10.5281/zenodo.8282614)
9
+
10
+ Provides a common interface to several surrogate models, including an OpenMDAO wrapper.
11
+
12
+ The documentation is available at: https://surrogate-models.pages.windenergy.dtu.dk/surrogate-models-interface
@@ -0,0 +1,132 @@
1
+ [tool.poetry]
2
+ name = "surrogates_interface"
3
+ version = "4.0.1"
4
+ description = "Interface for surrogate models."
5
+ authors = ["DTU Wind and Energy Systems"]
6
+ maintainers = [
7
+ "Riccardo Riva <ricriv@dtu.dk>",
8
+ "Mads Mølgaard Pedersen <mmpe@dtu.dk>",
9
+ ]
10
+ license = "MIT"
11
+ readme = "README.md"
12
+ repository = "https://gitlab.windenergy.dtu.dk/surrogate-models/surrogate-models-interface"
13
+
14
+ [tool.poetry.build]
15
+ generate-setup-file = false
16
+
17
+ [tool.poetry.dependencies]
18
+
19
+ python = ">=3.9,<3.12"
20
+ numpy = ">=1.10.0"
21
+ h5py = "*"
22
+ black = {version="*", optional=true}
23
+ flake8 = {version="*", optional=true}
24
+ isort = {version="*", optional=true}
25
+ codespell = {version="*", optional=true}
26
+ pytest = {version="*", optional=true}
27
+ pytest-cov = {version="*", optional=true}
28
+ pytest-testmon = {version="*", optional=true}
29
+ tomli = {version="^2.0.1", python="<3.11", optional=true}
30
+ sphinx = {version="*", optional=true}
31
+ pydata-sphinx-theme = {version="*", optional=true}
32
+ sphinx-copybutton = {version="*", optional=true}
33
+ sphinx-sitemap = {version="*", optional=true}
34
+ numpydoc = {version="*", optional=true}
35
+ matplotlib = {version="*", optional=true}
36
+ scikit-learn = {version="*", optional=true}
37
+ # Issue between poetry and tensorflow metadata since >=2.11
38
+ # This is a temporary workaround
39
+ # related to https://github.com/python-poetry/poetry/issues/8271
40
+ # Inspired from https://github.com/tensorflow/tensorflow/blob/adb39b04e9cb116df4659a7e2de9eea27e62f25c/tensorflow/tools/pip_package/setup.py#L148-L162
41
+ tensorflow = [
42
+ {version = ">=2.10.0, <2.11", markers = "platform_system == 'Windows'", optional=true },
43
+ {version = "^2.10.0", markers = "platform_system != 'Windows'", optional=true },
44
+ ]
45
+ tensorflow-macos = { version = "^2.10.0", platform = "darwin", markers = "platform_machine=='arm64'", optional=true }
46
+ tensorflow-intel = { version = "^2.10.0", platform = "win32", optional=true }
47
+ tensorflow-cpu = [
48
+ { version = "^2.10.0", platform = "linux", markers = "platform_machine!='arm64' and platform_machine!='aarch64'", optional=true },
49
+ { version = "^2.10.0", platform = "darwin", markers = "platform_machine!='arm64' and platform_machine!='aarch64'", optional=true },]
50
+ tensorflow-cpu-aws = { version = "^2.10.0", platform = "linux", markers = "platform_machine=='arm64' or platform_machine=='aarch64'" }
51
+ # https://github.com/tensorflow/tensorflow/blob/adb39b04e9cb116df4659a7e2de9eea27e62f25c/tensorflow/tools/pip_package/setup.py#L107-L108
52
+ # https://github.com/python-poetry/poetry/issues/8271#issuecomment-1697740447
53
+ tensorflow-io-gcs-filesystem = [
54
+ { version = ">= 0.23.1", markers = "platform_machine!='arm64' or platform_system!='Darwin'", optional=true },
55
+ { version = "< 0.32.0", markers = "platform_system == 'Windows'", optional=true }
56
+ ]
57
+ smt = {version="^2.0.1", optional=true}
58
+ openmdao = {version="^3.25", optional=true}
59
+
60
+ [tool.poetry.extras]
61
+ all = ["black",
62
+ "flake8",
63
+ "isort",
64
+ "codespell",
65
+ "pytest",
66
+ "pytest-cov",
67
+ "pytest-testmon",
68
+ "tomli",
69
+ "sphinx",
70
+ "pydata-sphinx-theme",
71
+ "sphinx-copybutton",
72
+ "sphinx-sitemap",
73
+ "numpydoc",
74
+ "matplotlib",
75
+ "scikit-learn",
76
+ "smt",
77
+ "tensorflow",
78
+ "openmdao",
79
+ ]
80
+
81
+ docs = ["sphinx",
82
+ "pydata-sphinx-theme",
83
+ "sphinx-copybutton",
84
+ "sphinx-sitemap",
85
+ "numpydoc",
86
+ "openmdao",
87
+ ]
88
+
89
+ code_style = ["black",
90
+ "flake8",
91
+ "isort",
92
+ "codespell",
93
+ ]
94
+
95
+ test = ["matplotlib", # Needed by SMT.
96
+ "pytest",
97
+ "pytest-cov",
98
+ "pytest-testmon",
99
+ "tomli",
100
+ "scikit-learn",
101
+ "smt",
102
+ "tensorflow",
103
+ "openmdao",
104
+ ]
105
+
106
+ smt = ["matplotlib", # Needed by SMT.
107
+ "scikit-learn",
108
+ "smt",
109
+ ]
110
+
111
+ tf = ["scikit-learn",
112
+ "tensorflow",
113
+ ]
114
+
115
+ om = ["openmdao"]
116
+
117
+
118
+ [build-system]
119
+ build-backend = "poetry.core.masonry.api"
120
+ requires = ["poetry-core", "numpy"]
121
+
122
+ [tool.coverage.run]
123
+ omit = ["surrogates_interface/test/*", ]
124
+
125
+ [tool.coverage.report]
126
+ fail_under = 100
127
+
128
+ [tool.isort]
129
+ profile = "black"
130
+
131
+ [tool.codespell]
132
+ ignore-words-list = "coo"
@@ -0,0 +1,3 @@
1
+ import importlib.metadata
2
+
3
+ __version__ = importlib.metadata.version(__name__)
@@ -0,0 +1,107 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ The classes contained in this module allow to find when a set of points is contained in the domain.
4
+ """
5
+
6
+ from abc import ABC, abstractmethod
7
+
8
+ import h5py
9
+ import numpy as np
10
+
11
+ # String type for h5py.
12
+ H5_STR = h5py.special_dtype(vlen=str)
13
+
14
+
15
+ class GenericDomain(ABC):
16
+ """Base class for all domains."""
17
+
18
+ @property
19
+ @abstractmethod
20
+ def fields(self):
21
+ """List of fields in hdf5 group and GenericDomain object."""
22
+
23
+ @abstractmethod
24
+ def in_domain(self, x):
25
+ """Check that the input points are inside the domain."""
26
+
27
+ def _save_h5(self, group):
28
+ """Save this domain to a h5py `Group`.
29
+
30
+ Parameters
31
+ ----------
32
+ group : h5py.Group
33
+ Group where this object will be saved.
34
+ """
35
+ group.create_dataset("type", data=self.__class__.__name__, dtype=H5_STR)
36
+ for f in self.fields:
37
+ group.create_dataset(f, data=getattr(self, f))
38
+
39
+ @classmethod
40
+ def _load_h5(cls, group):
41
+ """
42
+ Load this domain from a h5py `Group`.
43
+
44
+ Parameters
45
+ ----------
46
+ group : h5py.Group
47
+ Group where this object has been saved.
48
+
49
+ Returns
50
+ -------
51
+ obj : GenericDomain
52
+ The saved domain.
53
+ """
54
+ # Protected because this function should be called by SurrogateModel.load_h5.
55
+ return cls(*[group[f][:] for f in cls.fields])
56
+
57
+
58
+ class BoxDomain(GenericDomain):
59
+ """Implements a n-dimensional box domain."""
60
+
61
+ fields = ["min", "max"]
62
+
63
+ def __init__(self, min, max):
64
+ """Create a new `BoxDomain`, based on the given min and max for each feature.
65
+
66
+ Parameters
67
+ ----------
68
+ min : array-like of shape (n_features)
69
+ Minimum for each feature.
70
+ max : array-like of shape (n_features)
71
+ Maximum for each feature.
72
+ """
73
+ self.min = np.asarray(min)
74
+ self.max = np.asarray(max)
75
+ assert np.all(np.greater_equal(self.max, self.min))
76
+
77
+ def in_domain(self, x):
78
+ """Check that the input points are inside the domain.
79
+
80
+ Parameters
81
+ ----------
82
+ x : array-like of shape (n_points, n_features)
83
+ Input points.
84
+
85
+ Returns
86
+ -------
87
+ y : array-like of shape (n_points, )
88
+ Array with `True` if a point is inside the domain and `False` otherwise.
89
+ """
90
+ # Test x >= min for each dimension.
91
+ test_min = np.greater_equal(x, self.min)
92
+
93
+ # Test x <= max for each dimension.
94
+ test_max = np.less_equal(x, self.max)
95
+
96
+ # Test min <= x <= max for each dimension.
97
+ test_minmax = np.logical_and(test_min, test_max)
98
+
99
+ # Test min <= x <= max for all dimensions.
100
+ return np.all(test_minmax, axis=1)
101
+
102
+ def __eq__(self, other):
103
+ if isinstance(other, self.__class__):
104
+ test_min = np.array_equal(self.min, other.min)
105
+ test_max = np.array_equal(self.max, other.max)
106
+ return test_min and test_max
107
+ return False