Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ build/
dist/
/.pytest_cache/
/sostrades_optimization_plugins/tests/__pycache__/
/sostrades_optimization_plugins/tests/.pytest_cache/
/sostrades_optimization_plugins/tests/.pytest_cache/
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: update-headers
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.9.2
hooks:
- id: ruff
args: [
Expand All @@ -14,7 +14,7 @@ repos:
--config=ruff.toml,
]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -41,11 +41,11 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.39.0
rev: v0.43.0
hooks:
- id: markdownlint
args: [
Expand Down
116 changes: 58 additions & 58 deletions headers_ignore_config.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
{
"extension_to_ignore": [
"pkl",
"png",
"jpg",
"csv",
"md",
"markdown",
"avif",
"json",
"in",
"gitignore",
"cfg",
"puml",
"pdf",
"txt",
"ipynb",
"zip",
"rst",
"ini",
"coveragerc",
"yaml",
"bat",
"tex",
"toml"
],
"files_to_ignore": [
"LICENSE",
".readthedocs",
"docs/Makefile",
".flake8",
".prettierignore",
"sostrades_optimization_plugins/models/design_var/design_var.py",
"sostrades_optimization_plugins/models/design_var/design_var_disc.py",
"sostrades_optimization_plugins/models/func_manager/func_manager.py",
"sostrades_optimization_plugins/models/func_manager/func_manager_disc.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_design_var/__init__.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_design_var/process.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_design_var/usecase.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager/__init__.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager/process.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager/usecase.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager_faulty/__init__.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager_faulty/process.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager_faulty/usecase.py",
"sostrades_optimization_plugins/tests/l0_test_14_optim_scenario_with_func_manager.py",
"sostrades_optimization_plugins/tests/l0_test_44_func_manager.py",
"sostrades_optimization_plugins/tests/l0_test_62_design_var_in_sellar.py",
"sostrades_optimization_plugins/tests/l1s_test_all_usecases.py",
"sostrades_optimization_plugins/tools/cst_manager/common_config.py",
"sostrades_optimization_plugins/tools/cst_manager/constraint_manager.py",
"sostrades_optimization_plugins/tools/cst_manager/constraint_object.py",
"sostrades_optimization_plugins/tools/cst_manager/database.py",
"sostrades_optimization_plugins/tools/cst_manager/fileutils.py",
"sostrades_optimization_plugins/tools/cst_manager/func_manager_common.py",
"sostrades_optimization_plugins/tools/cst_manager/__init__.py"
],
"airbus_rev_commit": "d833fdf740389587b876e30f084631430687fa5a"
}
"extension_to_ignore": [
"pkl",
"png",
"jpg",
"csv",
"md",
"markdown",
"avif",
"json",
"in",
"gitignore",
"cfg",
"puml",
"pdf",
"txt",
"ipynb",
"zip",
"rst",
"ini",
"coveragerc",
"yaml",
"bat",
"tex",
"toml"
],
"files_to_ignore": [
"LICENSE",
".readthedocs",
"docs/Makefile",
".flake8",
".prettierignore",
"sostrades_optimization_plugins/models/design_var/design_var.py",
"sostrades_optimization_plugins/models/design_var/design_var_disc.py",
"sostrades_optimization_plugins/models/func_manager/func_manager.py",
"sostrades_optimization_plugins/models/func_manager/func_manager_disc.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_design_var/__init__.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_design_var/process.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_design_var/usecase.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager/__init__.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager/process.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager/usecase.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager_faulty/__init__.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager_faulty/process.py",
"sostrades_optimization_plugins/sos_processes/test/test_sellar_opt_w_func_manager_faulty/usecase.py",
"sostrades_optimization_plugins/tests/l0_test_14_optim_scenario_with_func_manager.py",
"sostrades_optimization_plugins/tests/l0_test_44_func_manager.py",
"sostrades_optimization_plugins/tests/l0_test_62_design_var_in_sellar.py",
"sostrades_optimization_plugins/tests/l1s_test_all_usecases.py",
"sostrades_optimization_plugins/tools/cst_manager/common_config.py",
"sostrades_optimization_plugins/tools/cst_manager/constraint_manager.py",
"sostrades_optimization_plugins/tools/cst_manager/constraint_object.py",
"sostrades_optimization_plugins/tools/cst_manager/database.py",
"sostrades_optimization_plugins/tools/cst_manager/fileutils.py",
"sostrades_optimization_plugins/tools/cst_manager/func_manager_common.py",
"sostrades_optimization_plugins/tools/cst_manager/__init__.py"
],
"airbus_rev_commit": "d833fdf740389587b876e30f084631430687fa5a"
}
2 changes: 1 addition & 1 deletion platform_version_required.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5.0.0
v5.0.0
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
python_files = l*_test*.py
testpaths =
sostrades_optimization_plugins/tests
addopts = --numprocesses=auto
addopts = --numprocesses=auto
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def rebuild_input_array_with_activated_elements(self, inputs_dict, elem):
return np.array(final_value), np.array(gradient)

def update_gradient_with_deactivated_elements_first_value(self, initial_gradient):
### TO DO generalize it with other deactivated elements
# TO DO generalize it with other deactivated elements

result = np.delete(initial_gradient, 0, axis=1)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ def run(self):
# update output dictionary with dspace
outputs_dict.update({'design_space_last_ite': dspace_out})


if self.get_sosdisc_inputs(self.WRITE_XVECT):
#dspace_out.to_csv(f"dspace_ite_{self.iter}.csv", index=False)
# dspace_out.to_csv(f"dspace_ite_{self.iter}.csv", index=False)

# write all iterations into a dictionnary
self.all_iterations_dict.update({f"iteration {self.iter}": dict_current})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Documentation
# Documentation

The design variable discipline handles the variables that are used to drive the optimization.

Expand All @@ -9,5 +9,5 @@ A b-spline function is a continuous composite function, that creates smooth curv

The optimizer has control over the poles, and moves them (on the y-axis) to modify the B-Spline function. Then the value
of the design variables for each year are calculated using the B-Spline function.
![](BSpline_example.PNG)

![](BSpline_example.PNG)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## Documentation

Function manager is a model that aggregates weighted objectives, inequality and equality constraints using smoothing functions.
It takes both dataframes/arrays and floats as objectives/constraints.
It takes both dataframes/arrays and floats as objectives/constraints.

![](scheme_funcmanager.png)

### Scalarize functions
### Scalarize functions

Objectives, inequality constraints and equality constraints functions enter the function manager with a numpy array containing a single (objective) or multiple (constraints) values.
The first step towards the aggregation of these functions is to merge these numpy array into a single scalar value.
Expand All @@ -15,8 +15,8 @@ Each type of function is treated individually at first:
-objectives:
the values are either summed or the smooth_maximum function is applied on value, depending on the 'aggr_type' variable of the function.
-equality and inequality constraints:
the array goes through a function 'cst_func_smooth_positive' to scale the values between 0 and +inf, then the smooth_maximum value is returned.
the array goes through a function 'cst_func_smooth_positive' to scale the values between 0 and +inf, then the smooth_maximum value is returned.

The scalar value of each function is then multiplied by the weight associated with the function

#### Function 'smooth\_maximum'
Expand Down Expand Up @@ -45,7 +45,7 @@ This function loops on the numpy array and apply one of four functions on each e
- if self.smooth_log and val.real > self.eps2: res = res0 + 2 * np.log(val)

The four parts of this function are designed to ensure a smooth continuous function, with a quadratic increase above 'eps'.
If 'smoothlog' is set to True, the function is capped with a log increase above eps2, to avoid some numeric issues with constraints
If 'smoothlog' is set to True, the function is capped with a log increase above eps2, to avoid some numeric issues with constraints
values going haywire.
!['Continuous positive smoothing function'](residuals_wo_smoothlog.png)

Expand All @@ -57,5 +57,3 @@ It is calculated as the sum of the three aggregated functions multiplied by 100.


[^1]: [Martins, J. R. R. A., and Nicholas MK Poon. "On structural optimization using constraint aggregation." VI World Congress on Structural and Multidisciplinary Optimization WCSMO6, Rio de Janeiro, Brasil. 2005.](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.140.3612&rep=rep1&type=pdf)


26 changes: 13 additions & 13 deletions sostrades_optimization_plugins/models/func_manager/func_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self):
self.POS_FTYPE = [self.OBJECTIVE,
self.INEQ_CONSTRAINT, self.EQ_CONSTRAINT]
self.reinit()
#-- We could use it to log?
# -- We could use it to log?

def reinit(self):
"""
Expand Down Expand Up @@ -129,13 +129,13 @@ def scalarize_all_functions(self, eps=1e-3, alpha=3):
dict_mod_func = {}
dict_mod_func[self.FTYPE] = self.functions[tag][self.FTYPE]
dict_mod_func[self.AGGR] = self.functions[tag][self.AGGR]
#-- All values are an np array even single values
#-- Weights are applied here to allow sign modification
# -- All values are an np array even single values
# -- Weights are applied here to allow sign modification
values = weight * self.functions[tag][self.VALUE]
aggr_type = dict_mod_func[self.AGGR]
if self.functions[tag][self.FTYPE] == self.OBJECTIVE:
#-- smooth maximum of values return the value if it was a float
#-- return smooth maximum if objective was an array
# -- smooth maximum of values return the value if it was a float
# -- return smooth maximum if objective was an array
if aggr_type == self.AGGR_TYPE_SMAX:
res = smooth_maximum(values, alpha)
elif aggr_type == self.AGGR_TYPE_SUM:
Expand All @@ -145,7 +145,7 @@ def scalarize_all_functions(self, eps=1e-3, alpha=3):
else:
raise Exception(f"Unhandled aggr_type {aggr_type}")
elif self.functions[tag][self.FTYPE] == self.INEQ_CONSTRAINT:
#-- scale between (0., +inf) and take smooth maximum
# -- scale between (0., +inf) and take smooth maximum
if aggr_type == self.INEQ_NEGATIVE_WHEN_SATIFIED:
res = keep_positive_only(values)
elif aggr_type == self.INEQ_POSITIVE_WHEN_SATIFIED:
Expand Down Expand Up @@ -189,12 +189,12 @@ def build_aggregated_functions(self, eps=1e-3, alpha=3):
elif self.mod_functions[tag][self.FTYPE] == self.EQ_CONSTRAINT:
all_mod_eq_cst.append(self.mod_functions[tag])

#-- Objective aggregation: sum all the objectives
# -- Objective aggregation: sum all the objectives
self.aggregated_functions[self.OBJECTIVE] = 0.
for obj_dict in all_mod_obj:
self.aggregated_functions[self.OBJECTIVE] += obj_dict[self.VALUE]

#-- Inequality constraint aggregation: takes the smooth maximum
# -- Inequality constraint aggregation: takes the smooth maximum
ineq_cst_val = [ineq_dict[self.VALUE] for ineq_dict in all_mod_ineq_cst]
ineq_cst_val = np.array(ineq_cst_val)
if len(ineq_cst_val) > 0:
Expand All @@ -207,7 +207,7 @@ def build_aggregated_functions(self, eps=1e-3, alpha=3):
else:
self.aggregated_functions[self.INEQ_CONSTRAINT] = 0.

#-- Equality constraint aggregation: takes the smooth maximum
# -- Equality constraint aggregation: takes the smooth maximum
eq_cst_val = [eq_dict[self.VALUE] for eq_dict in all_mod_eq_cst]
eq_cst_val = np.array(eq_cst_val)
if len(eq_cst_val) > 0:
Expand All @@ -219,7 +219,7 @@ def build_aggregated_functions(self, eps=1e-3, alpha=3):
else:
self.aggregated_functions[self.EQ_CONSTRAINT] = 0.

#--- Lagrangian objective calculation: sum the aggregated objective and constraints * 100.
# --- Lagrangian objective calculation: sum the aggregated objective and constraints * 100.
self.mod_obj = 0.
self.mod_obj += self.aggregated_functions[self.OBJECTIVE]
self.mod_obj += self.aggregated_functions[self.INEQ_CONSTRAINT]
Expand Down Expand Up @@ -279,15 +279,15 @@ def cst_func_eq_lintoquad(self, values, eps=1e-3, tag='cst'):
cst_result = np.zeros_like(values)
for iii, val in enumerate(values):
if val.real > eps:
#if val > eps: quadratic
# if val > eps: quadratic
res0 = eps * (np.exp(eps) - 1.)
res = res0 + val ** 2 - eps ** 2
elif -eps < val.real < 0:
# if val < 0: linear
res = eps * (np.exp(-val) - 1.)
elif val.real < -eps:
res0 = eps * (np.exp(eps) - 1.)
res= res0 + (-val) - eps
res = res0 + (-val) - eps
else:
# if 0 < val < eps: linear
res = eps * (np.exp(val) - 1.)
Expand Down Expand Up @@ -389,7 +389,7 @@ def scale_function(val, val_range):
:return: scaled function with 0 corresponding to ideal value and 1 to anti-ideal
"""
# TODO: consider using a positive interval and adding a maximisation flag in the sake of clarity
return np.array([(val - val_range[0]) / (val_range[1] - val_range[0])]).reshape((-1,)) # NB: funcmanager demands arrays of shape (N, )
return np.array([(val - val_range[0]) / (val_range[1] - val_range[0])]).reshape((-1,)) # NB: funcmanager demands arrays of shape (N, )

@staticmethod
def scale_function_derivative(val_range) -> float:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setup_usecase(self):

disc_dict = {}
# Sellar inputs
disc_dict[f'{ns}.{coupling_name}.x'] = pd.DataFrame(data={'index': [0,1,2,3], 'value' : [1., 1., 1., 1.]})
disc_dict[f'{ns}.{coupling_name}.x'] = pd.DataFrame(data={'index': [0, 1, 2, 3], 'value': [1., 1., 1., 1.]})
disc_dict[f'{ns}.{coupling_name}.y_1'] = 1.
disc_dict[f'{ns}.{coupling_name}.y_2'] = 1.
disc_dict[f'{ns}.{coupling_name}.z'] = array([5., 2.])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get_builders(self):

}

ns_dict = {'ns_optim': self.ee.study_name ,
'ns_OptimSellar': self.ee.study_name ,
ns_dict = {'ns_optim': self.ee.study_name,
'ns_OptimSellar': self.ee.study_name,
'ns_functions': self.ee.study_name
}

Expand All @@ -61,5 +61,4 @@ def get_builders(self):
"SellarCoupling")
coupling_builder.set_builder_info('cls_builder', builder_list)


return coupling_builder
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def setup_usecase(self):
disc_dict[
f'{ns}.{self.coupling_name}.DesignVar.design_var_descriptor'] = design_var_descriptor


# Sellar and design var inputs
disc_dict[f'{ns}.x_in'] = array([1., 1., 1., 1.])
disc_dict[f'{ns}.y_1'] = 5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Generate an optimization scenario
"""


class ProcessBuilder(BaseProcessBuilder):

# ontology information
Expand All @@ -30,6 +31,7 @@ class ProcessBuilder(BaseProcessBuilder):
'category': '',
'version': '',
}

def get_builders(self):
'''
default initialisation test
Expand Down
Loading
Loading