Skip to content

Commit

Permalink
Adjust ruff configuration to handle trailing whitespaces (#524)
Browse files Browse the repository at this point in the history
* Adjust ruff conf to fix whitespace related lints

* Fix whitespace-related lints (W)

* Fix MFK without noise link and make some sub-sections

* Enforce line not longer than 120 chars

* Wrap lines longer than 120 chars
  • Loading branch information
relf committed Feb 28, 2024
1 parent cbf33ea commit 8fc434b
Show file tree
Hide file tree
Showing 34 changed files with 193 additions and 131 deletions.
2 changes: 1 addition & 1 deletion doc/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Author: Dr. John T. Hwang <hwangjt@umich.edu>
This package is distributed under New BSD license.
"""

Expand Down
2 changes: 1 addition & 1 deletion doc/preprocess_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Author: Dr. John T. Hwang <hwangjt@umich.edu>
This package is distributed under New BSD license.
"""

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
requires = ["setuptools", "wheel", "numpy", "Cython"]

[tool.ruff.lint]
select = ["E", "F", "W"]
ignore = []

[tool.ruff.lint.pycodestyle]
max-line-length = 120

[tool.pytest.ini_options]
filterwarnings = ["ignore:FigureCanvasAgg is non-interactive:UserWarning"]
24 changes: 12 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Remi Lafage <remi.lafage@onera.fr>
Lucas Alber <lucasd.alber@gmail.com>
Paul Saves <paul.saves@onera.fr>
This package is distributed under New BSD license.
"""

Expand Down Expand Up @@ -33,19 +33,19 @@
"""

LONG_DESCRIPTION = """
The surrogate modeling toolbox (SMT) is a Python package that contains
a collection of surrogate modeling methods, sampling techniques, and
benchmarking functions. This package provides a library of surrogate
models that is simple to use and facilitates the implementation of additional methods.
The surrogate modeling toolbox (SMT) is a Python package that contains \
a collection of surrogate modeling methods, sampling techniques, and \
benchmarking functions. This package provides a library of surrogate \
models that is simple to use and facilitates the implementation of additional methods. \
SMT is different from existing surrogate modeling libraries because of
its emphasis on derivatives, including training derivatives used for
gradient-enhanced modeling, prediction derivatives, and derivatives
with respect to the training data. It also includes new surrogate models
that are not available elsewhere: kriging by partial-least squares reduction
SMT is different from existing surrogate modeling libraries because of \
its emphasis on derivatives, including training derivatives used for \
gradient-enhanced modeling, prediction derivatives, and derivatives \
with respect to the training data. It also includes new surrogate models \
that are not available elsewhere: kriging by partial-least squares reduction \
and energy-minimizing spline interpolation.
SMT 2.0 adds the capability to handle mixed-variable surrogate models
SMT 2.0 adds the capability to handle mixed-variable surrogate models \
and hierarchical variables.
"""

Expand Down Expand Up @@ -111,7 +111,7 @@
"scikit-learn",
"pyDOE3",
"scipy",
"jenn",
"jenn",
],
extras_require={
"numba": [ # pip install smt[numba]
Expand Down
12 changes: 8 additions & 4 deletions smt/applications/mfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def __init__(self, nlevel, xlimits=None, design_space=None, random_state=None):
)
elif xlimits is not None and design_space is not None:
raise ValueError(
"Use either design_space for mixed inputs or xlimits for continuous one. Please avoid overspecification."
"Use either design_space for mixed inputs or xlimits for continuous one. \
Please avoid overspecification."
)
elif xlimits is not None:
self.design_space = ensure_design_space(xlimits=xlimits)
Expand Down Expand Up @@ -243,7 +244,8 @@ def _new_train_init(self):
if self.name in ["MFKPLS", "MFKPLSK"]:
_pls = pls(self.options["n_comp"])

# As of sklearn 0.24.1 PLS with zeroed outputs raises an exception while sklearn 0.23 returns zeroed x_rotations
# As of sklearn 0.24.1 PLS with zeroed outputs raises an exception
# while sklearn 0.23 returns zeroed x_rotations
# For now the try/except below is a workaround to restore the 0.23 behaviour
try:
# PLS is done on the highest fidelity identified by the key None
Expand Down Expand Up @@ -1027,7 +1029,8 @@ def _check_param(self):
self.options["theta0"] *= np.ones((1, n_param))
else:
raise ValueError(
"the length of theta0 (%s) should be equal to the number of dim (%s) or levels of fidelity (%s)."
"the length of theta0 (%s) should be equal to the number of dim (%s) \
or levels of fidelity (%s)."
% (len(self.options["theta0"]), n_param, self.nlvl)
)
else:
Expand All @@ -1050,7 +1053,8 @@ def _check_param(self):
self.options["noise0"][i] *= np.ones(self.nt_all[i])
else:
raise ValueError(
"for the level of fidelity %s, the length of noise0 (%s) should be equal to the number of observations (%s)."
"for the level of fidelity %s, the length of noise0 (%s) should be equal to \
the number of observations (%s)."
% (i, len(self.options["noise0"][i]), self.nt_all[i])
)
else:
Expand Down
3 changes: 2 additions & 1 deletion smt/applications/mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ def __init__(
"categorical_kernel"
] = MixIntKernelType.HOMO_HSPHERE
warnings.warn(
"Using MixedIntegerSurrogateModel integer model with Continuous Relaxation is not supported. Switched to homoscedastic hypersphere kernel instead."
"Using MixedIntegerSurrogateModel integer model with Continuous Relaxation is not supported. \
Switched to homoscedastic hypersphere kernel instead."
)
if self._surrogate.options["categorical_kernel"] is not None:
self._input_in_folded_space = False
Expand Down
6 changes: 3 additions & 3 deletions smt/applications/tests/test_mfk_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
@author: Vincent Drouet and Nathalie Bartoli
in order to validate the variance formula for multifidelity on the branin 2D function
Comparisons are based on the paper Le Gratiet et Cannamela 2015 :
Le Gratiet, L., & Cannamela, C. (2015).
Comparisons are based on the paper Le Gratiet et Cannamela 2015 :
Le Gratiet, L., & Cannamela, C. (2015).
Cokriging-based sequential design strategies using fast cross-validation
techniques for multi-fidelity computer codes. Technometrics, 57(3), 418-427.
https://doi.org/10.1080/00401706.2014.928233
Expand Down
30 changes: 20 additions & 10 deletions smt/examples/run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the LS model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the LS model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)


Expand Down Expand Up @@ -134,7 +135,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the QP model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the QP model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)


Expand Down Expand Up @@ -187,7 +189,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the Kriging model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the Kriging model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)


Expand Down Expand Up @@ -243,7 +246,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the KPLS model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the KPLS model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)

# Prediction of the derivatives with regards to each direction space
Expand Down Expand Up @@ -311,7 +315,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the KPLSK model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the KPLSK model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)


Expand Down Expand Up @@ -375,7 +380,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the GEKPLS1 model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the GEKPLS1 model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)


Expand Down Expand Up @@ -439,7 +445,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the GEKPLS2 model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the GEKPLS2 model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)


Expand Down Expand Up @@ -510,7 +517,8 @@
plt.setp(axarr[3, 2].get_xticklabels(), visible=False)
plt.setp(axarr[3, 2].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the RBF model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:10"
"Validation of the RBF model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:10"
)

# Prediction of the derivatives with regards to each direction space
Expand Down Expand Up @@ -596,7 +604,8 @@
plt.setp(axarr[2, 0].get_xticklabels(), visible=False)
plt.setp(axarr[2, 0].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the RMTB model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:3"
"Validation of the RMTB model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:3"
)

# Prediction of the derivatives with regards to each direction space
Expand Down Expand Up @@ -658,7 +667,8 @@
plt.setp(axarr[2, 0].get_xticklabels(), visible=False)
plt.setp(axarr[2, 0].get_yticklabels(), visible=False)
plt.suptitle(
"Validation of the RMTC model (from left to right then from top to bottom): validation of the prediction model and the i-th prediction of the derivative---i=1:3"
"Validation of the RMTC model (from left to right then from top to bottom): \
validation of the prediction model and the i-th prediction of the derivative---i=1:3"
)

# Prediction of the derivatives with regards to each direction space
Expand Down
10 changes: 8 additions & 2 deletions smt/problems/cantilever_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
This package is distributed under New BSD license.
Cantilever beam problem from:
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design: comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition. American Society of Mechanical Engineers. June, 2016.
Cheng, G. H., Younis, A., Hajikolaei, K. H., and Wang, G. G. Trust Region Based Mode Pursuing Sampling Method for Global Optimization of High Dimensional Design Problems. Journal of Mechanical Design, 137(2). 2015.
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design:
comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition.
American Society of Mechanical Engineers. June, 2016.
Cheng, G. H., Younis, A., Hajikolaei, K. H., and Wang, G. G.
Trust Region Based Mode Pursuing Sampling Method for Global Optimization of High Dimensional Design Problems.
Journal of Mechanical Design, 137(2). 2015.
"""

import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion smt/problems/hierarchical_goldstein.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This package is distributed under New BSD license.
Cantilever beam problem from:
P. Saves, Y. Diouane, N. Bartoli, T. Lefebvre, and J. Morlier. A mixed-categorical correlation kernel for gaussian process, 2022
P. Saves, Y. Diouane, N. Bartoli, T. Lefebvre, and J. Morlier. A mixed-categorical correlation kernel
for gaussian process, 2022
"""

import numpy as np
Expand Down
5 changes: 3 additions & 2 deletions smt/problems/mixed_cantilever_beam.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
Author: P.Saves
Author: P.Saves
This package is distributed under New BSD license.
Cantilever beam problem from:
P. Saves, Y. Diouane, N. Bartoli, T. Lefebvre, and J. Morlier. A mixed-categorical correlation kernel for gaussian process, 2022
P. Saves, Y. Diouane, N. Bartoli, T. Lefebvre, and J. Morlier.
A mixed-categorical correlation kernel for gaussian process, 2022
"""

import numpy as np
Expand Down
9 changes: 5 additions & 4 deletions smt/problems/neural_network.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
Author: P.Saves
Author: P.Saves
This package is distributed under New BSD license.
Multi-Layer Perceptron problem from:
C. Audet, E. Hall e-Hannan, and S. Le Digabel. A general mathematical framework for constrained mixed-variable blackbox optimization problems with meta and categorical variables. Operations Research Forum,499
4:137, 2023.
"""
C. Audet, E. Hall e-Hannan, and S. Le Digabel. A general mathematical framework for
constrained mixed-variable blackbox optimization problems with meta and categorical variables.
Operations Research Forum,4994:137, 2023.
"""

import numpy as np

Expand Down
5 changes: 4 additions & 1 deletion smt/problems/robot_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
This package is distributed under New BSD license.
Robot arm problem from:
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design: comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition. American Society of Mechanical Engineers. June, 2016.
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design:
comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition.
American Society of Mechanical Engineers. June, 2016.
An, J., and Owen, A. Quasi-Regression. Journal of complexity, 17(4), pp. 588-607, 2001.
"""

Expand Down
10 changes: 8 additions & 2 deletions smt/problems/torsion_vibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
This package is distributed under New BSD license.
Torsion vibration problem from:
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design: comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition. American Society of Mechanical Engineers. June, 2016.
Wang, L., Beeson, D., Wiggs, G., and Rayasam, M. A Comparison of Metamodeling Methods Using Practical Industry Requirements. In Proceedings of the 47th AIAA/ASME/ASCE/AHS/ASC structures, structural dynamics, and materials conference, Newport, RI, pp. AIAA 2006-1811.
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design:
comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition.
American Society of Mechanical Engineers. June, 2016.
Wang, L., Beeson, D., Wiggs, G., and Rayasam, M.
A Comparison of Metamodeling Methods Using Practical Industry Requirements.
In Proceedings of the 47th AIAA/ASME/ASCE/AHS/ASC structures, structural dynamics,
and materials conference, Newport, RI, pp. AIAA 2006-1811.
"""

import numpy as np
Expand Down
8 changes: 6 additions & 2 deletions smt/problems/water_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
This package is distributed under New BSD license.
Water flow problem from:
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design: comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition. American Society of Mechanical Engineers. June, 2016.
Morris, M. D., Mitchell, T. J., and Ylvisaker, D. Bayesian Design and Analysis of Computer Experiments: Use of Derivatives in Surface Prediction. Technometrics, 35(3), pp. 243-255. 1993.
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design:
comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition.
American Society of Mechanical Engineers. June, 2016.
Morris, M. D., Mitchell, T. J., and Ylvisaker, D. Bayesian Design and Analysis of Computer Experiments:
Use of Derivatives in Surface Prediction. Technometrics, 35(3), pp. 243-255. 1993.
"""

import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion smt/problems/water_flow_lfidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Dr. John T. Hwang <hwangjt@umich.edu>
Water flow problem from:
Xiong, S., Qian, P. Z., & Wu, C. J. (2013). Sequential design and analysis of high-accuracy and low-accuracy computer codes. Technometrics, 55(1), 37-46.
Xiong, S., Qian, P. Z., & Wu, C. J. (2013). Sequential design and analysis of high-accuracy
and low-accuracy computer codes. Technometrics, 55(1), 37-46.
"""

import numpy as np
Expand Down
8 changes: 6 additions & 2 deletions smt/problems/welded_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
This package is distributed under New BSD license.
Welded beam problem from:
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design: comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition. American Society of Mechanical Engineers. June, 2016.
Deb, K. An Efficient Constraint Handling Method for Genetic Algorithms. Computer methods in applied mechanics and engineering, 186(2), pp. 311-338. 2000.
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design:
comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition.
American Society of Mechanical Engineers. June, 2016.
Deb, K. An Efficient Constraint Handling Method for Genetic Algorithms.
Computer methods in applied mechanics and engineering, 186(2), pp. 311-338. 2000.
"""

import numpy as np
Expand Down
5 changes: 4 additions & 1 deletion smt/problems/wing_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
This package is distributed under New BSD license.
Aircraft wing weight problem from:
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design: comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition. American Society of Mechanical Engineers. June, 2016.
Liu, H., Xu, S., & Wang, X. Sampling strategies and metamodeling techniques for engineering design:
comparison and application. In ASME Turbo Expo 2016: Turbomachinery Technical Conference and Exposition.
American Society of Mechanical Engineers. June, 2016.
Forrester, A., Sobester, A., and Keane, A., 2008,
Engineering Design Via Surrogate Modelling: A Practical Guide, John Wiley & Sons, United Kingdom.
"""
Expand Down
3 changes: 2 additions & 1 deletion smt/sampling_methods/pydoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def _initialize(self, **kwargs):
"reduction",
types=int,
default=2,
desc="Reduction factor (bigger than 1). Larger `reduction` means fewer experiments in the design and more possible complementary designs",
desc="Reduction factor (bigger than 1). Larger `reduction` means fewer experiments \
in the design and more possible complementary designs",
)

def _compute_doe(self):
Expand Down
Loading

0 comments on commit 8fc434b

Please sign in to comment.