gemseo-multi-fidelity 0.0.1__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 (76) hide show
  1. gemseo_multi_fidelity/__init__.py +17 -0
  2. gemseo_multi_fidelity/core/MFMapperAdapter_input.json +22 -0
  3. gemseo_multi_fidelity/core/MFMapperAdapter_output.json +22 -0
  4. gemseo_multi_fidelity/core/MFMapperLinker_input.json +22 -0
  5. gemseo_multi_fidelity/core/MFMapperLinker_output.json +22 -0
  6. gemseo_multi_fidelity/core/MFScenarioAdapter_input.json +39 -0
  7. gemseo_multi_fidelity/core/MFScenarioAdapter_output.json +23 -0
  8. gemseo_multi_fidelity/core/__init__.py +16 -0
  9. gemseo_multi_fidelity/core/boxed_domain.py +242 -0
  10. gemseo_multi_fidelity/core/corr_function.py +411 -0
  11. gemseo_multi_fidelity/core/criticality.py +124 -0
  12. gemseo_multi_fidelity/core/ds_mapper.py +307 -0
  13. gemseo_multi_fidelity/core/errors.py +42 -0
  14. gemseo_multi_fidelity/core/eval_mapper.py +188 -0
  15. gemseo_multi_fidelity/core/id_mapper_adapter.py +61 -0
  16. gemseo_multi_fidelity/core/mapper_adapter.py +126 -0
  17. gemseo_multi_fidelity/core/mapper_linker.py +72 -0
  18. gemseo_multi_fidelity/core/mf_formulation.py +635 -0
  19. gemseo_multi_fidelity/core/mf_logger.py +216 -0
  20. gemseo_multi_fidelity/core/mf_opt_problem.py +480 -0
  21. gemseo_multi_fidelity/core/mf_scenario.py +205 -0
  22. gemseo_multi_fidelity/core/noise_criterion.py +94 -0
  23. gemseo_multi_fidelity/core/projpolytope.out +0 -0
  24. gemseo_multi_fidelity/core/scenario_adapter.py +568 -0
  25. gemseo_multi_fidelity/core/stop_criteria.py +201 -0
  26. gemseo_multi_fidelity/core/strict_chain.py +75 -0
  27. gemseo_multi_fidelity/core/utils_model_quality.py +74 -0
  28. gemseo_multi_fidelity/corrections/__init__.py +16 -0
  29. gemseo_multi_fidelity/corrections/add_corr_function.py +80 -0
  30. gemseo_multi_fidelity/corrections/correction_factory.py +65 -0
  31. gemseo_multi_fidelity/corrections/mul_corr_function.py +86 -0
  32. gemseo_multi_fidelity/drivers/__init__.py +16 -0
  33. gemseo_multi_fidelity/drivers/mf_algo_factory.py +38 -0
  34. gemseo_multi_fidelity/drivers/mf_driver_lib.py +462 -0
  35. gemseo_multi_fidelity/drivers/refinement.py +234 -0
  36. gemseo_multi_fidelity/drivers/settings/__init__.py +16 -0
  37. gemseo_multi_fidelity/drivers/settings/base_mf_driver_settings.py +59 -0
  38. gemseo_multi_fidelity/drivers/settings/mf_refine_settings.py +50 -0
  39. gemseo_multi_fidelity/formulations/__init__.py +16 -0
  40. gemseo_multi_fidelity/formulations/refinement.py +144 -0
  41. gemseo_multi_fidelity/mapping/__init__.py +16 -0
  42. gemseo_multi_fidelity/mapping/identity_mapper.py +74 -0
  43. gemseo_multi_fidelity/mapping/interp_mapper.py +422 -0
  44. gemseo_multi_fidelity/mapping/mapper_factory.py +70 -0
  45. gemseo_multi_fidelity/mapping/mapping_errors.py +46 -0
  46. gemseo_multi_fidelity/mapping/subset_mapper.py +122 -0
  47. gemseo_multi_fidelity/mf_rosenbrock/__init__.py +16 -0
  48. gemseo_multi_fidelity/mf_rosenbrock/delayed_disc.py +136 -0
  49. gemseo_multi_fidelity/mf_rosenbrock/refact_rosen_testcase.py +46 -0
  50. gemseo_multi_fidelity/mf_rosenbrock/rosen_mf_case.py +284 -0
  51. gemseo_multi_fidelity/mf_rosenbrock/rosen_mf_funcs.py +350 -0
  52. gemseo_multi_fidelity/models/__init__.py +16 -0
  53. gemseo_multi_fidelity/models/fake_updater.py +112 -0
  54. gemseo_multi_fidelity/models/model_updater.py +91 -0
  55. gemseo_multi_fidelity/models/rbf/__init__.py +16 -0
  56. gemseo_multi_fidelity/models/rbf/kernel_factory.py +66 -0
  57. gemseo_multi_fidelity/models/rbf/kernels/__init__.py +16 -0
  58. gemseo_multi_fidelity/models/rbf/kernels/gaussian.py +93 -0
  59. gemseo_multi_fidelity/models/rbf/kernels/matern_3_2.py +101 -0
  60. gemseo_multi_fidelity/models/rbf/kernels/matern_5_2.py +101 -0
  61. gemseo_multi_fidelity/models/rbf/kernels/rbf_kernel.py +172 -0
  62. gemseo_multi_fidelity/models/rbf/rbf_model.py +422 -0
  63. gemseo_multi_fidelity/models/sparse_rbf_updater.py +96 -0
  64. gemseo_multi_fidelity/models/taylor/__init__.py +16 -0
  65. gemseo_multi_fidelity/models/taylor/taylor.py +212 -0
  66. gemseo_multi_fidelity/models/taylor_updater.py +66 -0
  67. gemseo_multi_fidelity/models/updater_factory.py +62 -0
  68. gemseo_multi_fidelity/settings/__init__.py +16 -0
  69. gemseo_multi_fidelity/settings/drivers.py +22 -0
  70. gemseo_multi_fidelity/settings/formulations.py +16 -0
  71. gemseo_multi_fidelity-0.0.1.dist-info/METADATA +99 -0
  72. gemseo_multi_fidelity-0.0.1.dist-info/RECORD +76 -0
  73. gemseo_multi_fidelity-0.0.1.dist-info/WHEEL +5 -0
  74. gemseo_multi_fidelity-0.0.1.dist-info/entry_points.txt +2 -0
  75. gemseo_multi_fidelity-0.0.1.dist-info/licenses/LICENSE.txt +165 -0
  76. gemseo_multi_fidelity-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,16 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+
16
+ """Drivers settings."""
@@ -0,0 +1,59 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+ # Francois Gallard: portage to GEMSEO 6
16
+ """Settings for the Refinement algorithm."""
17
+
18
+ from __future__ import annotations
19
+
20
+ from pydantic import BaseModel
21
+ from pydantic import Field
22
+
23
+
24
+ def check_sizes(model: BaseModel, field_name: str, expected_size: int) -> BaseModel:
25
+ """Check the sizes of the data.
26
+
27
+ If the field is None or of length one, updates its value to a list of expected_size.
28
+
29
+ Args:
30
+ model: The model to be checked.
31
+ field_name: The name of the field to validate.
32
+ expected_size: The expected size of the field.
33
+
34
+ Returns:
35
+ The checked model.
36
+ """
37
+ field_value = getattr(model, field_name)
38
+
39
+ if isinstance(field_value, (bool, str, dict, type(None))):
40
+ field_value = [field_value] * expected_size
41
+ elif len(field_value) == 0:
42
+ field_value = [False] * expected_size
43
+ elif len(field_value) != expected_size:
44
+ msg = f"The field {field_name} length must be 0 or {expected_size}."
45
+ raise ValueError(msg)
46
+ setattr(model, field_name, field_value)
47
+ return model
48
+
49
+
50
+ class BaseMFDriver_Settings(BaseModel): # noqa: N801
51
+ """The Refinement algorithms settings."""
52
+
53
+ x_start: object = Field(default=None, description="Optimization initial guess")
54
+
55
+ input_level: int = Field(
56
+ default=0,
57
+ description="The index (from 0) of the sub scenario level to start the "
58
+ "optimization.",
59
+ )
@@ -0,0 +1,50 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+ # Francois Gallard: portage to GEMSEO 6
16
+ """Settings for the MFDriverLibrary algorithm."""
17
+
18
+ from __future__ import annotations
19
+
20
+ from pydantic import Field
21
+ from pydantic import model_validator
22
+
23
+ from gemseo_multi_fidelity.drivers.settings.base_mf_driver_settings import (
24
+ BaseMFDriver_Settings,
25
+ )
26
+ from gemseo_multi_fidelity.drivers.settings.base_mf_driver_settings import check_sizes
27
+
28
+
29
+ class MFRefine_Settings(BaseMFDriver_Settings): # noqa: N801
30
+ """The MFRefine Settings."""
31
+
32
+ _TARGET_CLASS_NAME = "MF_REFINE"
33
+
34
+ n_levels: int = Field(description="The number of fidelity levels.")
35
+
36
+ build_precond: list[bool] | bool = Field(
37
+ default=False, description="Whether to build a preconditioner."
38
+ )
39
+
40
+ forward_precond: list[bool] | bool = Field(
41
+ default=False,
42
+ description="Whether to forwards the current preconditioner to the next level.",
43
+ )
44
+
45
+ @model_validator(mode="after")
46
+ def check_precond(self) -> MFRefine_Settings:
47
+ """Check preconditioner."""
48
+ for field_name in "build_precond", "forward_precond":
49
+ check_sizes(self, field_name, self.n_levels)
50
+ return self
@@ -0,0 +1,16 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+
16
+ """Formulations."""
@@ -0,0 +1,144 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+
16
+ # Copyright (c) 2019 AIRBUS OPERATIONS
17
+
18
+ #
19
+ # Contributors:
20
+ # INITIAL AUTHORS - API and implementation and/or documentation
21
+ # :author: Romain Olivanti
22
+ # OTHER AUTHORS - MACROSCOPIC CHANGES
23
+ """Refinement multi-fidelity formulation."""
24
+
25
+ from __future__ import annotations
26
+
27
+ from typing import TYPE_CHECKING
28
+ from typing import Any
29
+ from typing import ClassVar
30
+
31
+ from gemseo.algos.opt.factory import OptimizationLibraryFactory
32
+
33
+ from gemseo_multi_fidelity.core.mapper_adapter import MFMapperAdapter
34
+ from gemseo_multi_fidelity.core.mf_formulation import MFFormulation
35
+ from gemseo_multi_fidelity.core.scenario_adapter import MFScenarioAdapter
36
+ from gemseo_multi_fidelity.core.strict_chain import StrictChain
37
+
38
+ if TYPE_CHECKING:
39
+ from collections.abc import Iterable
40
+ from collections.abc import Mapping
41
+ from collections.abc import Sequence
42
+
43
+ from gemseo.algos.database import Database
44
+ from gemseo.algos.design_space import DesignSpace
45
+ from gemseo.scenarios.mdo_scenario import MDOScenario
46
+
47
+ from gemseo_multi_fidelity.core.ds_mapper import DesignSpaceMapper
48
+
49
+
50
+ class Refinement(MFFormulation):
51
+ """Refinement multi-fidelity formulation."""
52
+
53
+ _ALGO_FACTORY_CLASS: ClassVar[type[OptimizationLibraryFactory]] = (
54
+ OptimizationLibraryFactory
55
+ )
56
+ """Algorithm factory class."""
57
+
58
+ def __init__(
59
+ self,
60
+ disciplines: Sequence[MDOScenario],
61
+ objective_name: str,
62
+ design_space: DesignSpace,
63
+ design_space_mapping: DesignSpaceMapper = None,
64
+ functions_mapping: Mapping[str, Any] | None = None,
65
+ correction_mapping: Iterable[Mapping[str, Any]] | None = None,
66
+ databases: Iterable[Database] | None = None,
67
+ **options: Any,
68
+ ) -> None:
69
+ """Constructor."""
70
+ # TODO old style until the bug is fixed
71
+ # super(Refinement, self).__init__
72
+ super().__init__(
73
+ disciplines,
74
+ objective_name,
75
+ design_space,
76
+ design_space_mapping=design_space_mapping,
77
+ functions_mapping=functions_mapping,
78
+ correction_mapping=correction_mapping,
79
+ databases=databases,
80
+ )
81
+
82
+ chain, opt_adapters = self._build_refinement_chain()
83
+ self._opt_adapters = opt_adapters
84
+ self._chain = chain
85
+ self._build_driver_interface()
86
+
87
+ def _build_opt_adapter_at_level(self, i: int):
88
+ scenario = self._scenarios[i]
89
+ return MFScenarioAdapter(scenario)
90
+
91
+ def _build_mapper_adapter_at_level(self, i: int):
92
+ mapper = self._eval_mappers[i - 1]
93
+ mapper_name = f"mapper_{i:d}"
94
+ return MFMapperAdapter(mapper_name, mapper, direct=True)
95
+
96
+ def _build_refinement_chain(self):
97
+ disciplines = []
98
+ opt_adapters = []
99
+
100
+ add_disc = disciplines.append
101
+ add_opt_adapter = opt_adapters.append
102
+
103
+ levels = list(range(len(self._scenarios)))
104
+
105
+ # Low-fidelity -> High-fidelity
106
+ for level in levels[:0:-1]:
107
+ # Add the sub opt adapter
108
+ opt_adapter = self._build_opt_adapter_at_level(level)
109
+ add_disc(opt_adapter)
110
+ add_opt_adapter(opt_adapter)
111
+ # Add the mapper to link it with the next level
112
+ mapper_adapter = self._build_mapper_adapter_at_level(level)
113
+ add_disc(mapper_adapter)
114
+
115
+ # Add the top level which is not linked to anything
116
+ opt_adapter = self._build_opt_adapter_at_level(0)
117
+ add_disc(opt_adapter)
118
+ add_opt_adapter(opt_adapter)
119
+ chain = StrictChain(disciplines, name="refinement_chain")
120
+
121
+ # reverse the opt adapter to provide them in the hierarchical order
122
+ opt_adapters.reverse()
123
+ return chain, opt_adapters
124
+
125
+ def _build_workflow_runner(self):
126
+ def run_refinement(x_start, **options):
127
+ # Prepare options
128
+ input_data = options
129
+ input_data[MFScenarioAdapter.X_START] = x_start
130
+ # Run the chain
131
+ self._chain.execute(input_data=input_data)
132
+ # Extract the best point found
133
+ output = self._chain.get_output_data()
134
+ return output[MFScenarioAdapter.X_BEST]
135
+
136
+ return run_refinement
137
+
138
+ def get_expected_workflow(self):
139
+ """Get the expected workflow."""
140
+ return self._chain.get_expected_workflow()
141
+
142
+ def get_expected_dataflow(self):
143
+ """Get the expected dataflow."""
144
+ return self._chain.get_expected_dataflow()
@@ -0,0 +1,16 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+
16
+ """Mapping."""
@@ -0,0 +1,74 @@
1
+ # Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 3 as published by the Free Software Foundation.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public License
13
+ # along with this program; if not, write to the Free Software Foundation,
14
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+
16
+ # Copyright (c) 2019 AIRBUS OPERATIONS
17
+
18
+ #
19
+ # Contributors:
20
+ # INITIAL AUTHORS - API and implementation and/or documentation
21
+ # :author: Romain Olivanti
22
+ # OTHER AUTHORS - MACROSCOPIC CHANGES
23
+ """Identity mapper."""
24
+
25
+ from __future__ import annotations
26
+
27
+ from copy import deepcopy
28
+ from typing import TYPE_CHECKING
29
+
30
+ from numpy import eye
31
+
32
+ from gemseo_multi_fidelity.core.ds_mapper import DesignSpaceMapper
33
+
34
+ if TYPE_CHECKING:
35
+ from gemseo.algos.design_space import DesignSpace
36
+ from numpy.typing import NDArray
37
+
38
+
39
+ class IdentityMapper(DesignSpaceMapper):
40
+ """Identity mapper."""
41
+
42
+ def _map_vars_direct(self, dvs_dict_in: DesignSpace) -> DesignSpace:
43
+ """Map vars direct.
44
+
45
+ Args:
46
+ dvs_dict_in: The input design space.
47
+
48
+ Returns:
49
+ The output design space.
50
+ """
51
+ return deepcopy(dvs_dict_in)
52
+
53
+ def _map_vars_reverse(self, dvs_dict_out: DesignSpace) -> DesignSpace:
54
+ """Map vars reverse.
55
+
56
+ Args:
57
+ dvs_dict_out: The output design space.
58
+
59
+ Returns:
60
+ The input design space.
61
+ """
62
+ return deepcopy(dvs_dict_out)
63
+
64
+ def get_jac(self) -> NDArray:
65
+ """Get jacobian.
66
+
67
+ Returns:
68
+ The jacobian.
69
+ """
70
+ jac = {}
71
+ ds = self.design_space_in
72
+ for var, var_size in ds.variable_sizes.items():
73
+ jac[var] = {var: eye(var_size)}
74
+ return jac