From 4d80c52ce2a142b45497e8007e8f608bfca29880 Mon Sep 17 00:00:00 2001 From: Saves Paul Date: Wed, 20 Mar 2024 15:11:11 +0100 Subject: [PATCH] Rust formatting (#540) --- smt/applications/__init__.py | 6 +- smt/applications/application.py | 4 +- smt/applications/ego.py | 9 +- smt/applications/mfk.py | 20 ++-- smt/applications/mfkpls.py | 1 - smt/applications/mfkplsk.py | 2 +- smt/applications/mixed_integer.py | 8 +- smt/applications/moe.py | 3 +- smt/applications/tests/test_ego.py | 47 ++++---- smt/applications/tests/test_mfk.py | 14 ++- smt/applications/tests/test_mfk_1fidelity.py | 11 +- .../tests/test_mfk_mfkpls_mixed.py | 14 +-- smt/applications/tests/test_mfk_variance.py | 5 +- smt/applications/tests/test_mfkpls.py | 13 ++- smt/applications/tests/test_mfkplsk.py | 13 ++- smt/applications/tests/test_mixed_integer.py | 110 +++++++++--------- smt/applications/tests/test_moe.py | 18 +-- smt/applications/tests/test_vfm.py | 16 ++- .../learning_airfoil_parameters.py | 3 +- smt/examples/airfoil_parameters/run_genn.py | 2 +- smt/examples/b777_engine/b777_engine.py | 5 +- .../b777_engine/run_b777_engine_rmtb.py | 2 +- .../b777_engine/run_b777_engine_rmtc.py | 2 +- smt/examples/one_D_step/one_D_step.py | 2 +- .../one_D_step/run_one_D_step_rmtb.py | 2 +- .../one_D_step/run_one_D_step_rmtc.py | 2 +- smt/examples/rans_crm_wing/rans_crm_wing.py | 3 +- .../rans_crm_wing/run_rans_crm_wing_rmtb.py | 2 +- .../rans_crm_wing/run_rans_crm_wing_rmtc.py | 2 +- smt/examples/run_examples.py | 8 +- smt/problems/__init__.py | 18 +-- smt/problems/hierarchical_goldstein.py | 4 +- smt/problems/mixed_cantilever_beam.py | 2 +- smt/problems/ndim_cantilever_beam.py | 4 +- smt/problems/ndim_robot_arm.py | 2 +- smt/problems/ndim_rosenbrock.py | 2 +- smt/problems/ndim_step_function.py | 2 +- smt/problems/neural_network.py | 4 +- smt/problems/problem.py | 3 +- smt/problems/reduced_problem.py | 2 +- smt/problems/tests/test_problem_examples.py | 26 +++-- smt/problems/welded_beam.py | 1 + smt/sampling_methods/__init__.py | 6 +- smt/sampling_methods/lhs.py | 4 +- smt/sampling_methods/pydoe.py | 5 +- smt/sampling_methods/sampling_method.py | 1 + .../tests/test_fullfactorial.py | 1 + smt/sampling_methods/tests/test_lhs.py | 1 + smt/sampling_methods/tests/test_pydoe.py | 1 + .../tests/test_sampling_method_examples.py | 14 +-- .../tests/test_scaled_sampling_methods.py | 1 + smt/surrogate_models/gpx.py | 4 +- smt/surrogate_models/idw.py | 4 +- smt/surrogate_models/ls.py | 2 +- smt/surrogate_models/mgp.py | 5 +- smt/surrogate_models/qp.py | 1 + smt/surrogate_models/rbf.py | 7 +- smt/surrogate_models/rmtb.py | 4 +- smt/surrogate_models/rmtc.py | 4 +- smt/surrogate_models/rmts.py | 9 +- smt/surrogate_models/tests/test_gpx.py | 4 +- smt/surrogate_models/tests/test_kpls.py | 4 +- smt/surrogate_models/tests/test_krg_based.py | 3 +- smt/surrogate_models/tests/test_krg_noise.py | 1 + .../tests/test_krg_outputs.py | 4 +- .../tests/test_krg_predictions.py | 4 +- .../tests/test_krg_training.py | 21 ++-- smt/surrogate_models/tests/test_mgp.py | 4 +- smt/surrogate_models/tests/test_qp.py | 3 +- smt/surrogate_models/tests/test_rmts.py | 5 +- smt/surrogate_models/tests/test_sgp.py | 3 +- .../tests/test_surrogate_model_examples.py | 60 +++++----- smt/tests/test_all.py | 27 +++-- smt/tests/test_array_outputs.py | 7 +- smt/tests/test_derivs.py | 18 ++- smt/tests/test_extrap.py | 9 +- smt/tests/test_high_dim.py | 13 +-- smt/tests/test_kpls_auto.py | 13 +-- smt/tests/test_low_dim.py | 15 ++- smt/tests/test_output_derivs.py | 12 +- smt/tests/test_problems.py | 21 ++-- smt/tests/test_training_derivs.py | 13 +-- smt/utils/caching.py | 2 +- smt/utils/design_space.py | 17 +-- smt/utils/krg_sampling.py | 3 +- smt/utils/kriging.py | 8 +- smt/utils/linear_solvers.py | 5 +- smt/utils/misc.py | 3 +- smt/utils/neural_net/data.py | 5 +- smt/utils/neural_net/model.py | 12 +- smt/utils/printer.py | 2 +- smt/utils/sm_test_case.py | 3 +- smt/utils/test/test_design_space.py | 16 +-- smt/utils/test/test_kriging_sampling_utils.py | 8 +- smt/utils/test/test_misc_utils.py | 4 +- 95 files changed, 440 insertions(+), 405 deletions(-) diff --git a/smt/applications/__init__.py b/smt/applications/__init__.py index a470d8e06..c14b199a0 100644 --- a/smt/applications/__init__.py +++ b/smt/applications/__init__.py @@ -1,9 +1,9 @@ -from .vfm import VFM -from .moe import MOE, MOESurrogateModel +from .ego import EGO, Evaluator from .mfk import MFK, NestedLHS from .mfkpls import MFKPLS from .mfkplsk import MFKPLSK -from .ego import EGO, Evaluator +from .moe import MOE, MOESurrogateModel +from .vfm import VFM __all__ = [ "VFM", diff --git a/smt/applications/application.py b/smt/applications/application.py index 40e01c542..11be6787c 100644 --- a/smt/applications/application.py +++ b/smt/applications/application.py @@ -4,11 +4,11 @@ This package is distributed under New BSD license. """ +from smt.surrogate_models import GEKPLS, KPLS, KPLSK, KRG, LS, MGP, QP from smt.utils.options_dictionary import OptionsDictionary -from smt.surrogate_models import LS, QP, KPLS, KRG, KPLSK, GEKPLS, MGP try: - from smt.surrogate_models import IDW, RBF, RMTC, RMTB + from smt.surrogate_models import IDW, RBF, RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/applications/ego.py b/smt/applications/ego.py index 7fab37d42..8e6155088 100644 --- a/smt/applications/ego.py +++ b/smt/applications/ego.py @@ -5,24 +5,23 @@ """ -import numpy as np - from types import FunctionType -from scipy.stats import norm +import numpy as np from scipy.optimize import minimize +from scipy.stats import norm -from smt.surrogate_models import KPLS, KRG, KPLSK, MGP, GEKPLS from smt.applications.application import SurrogateBasedApplication from smt.applications.mixed_integer import ( MixedIntegerContext, MixedIntegerSamplingMethod, ) +from smt.sampling_methods import LHS +from smt.surrogate_models import GEKPLS, KPLS, KPLSK, KRG, MGP from smt.utils.design_space import ( BaseDesignSpace, DesignSpace, ) -from smt.sampling_methods import LHS class Evaluator(object): diff --git a/smt/applications/mfk.py b/smt/applications/mfk.py index 7ddbdfd79..35bdd0f63 100644 --- a/smt/applications/mfk.py +++ b/smt/applications/mfk.py @@ -8,34 +8,32 @@ Adapted on January 2021 by Andres Lopez-Lopera to the new SMT version """ -from copy import deepcopy import warnings +from copy import deepcopy + import numpy as np -from scipy.linalg import solve_triangular from scipy import linalg +from scipy.linalg import solve_triangular from scipy.spatial.distance import cdist - from sklearn.cross_decomposition import PLSRegression as pls +from smt.sampling_methods import LHS from smt.surrogate_models.krg_based import ( KrgBased, MixIntKernelType, + compute_n_param, ) - -from smt.sampling_methods import LHS +from smt.utils.design_space import ensure_design_space from smt.utils.kriging import ( - cross_distances, componentwise_distance, + compute_X_cont, + cross_distances, + cross_levels, differences, gower_componentwise_distances, - cross_levels, - compute_X_cont, ) from smt.utils.misc import standardization -from smt.surrogate_models.krg_based import compute_n_param -from smt.utils.design_space import ensure_design_space - class NestedLHS(object): def __init__(self, nlevel, xlimits=None, design_space=None, random_state=None): diff --git a/smt/applications/mfkpls.py b/smt/applications/mfkpls.py index 39397f22c..d20b2a6c2 100644 --- a/smt/applications/mfkpls.py +++ b/smt/applications/mfkpls.py @@ -10,7 +10,6 @@ """ import numpy as np - from sklearn.cross_decomposition import PLSRegression as pls from sklearn.metrics.pairwise import check_pairwise_arrays diff --git a/smt/applications/mfkplsk.py b/smt/applications/mfkplsk.py index 85086b49c..9f025e4c4 100644 --- a/smt/applications/mfkplsk.py +++ b/smt/applications/mfkplsk.py @@ -10,8 +10,8 @@ Adapted on January 2021 by Andres Lopez-Lopera to the new SMT version """ -from smt.utils.kriging import componentwise_distance from smt.applications import MFKPLS +from smt.utils.kriging import componentwise_distance class MFKPLSK(MFKPLS): diff --git a/smt/applications/mixed_integer.py b/smt/applications/mixed_integer.py index 48cabd599..c1e76ad9a 100644 --- a/smt/applications/mixed_integer.py +++ b/smt/applications/mixed_integer.py @@ -4,17 +4,19 @@ This package is distributed under New BSD license. """ +import warnings + import numpy as np -from smt.surrogate_models.surrogate_model import SurrogateModel + from smt.sampling_methods.sampling_method import SamplingMethod -from smt.utils.checks import ensure_2d_array from smt.surrogate_models.krg_based import KrgBased, MixIntKernelType +from smt.surrogate_models.surrogate_model import SurrogateModel +from smt.utils.checks import ensure_2d_array from smt.utils.design_space import ( BaseDesignSpace, CategoricalVariable, ensure_design_space, ) -import warnings class MixedIntegerSamplingMethod(SamplingMethod): diff --git a/smt/applications/moe.py b/smt/applications/moe.py index f74b3f575..ff8d8ac20 100644 --- a/smt/applications/moe.py +++ b/smt/applications/moe.py @@ -11,9 +11,8 @@ # TODO : documentation import numpy as np - -from sklearn.mixture import GaussianMixture from scipy.stats import multivariate_normal +from sklearn.mixture import GaussianMixture from smt.applications.application import SurrogateBasedApplication from smt.surrogate_models.surrogate_model import SurrogateModel diff --git a/smt/applications/tests/test_ego.py b/smt/applications/tests/test_ego.py index 21e58e77d..0d1a8bc32 100644 --- a/smt/applications/tests/test_ego.py +++ b/smt/applications/tests/test_ego.py @@ -6,33 +6,32 @@ import os import unittest -import numpy as np +from multiprocessing import Pool from sys import argv +import numpy as np +import smt.utils.design_space as ds from smt.applications import EGO from smt.applications.ego import Evaluator -from smt.utils.sm_test_case import SMTestCase +from smt.applications.mixed_integer import ( + MixedIntegerContext, + MixedIntegerSamplingMethod, +) from smt.problems import Branin, Rosenbrock -from smt.sampling_methods import FullFactorial -from multiprocessing import Pool -from smt.sampling_methods import LHS +from smt.sampling_methods import LHS, FullFactorial from smt.surrogate_models import ( - KRG, GEKPLS, KPLS, - MixIntKernelType, + KRG, + CategoricalVariable, DesignSpace, - OrdinalVariable, FloatVariable, - CategoricalVariable, IntegerVariable, + MixIntKernelType, + OrdinalVariable, ) -from smt.applications.mixed_integer import ( - MixedIntegerContext, - MixedIntegerSamplingMethod, -) -import smt.utils.design_space as ds +from smt.utils.sm_test_case import SMTestCase try: import matplotlib @@ -1084,11 +1083,12 @@ def test_examples(self): @staticmethod def run_ego_example(): + import matplotlib.pyplot as plt import numpy as np + from smt.applications import EGO from smt.surrogate_models import KRG from smt.utils.design_space import DesignSpace - import matplotlib.pyplot as plt def function_test_1d(x): # function xsinx @@ -1173,18 +1173,18 @@ def function_test_1d(x): @staticmethod def run_ego_mixed_integer_example(): + import matplotlib.pyplot as plt import numpy as np + from smt.applications import EGO from smt.applications.mixed_integer import MixedIntegerContext - from smt.surrogate_models import MixIntKernelType + from smt.surrogate_models import KRG, MixIntKernelType from smt.utils.design_space import ( - DesignSpace, CategoricalVariable, + DesignSpace, FloatVariable, IntegerVariable, ) - import matplotlib.pyplot as plt - from smt.surrogate_models import KRG # Regarding the interface, the function to be optimized should handle # categorical values as index values in the enumeration type specification. @@ -1271,13 +1271,13 @@ def function_test_mixed_integer(X): @staticmethod def run_ego_parallel_example(): + import matplotlib.pyplot as plt import numpy as np + from smt.applications import EGO from smt.applications.ego import Evaluator from smt.surrogate_models import KRG, DesignSpace - import matplotlib.pyplot as plt - def function_test_1d(x): # function xsinx import numpy as np @@ -1305,9 +1305,10 @@ class ParallelEvaluator(Evaluator): def run(self, fun, x): n_thread = 5 # Caveat: import are made here due to SMT documentation building process - import numpy as np - from sys import version_info from multiprocessing.pool import ThreadPool + from sys import version_info + + import numpy as np if version_info.major == 2: return fun(x) diff --git a/smt/applications/tests/test_mfk.py b/smt/applications/tests/test_mfk.py index 77a59a6ff..a3ada0640 100644 --- a/smt/applications/tests/test_mfk.py +++ b/smt/applications/tests/test_mfk.py @@ -6,6 +6,7 @@ """ import unittest + import numpy as np try: @@ -16,14 +17,14 @@ except ImportError: NO_MATPLOTLIB = True +from copy import deepcopy + +from smt.applications.mfk import MFK, NestedLHS from smt.problems import Sphere, TensorProduct from smt.sampling_methods import LHS, FullFactorial - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence from smt.utils.misc import compute_rms_error -from smt.applications.mfk import MFK, NestedLHS -from copy import deepcopy +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase print_output = False @@ -138,8 +139,9 @@ def test_mfk_derivs(self): @staticmethod def run_mfk_example(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np + from smt.applications.mfk import MFK, NestedLHS # low fidelity model diff --git a/smt/applications/tests/test_mfk_1fidelity.py b/smt/applications/tests/test_mfk_1fidelity.py index abc0bed78..3914ab64a 100644 --- a/smt/applications/tests/test_mfk_1fidelity.py +++ b/smt/applications/tests/test_mfk_1fidelity.py @@ -7,15 +7,15 @@ NO_MATPLOTLIB = True import unittest + import numpy as np +from smt.applications.mfk import MFK from smt.problems import TensorProduct from smt.sampling_methods import LHS - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence from smt.utils.misc import compute_rms_error -from smt.applications.mfk import MFK +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase print_output = False @@ -61,8 +61,9 @@ def test_mfk_1fidelity(self): @staticmethod def run_mfk_example_1fidelity(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np + from smt.applications.mfk import MFK, NestedLHS # Consider only 1 fidelity level diff --git a/smt/applications/tests/test_mfk_mfkpls_mixed.py b/smt/applications/tests/test_mfk_mfkpls_mixed.py index d96bd6fc6..4604b9d98 100644 --- a/smt/applications/tests/test_mfk_mfkpls_mixed.py +++ b/smt/applications/tests/test_mfk_mfkpls_mixed.py @@ -7,6 +7,7 @@ """ import unittest + import numpy as np try: @@ -19,28 +20,23 @@ import numpy.linalg as npl -from smt.applications.mfkpls import MFKPLS +from smt.applications import NestedLHS from smt.applications.mfk import MFK - +from smt.applications.mfkpls import MFKPLS from smt.applications.mixed_integer import ( MixedIntegerSamplingMethod, ) - -from smt.applications import NestedLHS - from smt.sampling_methods import LHS - from smt.surrogate_models import ( - KRG, KPLS, + KRG, MixIntKernelType, ) - from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, FloatVariable, IntegerVariable, - CategoricalVariable, ) diff --git a/smt/applications/tests/test_mfk_variance.py b/smt/applications/tests/test_mfk_variance.py index f2fcf3416..cccbcb01d 100644 --- a/smt/applications/tests/test_mfk_variance.py +++ b/smt/applications/tests/test_mfk_variance.py @@ -12,11 +12,12 @@ https://doi.org/10.1080/00401706.2014.928233 """ +import unittest + import numpy as np + from smt.applications.mfk import MFK, NestedLHS from smt.sampling_methods import LHS -import unittest - from smt.utils.sm_test_case import SMTestCase print_output = True diff --git a/smt/applications/tests/test_mfkpls.py b/smt/applications/tests/test_mfkpls.py index 69938ddf1..7a501e203 100644 --- a/smt/applications/tests/test_mfkpls.py +++ b/smt/applications/tests/test_mfkpls.py @@ -16,16 +16,16 @@ NO_MATPLOTLIB = True import unittest +from copy import deepcopy + import numpy as np +from smt.applications.mfkpls import MFKPLS from smt.problems import Sphere, TensorProduct from smt.sampling_methods import LHS, FullFactorial - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence from smt.utils.misc import compute_rms_error -from smt.applications.mfkpls import MFKPLS -from copy import deepcopy +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase print_output = False @@ -135,8 +135,9 @@ def test_mfkpls_derivs(self): @staticmethod def run_mfkpls_example(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np + from smt.applications.mfk import NestedLHS from smt.applications.mfkpls import MFKPLS diff --git a/smt/applications/tests/test_mfkplsk.py b/smt/applications/tests/test_mfkplsk.py index 480ac6ccd..0cc26bfde 100644 --- a/smt/applications/tests/test_mfkplsk.py +++ b/smt/applications/tests/test_mfkplsk.py @@ -16,16 +16,16 @@ NO_MATPLOTLIB = True import unittest +from copy import deepcopy + import numpy as np +from smt.applications.mfkplsk import MFKPLSK from smt.problems import Sphere, TensorProduct from smt.sampling_methods import LHS, FullFactorial - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence from smt.utils.misc import compute_rms_error -from smt.applications.mfkplsk import MFKPLSK -from copy import deepcopy +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase print_output = False @@ -140,8 +140,9 @@ def test_mfkplsk_derivs(self): @staticmethod def run_mfkplsk_example(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np + from smt.applications.mfk import NestedLHS from smt.applications.mfkplsk import MFKPLSK diff --git a/smt/applications/tests/test_mixed_integer.py b/smt/applications/tests/test_mixed_integer.py index e9cfddaf9..a2b971be1 100644 --- a/smt/applications/tests/test_mixed_integer.py +++ b/smt/applications/tests/test_mixed_integer.py @@ -3,10 +3,11 @@ @author: psaves """ -import unittest -import numpy as np import itertools import os +import unittest + +import numpy as np try: import matplotlib @@ -16,29 +17,28 @@ except ImportError: NO_MATPLOTLIB = True +import smt.utils.design_space as ds from smt.applications.mixed_integer import ( MixedIntegerContext, - MixedIntegerSamplingMethod, MixedIntegerKrigingModel, + MixedIntegerSamplingMethod, ) -from smt.problems import Sphere, HierarchicalGoldstein, HierarchicalNeuralNetwork -from smt.utils.design_space import ( - DesignSpace, - FloatVariable, - IntegerVariable, - OrdinalVariable, - CategoricalVariable, - HAS_CONFIG_SPACE, -) -import smt.utils.design_space as ds - +from smt.problems import HierarchicalGoldstein, HierarchicalNeuralNetwork, Sphere from smt.sampling_methods import LHS from smt.surrogate_models import ( - KRG, KPLS, + KRG, QP, - MixIntKernelType, MixHrcKernelType, + MixIntKernelType, +) +from smt.utils.design_space import ( + HAS_CONFIG_SPACE, + CategoricalVariable, + DesignSpace, + FloatVariable, + IntegerVariable, + OrdinalVariable, ) @@ -467,17 +467,17 @@ def test_examples(self): self.run_hierarchical_design_space_example() # works only with config space impl def run_mixed_integer_lhs_example(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from matplotlib import colors + from smt.applications.mixed_integer import MixedIntegerSamplingMethod + from smt.sampling_methods import LHS from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, FloatVariable, - CategoricalVariable, ) - from smt.sampling_methods import LHS - from smt.applications.mixed_integer import MixedIntegerSamplingMethod float_var = FloatVariable(0, 4) cat_var = CategoricalVariable(["blue", "red"]) @@ -501,11 +501,11 @@ def run_mixed_integer_lhs_example(self): plt.show() def run_mixed_integer_qp_example(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import QP from smt.applications.mixed_integer import MixedIntegerSurrogateModel + from smt.surrogate_models import QP from smt.utils.design_space import DesignSpace, IntegerVariable xt = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) @@ -535,13 +535,14 @@ def run_mixed_integer_qp_example(self): def run_mixed_integer_context_example(self): import matplotlib.pyplot as plt - from smt.surrogate_models import KRG + from smt.applications.mixed_integer import MixedIntegerContext + from smt.surrogate_models import KRG from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, FloatVariable, IntegerVariable, - CategoricalVariable, ) design_space = DesignSpace( @@ -743,15 +744,16 @@ def test_hierarchical_variables_Goldstein(self): def run_mixed_discrete_design_space_example(self): import numpy as np + + from smt.applications.mixed_integer import MixedIntegerSamplingMethod + from smt.sampling_methods import LHS from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, FloatVariable, IntegerVariable, OrdinalVariable, - CategoricalVariable, ) - from smt.sampling_methods import LHS - from smt.applications.mixed_integer import MixedIntegerSamplingMethod ds = DesignSpace( [ @@ -789,19 +791,20 @@ def run_mixed_discrete_design_space_example(self): def run_hierarchical_design_space_example(self): import numpy as np + + from smt.applications.mixed_integer import ( + MixedIntegerKrigingModel, + MixedIntegerSamplingMethod, + ) + from smt.sampling_methods import LHS + from smt.surrogate_models import KRG, MixHrcKernelType, MixIntKernelType from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, FloatVariable, IntegerVariable, OrdinalVariable, - CategoricalVariable, - ) - from smt.applications.mixed_integer import ( - MixedIntegerKrigingModel, - MixedIntegerSamplingMethod, ) - from smt.surrogate_models import MixIntKernelType, MixHrcKernelType, KRG - from smt.sampling_methods import LHS ds = DesignSpace( [ @@ -1082,18 +1085,19 @@ def test_hierarchical_design_space_example_all_categorical_decreed(self): def run_hierarchical_variables_Goldstein(self): import numpy as np - from smt.utils.design_space import ( - DesignSpace, - CategoricalVariable, - IntegerVariable, - FloatVariable, - ) + from smt.applications.mixed_integer import ( MixedIntegerKrigingModel, MixedIntegerSamplingMethod, ) - from smt.surrogate_models import MixIntKernelType, MixHrcKernelType, KRG from smt.sampling_methods import LHS + from smt.surrogate_models import KRG, MixHrcKernelType, MixIntKernelType + from smt.utils.design_space import ( + CategoricalVariable, + DesignSpace, + FloatVariable, + IntegerVariable, + ) def f_hv(X): import numpy as np @@ -1865,16 +1869,16 @@ def test_mixed_gower_3D(self): self.assertTrue(eq_check) def run_mixed_gower_example(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import KRG, MixIntKernelType from smt.applications.mixed_integer import ( MixedIntegerKrigingModel, ) + from smt.surrogate_models import KRG, MixIntKernelType from smt.utils.design_space import ( - DesignSpace, CategoricalVariable, + DesignSpace, FloatVariable, ) @@ -1996,16 +2000,16 @@ def run_mixed_gower_example(self): plt.show() def run_mixed_cs_example(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import KRG, MixIntKernelType from smt.applications.mixed_integer import ( MixedIntegerKrigingModel, ) + from smt.surrogate_models import KRG, MixIntKernelType from smt.utils.design_space import ( - DesignSpace, CategoricalVariable, + DesignSpace, FloatVariable, ) @@ -2127,14 +2131,14 @@ def run_mixed_cs_example(self): plt.show() def run_mixed_homo_gaussian_example(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import KRG, MixIntKernelType from smt.applications.mixed_integer import MixedIntegerKrigingModel + from smt.surrogate_models import KRG, MixIntKernelType from smt.utils.design_space import ( - DesignSpace, CategoricalVariable, + DesignSpace, FloatVariable, ) @@ -2256,14 +2260,14 @@ def run_mixed_homo_gaussian_example(self): plt.show() def run_mixed_homo_hyp_example(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import KRG, MixIntKernelType from smt.applications.mixed_integer import MixedIntegerKrigingModel + from smt.surrogate_models import KRG, MixIntKernelType from smt.utils.design_space import ( - DesignSpace, CategoricalVariable, + DesignSpace, FloatVariable, ) diff --git a/smt/applications/tests/test_moe.py b/smt/applications/tests/test_moe.py index 912cc1d94..a4a2fa501 100644 --- a/smt/applications/tests/test_moe.py +++ b/smt/applications/tests/test_moe.py @@ -13,15 +13,16 @@ NO_MATPLOTLIB = True import unittest -import numpy as np from sys import argv +import numpy as np + from smt.applications import MOE, MOESurrogateModel -from smt.utils.sm_test_case import SMTestCase from smt.problems import Branin, LpNorm -from smt.sampling_methods import FullFactorial, LHS -from smt.utils.misc import compute_rms_error +from smt.sampling_methods import LHS, FullFactorial from smt.surrogate_models import RMTB, RMTC +from smt.utils.misc import compute_rms_error +from smt.utils.sm_test_case import SMTestCase class TestMOE(SMTestCase): @@ -389,10 +390,11 @@ def test_bad_allow_value(self): @staticmethod def run_moe_example_1d(): + import matplotlib.pyplot as plt import numpy as np + from smt.applications import MOE from smt.sampling_methods import FullFactorial - import matplotlib.pyplot as plt nt = 35 @@ -444,14 +446,14 @@ def function_test_1d(x): @staticmethod def run_moe_example_2d(): + import matplotlib.pyplot as plt import numpy as np + from matplotlib import colors + from smt.applications import MOE from smt.problems import LpNorm from smt.sampling_methods import FullFactorial - import matplotlib.pyplot as plt - from matplotlib import colors - ndim = 2 nt = 200 ne = 200 diff --git a/smt/applications/tests/test_vfm.py b/smt/applications/tests/test_vfm.py index d542211a4..dad6d4106 100644 --- a/smt/applications/tests/test_vfm.py +++ b/smt/applications/tests/test_vfm.py @@ -15,18 +15,16 @@ NO_MATPLOTLIB = True import numpy as np -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence -from smt.problems import WaterFlowLFidelity, WaterFlow -from smt.sampling_methods import LHS from smt.applications import VFM -from smt.utils.misc import compute_rms_error - - from smt.examples.rans_crm_wing.rans_crm_wing import ( get_rans_crm_wing, ) +from smt.problems import WaterFlow, WaterFlowLFidelity +from smt.sampling_methods import LHS +from smt.utils.misc import compute_rms_error +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase def setupCRM(LF_candidate="QP", Bridge_candidate="KRG", type_bridge="Additive"): @@ -121,9 +119,9 @@ def run_vfm_example(self): import matplotlib.pyplot as plt import numpy as np - from smt.problems import WaterFlowLFidelity, WaterFlow - from smt.sampling_methods import LHS from smt.applications import VFM + from smt.problems import WaterFlow, WaterFlowLFidelity + from smt.sampling_methods import LHS # Problem set up ndim = 8 diff --git a/smt/examples/airfoil_parameters/learning_airfoil_parameters.py b/smt/examples/airfoil_parameters/learning_airfoil_parameters.py index a0803cf74..c57062fb0 100644 --- a/smt/examples/airfoil_parameters/learning_airfoil_parameters.py +++ b/smt/examples/airfoil_parameters/learning_airfoil_parameters.py @@ -1,6 +1,7 @@ +import csv import os + import numpy as np -import csv WORKDIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/smt/examples/airfoil_parameters/run_genn.py b/smt/examples/airfoil_parameters/run_genn.py index 5db4f04ca..390ac5efa 100644 --- a/smt/examples/airfoil_parameters/run_genn.py +++ b/smt/examples/airfoil_parameters/run_genn.py @@ -3,13 +3,13 @@ """ import numpy as np +from sklearn.model_selection import train_test_split from smt.examples.airfoil_parameters.learning_airfoil_parameters import ( load_cd_training_data, load_NACA4412_modeshapes, plot_predictions, ) -from sklearn.model_selection import train_test_split from smt.surrogate_models.genn import GENN x, y, dy = load_cd_training_data() diff --git a/smt/examples/b777_engine/b777_engine.py b/smt/examples/b777_engine/b777_engine.py index fd068e3b3..b14bc262d 100644 --- a/smt/examples/b777_engine/b777_engine.py +++ b/smt/examples/b777_engine/b777_engine.py @@ -1,6 +1,7 @@ -import numpy as np import os +import numpy as np + def get_b777_engine(): this_dir = os.path.split(__file__)[0] @@ -18,8 +19,8 @@ def get_b777_engine(): def plot_b777_engine(xt, yt, limits, interp): - import numpy as np import matplotlib + import numpy as np matplotlib.use("Agg") import matplotlib.pyplot as plt diff --git a/smt/examples/b777_engine/run_b777_engine_rmtb.py b/smt/examples/b777_engine/run_b777_engine_rmtb.py index 75507ccd5..6f347086c 100644 --- a/smt/examples/b777_engine/run_b777_engine_rmtb.py +++ b/smt/examples/b777_engine/run_b777_engine_rmtb.py @@ -1,5 +1,5 @@ -from smt.surrogate_models import RMTB from smt.examples.b777_engine.b777_engine import get_b777_engine, plot_b777_engine +from smt.surrogate_models import RMTB xt, yt, dyt_dxt, xlimits = get_b777_engine() diff --git a/smt/examples/b777_engine/run_b777_engine_rmtc.py b/smt/examples/b777_engine/run_b777_engine_rmtc.py index 561edecb6..294171c61 100644 --- a/smt/examples/b777_engine/run_b777_engine_rmtc.py +++ b/smt/examples/b777_engine/run_b777_engine_rmtc.py @@ -1,5 +1,5 @@ -from smt.surrogate_models import RMTC from smt.examples.b777_engine.b777_engine import get_b777_engine, plot_b777_engine +from smt.surrogate_models import RMTC xt, yt, dyt_dxt, xlimits = get_b777_engine() diff --git a/smt/examples/one_D_step/one_D_step.py b/smt/examples/one_D_step/one_D_step.py index 13381f273..fce0dc768 100644 --- a/smt/examples/one_D_step/one_D_step.py +++ b/smt/examples/one_D_step/one_D_step.py @@ -65,8 +65,8 @@ def get_one_d_step(): def plot_one_d_step(xt, yt, limits, interp): - import numpy as np import matplotlib + import numpy as np matplotlib.use("Agg") import matplotlib.pyplot as plt diff --git a/smt/examples/one_D_step/run_one_D_step_rmtb.py b/smt/examples/one_D_step/run_one_D_step_rmtb.py index 04d4f0e8e..d7040975e 100644 --- a/smt/examples/one_D_step/run_one_D_step_rmtb.py +++ b/smt/examples/one_D_step/run_one_D_step_rmtb.py @@ -1,5 +1,5 @@ -from smt.surrogate_models import RMTB from smt.examples.one_D_step.one_D_step import get_one_d_step, plot_one_d_step +from smt.surrogate_models import RMTB xt, yt, xlimits = get_one_d_step() diff --git a/smt/examples/one_D_step/run_one_D_step_rmtc.py b/smt/examples/one_D_step/run_one_D_step_rmtc.py index 6381e6f32..c1ccca045 100644 --- a/smt/examples/one_D_step/run_one_D_step_rmtc.py +++ b/smt/examples/one_D_step/run_one_D_step_rmtc.py @@ -1,5 +1,5 @@ -from smt.surrogate_models import RMTC from smt.examples.one_D_step.one_D_step import get_one_d_step, plot_one_d_step +from smt.surrogate_models import RMTC xt, yt, xlimits = get_one_d_step() diff --git a/smt/examples/rans_crm_wing/rans_crm_wing.py b/smt/examples/rans_crm_wing/rans_crm_wing.py index 467f2caff..2b9cafb9c 100644 --- a/smt/examples/rans_crm_wing/rans_crm_wing.py +++ b/smt/examples/rans_crm_wing/rans_crm_wing.py @@ -1,6 +1,5 @@ import numpy as np - raw = np.array( [ [ @@ -339,8 +338,8 @@ def get_rans_crm_wing(): def plot_rans_crm_wing(xt, yt, limits, interp): - import numpy as np import matplotlib + import numpy as np matplotlib.use("Agg") import matplotlib.pyplot as plt diff --git a/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtb.py b/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtb.py index 3855a8481..c1c83a882 100644 --- a/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtb.py +++ b/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtb.py @@ -1,8 +1,8 @@ -from smt.surrogate_models import RMTB from smt.examples.rans_crm_wing.rans_crm_wing import ( get_rans_crm_wing, plot_rans_crm_wing, ) +from smt.surrogate_models import RMTB xt, yt, xlimits = get_rans_crm_wing() diff --git a/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtc.py b/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtc.py index 2bd5bfd57..cb41309ae 100644 --- a/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtc.py +++ b/smt/examples/rans_crm_wing/run_rans_crm_wing_rmtc.py @@ -1,8 +1,8 @@ -from smt.surrogate_models import RMTC from smt.examples.rans_crm_wing.rans_crm_wing import ( get_rans_crm_wing, plot_rans_crm_wing, ) +from smt.surrogate_models import RMTC xt, yt, xlimits = get_rans_crm_wing() diff --git a/smt/examples/run_examples.py b/smt/examples/run_examples.py index b9e6272c1..68ed8fff7 100644 --- a/smt/examples/run_examples.py +++ b/smt/examples/run_examples.py @@ -6,14 +6,14 @@ """ import numpy as np -from smt.utils.misc import compute_rms_error -from smt.problems import Sphere, NdimRobotArm +from smt.problems import NdimRobotArm, Sphere from smt.sampling_methods import LHS -from smt.surrogate_models import LS, QP, KPLS, KRG, KPLSK, GEKPLS, DesignSpace +from smt.surrogate_models import GEKPLS, KPLS, KPLSK, KRG, LS, QP, DesignSpace +from smt.utils.misc import compute_rms_error try: - from smt.surrogate_models import IDW, RBF, RMTC, RMTB + from smt.surrogate_models import IDW, RBF, RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/problems/__init__.py b/smt/problems/__init__.py index 42a442579..a82db9c9a 100644 --- a/smt/problems/__init__.py +++ b/smt/problems/__init__.py @@ -1,23 +1,23 @@ from .branin import Branin from .cantilever_beam import CantileverBeam -from .sphere import Sphere +from .hierarchical_goldstein import HierarchicalGoldstein +from .lp_norm import LpNorm +from .mixed_cantilever_beam import MixedCantileverBeam +from .ndim_cantilever_beam import NdimCantileverBeam +from .ndim_robot_arm import NdimRobotArm +from .ndim_rosenbrock import NdimRosenbrock +from .ndim_step_function import NdimStepFunction +from .neural_network import HierarchicalNeuralNetwork from .reduced_problem import ReducedProblem from .robot_arm import RobotArm from .rosenbrock import Rosenbrock +from .sphere import Sphere from .tensor_product import TensorProduct from .torsion_vibration import TorsionVibration from .water_flow import WaterFlow from .water_flow_lfidelity import WaterFlowLFidelity from .welded_beam import WeldedBeam from .wing_weight import WingWeight -from .ndim_cantilever_beam import NdimCantileverBeam -from .mixed_cantilever_beam import MixedCantileverBeam -from .neural_network import HierarchicalNeuralNetwork -from .hierarchical_goldstein import HierarchicalGoldstein -from .ndim_robot_arm import NdimRobotArm -from .ndim_rosenbrock import NdimRosenbrock -from .ndim_step_function import NdimStepFunction -from .lp_norm import LpNorm __all__ = [ "Branin", diff --git a/smt/problems/hierarchical_goldstein.py b/smt/problems/hierarchical_goldstein.py index f2c354d85..43166d23a 100644 --- a/smt/problems/hierarchical_goldstein.py +++ b/smt/problems/hierarchical_goldstein.py @@ -11,11 +11,11 @@ from smt.problems.problem import Problem from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, - OrdinalVariable, FloatVariable, - CategoricalVariable, IntegerVariable, + OrdinalVariable, ) diff --git a/smt/problems/mixed_cantilever_beam.py b/smt/problems/mixed_cantilever_beam.py index c9b847305..4c410b47e 100644 --- a/smt/problems/mixed_cantilever_beam.py +++ b/smt/problems/mixed_cantilever_beam.py @@ -10,7 +10,7 @@ import numpy as np from smt.problems.problem import Problem -from smt.utils.design_space import DesignSpace, FloatVariable, CategoricalVariable +from smt.utils.design_space import CategoricalVariable, DesignSpace, FloatVariable class MixedCantileverBeam(Problem): diff --git a/smt/problems/ndim_cantilever_beam.py b/smt/problems/ndim_cantilever_beam.py index 466cc7f13..9404788ca 100644 --- a/smt/problems/ndim_cantilever_beam.py +++ b/smt/problems/ndim_cantilever_beam.py @@ -8,10 +8,10 @@ import numpy as np -from smt.utils.options_dictionary import OptionsDictionary +from smt.problems.cantilever_beam import CantileverBeam from smt.problems.problem import Problem from smt.problems.reduced_problem import ReducedProblem -from smt.problems.cantilever_beam import CantileverBeam +from smt.utils.options_dictionary import OptionsDictionary class NdimCantileverBeam(Problem): diff --git a/smt/problems/ndim_robot_arm.py b/smt/problems/ndim_robot_arm.py index 0f164f604..8ca567138 100644 --- a/smt/problems/ndim_robot_arm.py +++ b/smt/problems/ndim_robot_arm.py @@ -8,10 +8,10 @@ import numpy as np -from smt.utils.options_dictionary import OptionsDictionary from smt.problems.problem import Problem from smt.problems.reduced_problem import ReducedProblem from smt.problems.robot_arm import RobotArm +from smt.utils.options_dictionary import OptionsDictionary class NdimRobotArm(Problem): diff --git a/smt/problems/ndim_rosenbrock.py b/smt/problems/ndim_rosenbrock.py index 2a0c12653..41f7d8be0 100644 --- a/smt/problems/ndim_rosenbrock.py +++ b/smt/problems/ndim_rosenbrock.py @@ -8,10 +8,10 @@ import numpy as np -from smt.utils.options_dictionary import OptionsDictionary from smt.problems.problem import Problem from smt.problems.reduced_problem import ReducedProblem from smt.problems.rosenbrock import Rosenbrock +from smt.utils.options_dictionary import OptionsDictionary class NdimRosenbrock(Problem): diff --git a/smt/problems/ndim_step_function.py b/smt/problems/ndim_step_function.py index e3ec09ed9..96836d5ed 100644 --- a/smt/problems/ndim_step_function.py +++ b/smt/problems/ndim_step_function.py @@ -6,9 +6,9 @@ N-dimensional step function problem. """ -from smt.utils.options_dictionary import OptionsDictionary from smt.problems.problem import Problem from smt.problems.tensor_product import TensorProduct +from smt.utils.options_dictionary import OptionsDictionary class NdimStepFunction(Problem): diff --git a/smt/problems/neural_network.py b/smt/problems/neural_network.py index d0d29dd6e..849f9b39d 100644 --- a/smt/problems/neural_network.py +++ b/smt/problems/neural_network.py @@ -12,11 +12,11 @@ from smt.problems.problem import Problem from smt.utils.design_space import ( + CategoricalVariable, DesignSpace, - OrdinalVariable, FloatVariable, - CategoricalVariable, IntegerVariable, + OrdinalVariable, ) diff --git a/smt/problems/problem.py b/smt/problems/problem.py index 231cd6ea4..5bda81c9c 100644 --- a/smt/problems/problem.py +++ b/smt/problems/problem.py @@ -7,11 +7,12 @@ """ from typing import Optional + import numpy as np -from smt.utils.options_dictionary import OptionsDictionary from smt.utils.checks import ensure_2d_array from smt.utils.design_space import BaseDesignSpace, DesignSpace +from smt.utils.options_dictionary import OptionsDictionary class Problem: diff --git a/smt/problems/reduced_problem.py b/smt/problems/reduced_problem.py index b7d187561..fa3e7eab3 100644 --- a/smt/problems/reduced_problem.py +++ b/smt/problems/reduced_problem.py @@ -8,8 +8,8 @@ import numpy as np -from smt.utils.options_dictionary import OptionsDictionary from smt.problems.problem import Problem +from smt.utils.options_dictionary import OptionsDictionary class ReducedProblem(Problem): diff --git a/smt/problems/tests/test_problem_examples.py b/smt/problems/tests/test_problem_examples.py index de941f5b5..dc6237406 100644 --- a/smt/problems/tests/test_problem_examples.py +++ b/smt/problems/tests/test_problem_examples.py @@ -12,8 +12,8 @@ class Test(unittest.TestCase): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_cantilever_beam(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import CantileverBeam @@ -42,6 +42,7 @@ def test_cantilever_beam(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_mixed_cantilever_beam(self): import matplotlib.pyplot as plt + from smt.problems import MixedCantileverBeam problem = MixedCantileverBeam() @@ -58,8 +59,9 @@ def test_mixed_cantilever_beam(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_hier_neural_network(self): import matplotlib.pyplot as plt - from smt.problems import HierarchicalNeuralNetwork + from smt.applications.mixed_integer import MixedIntegerSamplingMethod + from smt.problems import HierarchicalNeuralNetwork from smt.sampling_methods import LHS problem = HierarchicalNeuralNetwork() @@ -80,8 +82,8 @@ def test_hier_neural_network(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_robot_arm(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import RobotArm @@ -108,8 +110,8 @@ def test_robot_arm(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_rosenbrock(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import Rosenbrock @@ -136,8 +138,8 @@ def test_rosenbrock(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_sphere(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import Sphere @@ -164,8 +166,8 @@ def test_sphere(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_branin(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import Branin @@ -192,8 +194,8 @@ def test_branin(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_lp_norm(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import LpNorm @@ -220,8 +222,8 @@ def test_lp_norm(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_tensor_product(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import TensorProduct @@ -248,8 +250,8 @@ def test_tensor_product(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_torsion_vibration(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import TorsionVibration @@ -277,8 +279,8 @@ def test_torsion_vibration(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_water_flow(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import WaterFlow @@ -306,8 +308,8 @@ def test_water_flow(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_welded_beam(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import WeldedBeam @@ -335,8 +337,8 @@ def test_welded_beam(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_wing_weight(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.problems import WingWeight diff --git a/smt/problems/welded_beam.py b/smt/problems/welded_beam.py index 09376c9ee..bec49df64 100644 --- a/smt/problems/welded_beam.py +++ b/smt/problems/welded_beam.py @@ -15,6 +15,7 @@ import numpy as np from scipy.misc import derivative + from smt.problems.problem import Problem diff --git a/smt/sampling_methods/__init__.py b/smt/sampling_methods/__init__.py index 4041e3a9c..f6b55a657 100644 --- a/smt/sampling_methods/__init__.py +++ b/smt/sampling_methods/__init__.py @@ -1,7 +1,7 @@ -from .random import Random -from .lhs import LHS from .full_factorial import FullFactorial -from .pydoe import BoxBehnken, PlackettBurman, Factorial, Gsd +from .lhs import LHS +from .pydoe import BoxBehnken, Factorial, Gsd, PlackettBurman +from .random import Random __all__ = [ "Random", diff --git a/smt/sampling_methods/lhs.py b/smt/sampling_methods/lhs.py index 274fe5df8..4fc3c6f49 100644 --- a/smt/sampling_methods/lhs.py +++ b/smt/sampling_methods/lhs.py @@ -6,9 +6,9 @@ LHS sampling; uses the pyDOE3 package. """ -from pyDOE3 import lhs -from scipy.spatial.distance import pdist, cdist import numpy as np +from pyDOE3 import lhs +from scipy.spatial.distance import cdist, pdist from smt.sampling_methods.sampling_method import ScaledSamplingMethod diff --git a/smt/sampling_methods/pydoe.py b/smt/sampling_methods/pydoe.py index da7dbd307..caed5cdb7 100644 --- a/smt/sampling_methods/pydoe.py +++ b/smt/sampling_methods/pydoe.py @@ -6,11 +6,8 @@ pyDOE3 sampling methods """ -from pyDOE3 import doe_box_behnken -from pyDOE3 import doe_gsd -from pyDOE3 import doe_factorial -from pyDOE3 import doe_plackett_burman import numpy as np +from pyDOE3 import doe_box_behnken, doe_factorial, doe_gsd, doe_plackett_burman from smt.sampling_methods.sampling_method import SamplingMethod diff --git a/smt/sampling_methods/sampling_method.py b/smt/sampling_methods/sampling_method.py index f5e396ed2..90df6dc31 100644 --- a/smt/sampling_methods/sampling_method.py +++ b/smt/sampling_methods/sampling_method.py @@ -7,6 +7,7 @@ """ from abc import ABCMeta, abstractmethod + import numpy as np from smt.utils.options_dictionary import OptionsDictionary diff --git a/smt/sampling_methods/tests/test_fullfactorial.py b/smt/sampling_methods/tests/test_fullfactorial.py index 5a5c1c775..b3a00e879 100644 --- a/smt/sampling_methods/tests/test_fullfactorial.py +++ b/smt/sampling_methods/tests/test_fullfactorial.py @@ -1,4 +1,5 @@ import unittest + import numpy as np from smt.sampling_methods import FullFactorial diff --git a/smt/sampling_methods/tests/test_lhs.py b/smt/sampling_methods/tests/test_lhs.py index e7791e1e2..72954d6c0 100644 --- a/smt/sampling_methods/tests/test_lhs.py +++ b/smt/sampling_methods/tests/test_lhs.py @@ -1,5 +1,6 @@ import os import unittest + import numpy as np from smt.sampling_methods import LHS diff --git a/smt/sampling_methods/tests/test_pydoe.py b/smt/sampling_methods/tests/test_pydoe.py index 73dfdf5a7..bd6a9e807 100644 --- a/smt/sampling_methods/tests/test_pydoe.py +++ b/smt/sampling_methods/tests/test_pydoe.py @@ -1,4 +1,5 @@ import unittest + import numpy as np from smt.sampling_methods import pydoe diff --git a/smt/sampling_methods/tests/test_sampling_method_examples.py b/smt/sampling_methods/tests/test_sampling_method_examples.py index e55b61e34..2e1da1d8e 100644 --- a/smt/sampling_methods/tests/test_sampling_method_examples.py +++ b/smt/sampling_methods/tests/test_sampling_method_examples.py @@ -12,8 +12,8 @@ class Test(unittest.TestCase): @staticmethod def run_random(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import Random @@ -32,8 +32,8 @@ def run_random(): @staticmethod def run_lhs(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import LHS @@ -52,8 +52,8 @@ def run_lhs(): @staticmethod def run_full_factorial(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import FullFactorial @@ -72,8 +72,8 @@ def run_full_factorial(): @staticmethod def run_box_behnken(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import BoxBehnken @@ -94,8 +94,8 @@ def run_box_behnken(): @staticmethod def run_plackett_burman(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import PlackettBurman @@ -116,8 +116,8 @@ def run_plackett_burman(): @staticmethod def run_factorial(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import Factorial @@ -138,8 +138,8 @@ def run_factorial(): @staticmethod def run_gsd(): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.sampling_methods import Gsd diff --git a/smt/sampling_methods/tests/test_scaled_sampling_methods.py b/smt/sampling_methods/tests/test_scaled_sampling_methods.py index 8ca4d2cf7..5720d0775 100644 --- a/smt/sampling_methods/tests/test_scaled_sampling_methods.py +++ b/smt/sampling_methods/tests/test_scaled_sampling_methods.py @@ -1,4 +1,5 @@ import unittest + import numpy as np from smt.sampling_methods import LHS, FullFactorial, Random diff --git a/smt/surrogate_models/gpx.py b/smt/surrogate_models/gpx.py index 06336e75a..29aa012c0 100644 --- a/smt/surrogate_models/gpx.py +++ b/smt/surrogate_models/gpx.py @@ -1,5 +1,7 @@ -import numpy as np import warnings + +import numpy as np + from smt.surrogate_models.surrogate_model import SurrogateModel try: diff --git a/smt/surrogate_models/idw.py b/smt/surrogate_models/idw.py index 82aeb6e42..aa08b3776 100644 --- a/smt/surrogate_models/idw.py +++ b/smt/surrogate_models/idw.py @@ -6,10 +6,10 @@ """ import numpy as np -from smt.surrogate_models.surrogate_model import SurrogateModel -from smt.utils.caching import cached_operation from smt.surrogate_models.idwclib import PyIDW +from smt.surrogate_models.surrogate_model import SurrogateModel +from smt.utils.caching import cached_operation class IDW(SurrogateModel): diff --git a/smt/surrogate_models/ls.py b/smt/surrogate_models/ls.py index 754eac2e8..f33135e50 100644 --- a/smt/surrogate_models/ls.py +++ b/smt/surrogate_models/ls.py @@ -9,8 +9,8 @@ """ import numpy as np - from sklearn import linear_model + from smt.surrogate_models.surrogate_model import SurrogateModel from smt.utils.caching import cached_operation diff --git a/smt/surrogate_models/mgp.py b/smt/surrogate_models/mgp.py index 7dc7632db..5f735dd39 100644 --- a/smt/surrogate_models/mgp.py +++ b/smt/surrogate_models/mgp.py @@ -5,12 +5,13 @@ """ from __future__ import division + import numpy as np from scipy import linalg -from smt.utils.kriging import differences, componentwise_distance from smt.surrogate_models.krg_based import KrgBased -from smt.utils.checks import check_support, check_nx, ensure_2d_array +from smt.utils.checks import check_nx, check_support, ensure_2d_array +from smt.utils.kriging import componentwise_distance, differences """ The Active kriging class. diff --git a/smt/surrogate_models/qp.py b/smt/surrogate_models/qp.py index 8647a9ad6..2a901c65d 100644 --- a/smt/surrogate_models/qp.py +++ b/smt/surrogate_models/qp.py @@ -10,6 +10,7 @@ import numpy as np import scipy + from smt.surrogate_models.surrogate_model import SurrogateModel from smt.utils.caching import cached_operation from smt.utils.misc import standardization diff --git a/smt/surrogate_models/rbf.py b/smt/surrogate_models/rbf.py index 8801f3074..024299901 100644 --- a/smt/surrogate_models/rbf.py +++ b/smt/surrogate_models/rbf.py @@ -6,12 +6,11 @@ import numpy as np from scipy.sparse import csc_matrix -from smt.surrogate_models.surrogate_model import SurrogateModel - -from smt.utils.linear_solvers import get_solver -from smt.utils.caching import cached_operation from smt.surrogate_models.rbfclib import PyRBF +from smt.surrogate_models.surrogate_model import SurrogateModel +from smt.utils.caching import cached_operation +from smt.utils.linear_solvers import get_solver class RBF(SurrogateModel): diff --git a/smt/surrogate_models/rmtb.py b/smt/surrogate_models/rmtb.py index 7e07966f3..7ce62274e 100644 --- a/smt/surrogate_models/rmtb.py +++ b/smt/surrogate_models/rmtb.py @@ -4,11 +4,11 @@ This package is distributed under New BSD license. """ -import numpy as np from numbers import Integral -from smt.surrogate_models.rmts import RMTS +import numpy as np +from smt.surrogate_models.rmts import RMTS from smt.surrogate_models.rmtsclib import PyRMTB diff --git a/smt/surrogate_models/rmtc.py b/smt/surrogate_models/rmtc.py index 7aec65337..9ec69ec9e 100644 --- a/smt/surrogate_models/rmtc.py +++ b/smt/surrogate_models/rmtc.py @@ -4,12 +4,12 @@ This package is distributed under New BSD license. """ +from numbers import Integral + import numpy as np import scipy.sparse -from numbers import Integral from smt.surrogate_models.rmts import RMTS - from smt.surrogate_models.rmtsclib import PyRMTC diff --git a/smt/surrogate_models/rmts.py b/smt/surrogate_models/rmts.py index b23d12f30..9dc903c44 100644 --- a/smt/surrogate_models/rmts.py +++ b/smt/surrogate_models/rmts.py @@ -4,14 +4,15 @@ This package is distributed under New BSD license. """ +from numbers import Integral + import numpy as np import scipy.sparse -from numbers import Integral -from smt.utils.linear_solvers import get_solver, LinearSolver, VALID_SOLVERS -from smt.utils.line_search import get_line_search_class, LineSearch, VALID_LINE_SEARCHES -from smt.utils.caching import cached_operation from smt.surrogate_models.surrogate_model import SurrogateModel +from smt.utils.caching import cached_operation +from smt.utils.line_search import VALID_LINE_SEARCHES, LineSearch, get_line_search_class +from smt.utils.linear_solvers import VALID_SOLVERS, LinearSolver, get_solver class RMTS(SurrogateModel): diff --git a/smt/surrogate_models/tests/test_gpx.py b/smt/surrogate_models/tests/test_gpx.py index 2d48fc824..8e449cb5a 100644 --- a/smt/surrogate_models/tests/test_gpx.py +++ b/smt/surrogate_models/tests/test_gpx.py @@ -1,7 +1,9 @@ import unittest + import numpy as np -from smt.sampling_methods import LHS + from smt.problems import Sphere +from smt.sampling_methods import LHS from smt.surrogate_models import GPX from smt.surrogate_models.gpx import GPX_AVAILABLE diff --git a/smt/surrogate_models/tests/test_kpls.py b/smt/surrogate_models/tests/test_kpls.py index 0eb8759ad..231b7dbf8 100644 --- a/smt/surrogate_models/tests/test_kpls.py +++ b/smt/surrogate_models/tests/test_kpls.py @@ -5,9 +5,11 @@ """ import unittest + import numpy as np -from smt.surrogate_models import KPLS + from smt.sampling_methods import LHS +from smt.surrogate_models import KPLS class TestKPLS(unittest.TestCase): diff --git a/smt/surrogate_models/tests/test_krg_based.py b/smt/surrogate_models/tests/test_krg_based.py index eaad6b828..6e37c457f 100644 --- a/smt/surrogate_models/tests/test_krg_based.py +++ b/smt/surrogate_models/tests/test_krg_based.py @@ -5,10 +5,11 @@ """ import unittest + import numpy as np -from smt.surrogate_models.krg_based import KrgBased from smt.surrogate_models import KRG +from smt.surrogate_models.krg_based import KrgBased # defining the toy example diff --git a/smt/surrogate_models/tests/test_krg_noise.py b/smt/surrogate_models/tests/test_krg_noise.py index bd0ea2ace..7aaa1e0c8 100644 --- a/smt/surrogate_models/tests/test_krg_noise.py +++ b/smt/surrogate_models/tests/test_krg_noise.py @@ -5,6 +5,7 @@ """ import unittest + import numpy as np from smt.surrogate_models import KRG diff --git a/smt/surrogate_models/tests/test_krg_outputs.py b/smt/surrogate_models/tests/test_krg_outputs.py index 2249bd8f2..dcac602f8 100644 --- a/smt/surrogate_models/tests/test_krg_outputs.py +++ b/smt/surrogate_models/tests/test_krg_outputs.py @@ -5,9 +5,11 @@ """ import unittest + import numpy as np -from smt.surrogate_models import KRG + from smt.sampling_methods import LHS +from smt.surrogate_models import KRG class TestKRG(unittest.TestCase): diff --git a/smt/surrogate_models/tests/test_krg_predictions.py b/smt/surrogate_models/tests/test_krg_predictions.py index af03a1407..e70417d1d 100644 --- a/smt/surrogate_models/tests/test_krg_predictions.py +++ b/smt/surrogate_models/tests/test_krg_predictions.py @@ -5,9 +5,11 @@ """ import unittest + import numpy as np -from smt.surrogate_models import KRG + from smt.sampling_methods import LHS +from smt.surrogate_models import KRG from smt.utils.sm_test_case import SMTestCase diff --git a/smt/surrogate_models/tests/test_krg_training.py b/smt/surrogate_models/tests/test_krg_training.py index 0b32204e7..582333451 100644 --- a/smt/surrogate_models/tests/test_krg_training.py +++ b/smt/surrogate_models/tests/test_krg_training.py @@ -6,23 +6,26 @@ @author: ninamoello """ -from __future__ import print_function, division -import numpy as np +from __future__ import division, print_function + import unittest -from smt.utils.sm_test_case import SMTestCase + +import numpy as np + +from smt.sampling_methods.lhs import LHS +from smt.surrogate_models import KRG, MGP from smt.utils.kriging import ( - pow_exp, abs_exp, - squar_exp, act_exp, - cross_distances, componentwise_distance, - matern52, + cross_distances, matern32, + matern52, + pow_exp, + squar_exp, ) from smt.utils.misc import standardization -from smt.sampling_methods.lhs import LHS -from smt.surrogate_models import KRG, MGP +from smt.utils.sm_test_case import SMTestCase print_output = False diff --git a/smt/surrogate_models/tests/test_mgp.py b/smt/surrogate_models/tests/test_mgp.py index 5fe8ce5cf..48555bedf 100644 --- a/smt/surrogate_models/tests/test_mgp.py +++ b/smt/surrogate_models/tests/test_mgp.py @@ -5,9 +5,11 @@ """ import unittest + import numpy as np -from smt.surrogate_models import MGP + from smt.sampling_methods import LHS +from smt.surrogate_models import MGP class TestMGP(unittest.TestCase): diff --git a/smt/surrogate_models/tests/test_qp.py b/smt/surrogate_models/tests/test_qp.py index 2b804602d..52cc9dcb8 100644 --- a/smt/surrogate_models/tests/test_qp.py +++ b/smt/surrogate_models/tests/test_qp.py @@ -5,10 +5,11 @@ """ import unittest + import numpy as np -from smt.surrogate_models import QP from smt.examples.rans_crm_wing.rans_crm_wing import get_rans_crm_wing +from smt.surrogate_models import QP class TestQP(unittest.TestCase): diff --git a/smt/surrogate_models/tests/test_rmts.py b/smt/surrogate_models/tests/test_rmts.py index 2dbe24953..ed41b1994 100644 --- a/smt/surrogate_models/tests/test_rmts.py +++ b/smt/surrogate_models/tests/test_rmts.py @@ -5,12 +5,13 @@ """ import unittest + import numpy as np +from smt.surrogate_models import RMTB +from smt.utils.misc import compute_rms_error from smt.utils.silence import Silence from smt.utils.sm_test_case import SMTestCase -from smt.utils.misc import compute_rms_error -from smt.surrogate_models import RMTB def function_test_1d(x): diff --git a/smt/surrogate_models/tests/test_sgp.py b/smt/surrogate_models/tests/test_sgp.py index 53ef9b73a..dae9928a4 100644 --- a/smt/surrogate_models/tests/test_sgp.py +++ b/smt/surrogate_models/tests/test_sgp.py @@ -1,6 +1,7 @@ -import numpy as np import unittest +import numpy as np + from smt.surrogate_models import SGP from smt.utils.sm_test_case import SMTestCase diff --git a/smt/surrogate_models/tests/test_surrogate_model_examples.py b/smt/surrogate_models/tests/test_surrogate_model_examples.py index 9d7d8da7c..be000675a 100644 --- a/smt/surrogate_models/tests/test_surrogate_model_examples.py +++ b/smt/surrogate_models/tests/test_surrogate_model_examples.py @@ -30,8 +30,8 @@ class Test(unittest.TestCase): NO_COMPILED or NO_MATPLOTLIB, "C compilation failed or no matplotlib" ) def test_idw(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import IDW @@ -57,8 +57,8 @@ def test_idw(self): NO_COMPILED or NO_MATPLOTLIB, "C compilation failed or no matplotlib" ) def test_rbf(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import RBF @@ -84,8 +84,8 @@ def test_rbf(self): NO_COMPILED or NO_MATPLOTLIB, "C compilation failed or no matplotlib" ) def test_rmtb(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import RMTB @@ -119,8 +119,8 @@ def test_rmtb(self): NO_COMPILED or NO_MATPLOTLIB, "C compilation failed or no matplotlib" ) def test_rmtc(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import RMTC @@ -151,8 +151,8 @@ def test_rmtc(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_ls(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import LS @@ -176,8 +176,8 @@ def test_ls(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_qp(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import QP @@ -203,8 +203,8 @@ def test_qp(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_krg(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import KRG @@ -244,11 +244,11 @@ def test_krg(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_mixed_int_krg(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import KRG from smt.applications.mixed_integer import MixedIntegerKrigingModel + from smt.surrogate_models import KRG from smt.utils.design_space import DesignSpace, IntegerVariable xt = np.array([0.0, 2.0, 3.0]) @@ -291,8 +291,9 @@ def test_mixed_int_krg(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_noisy_krg(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np + from smt.surrogate_models import KRG # defining the toy example @@ -337,17 +338,18 @@ def target_fun(x): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_mixed_gower_krg(self): + import matplotlib.pyplot as plt + import numpy as np + + from smt.applications.mixed_integer import ( + MixedIntegerKrigingModel, + ) from smt.surrogate_models import ( - MixIntKernelType, KRG, - DesignSpace, CategoricalVariable, + DesignSpace, + MixIntKernelType, ) - from smt.applications.mixed_integer import ( - MixedIntegerKrigingModel, - ) - import matplotlib.pyplot as plt - import numpy as np xt = np.array([0, 3, 4]) yt = np.array([0.0, 1.0, 1.5]) @@ -382,9 +384,10 @@ def test_mixed_gower_krg(self): def test_kpls_auto(self): import numpy as np - from smt.surrogate_models import KPLS + from smt.problems import TensorProduct from smt.sampling_methods import LHS + from smt.surrogate_models import KPLS # The problem is the exponential problem with dimension 10 ndim = 10 @@ -409,8 +412,8 @@ def test_kpls_auto(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_kpls(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import KPLS @@ -452,8 +455,8 @@ def test_kpls(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_kplsk(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import KPLSK @@ -495,12 +498,12 @@ def test_kplsk(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_gekpls(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np - from smt.surrogate_models import GEKPLS, DesignSpace from smt.problems import Sphere from smt.sampling_methods import LHS + from smt.surrogate_models import GEKPLS, DesignSpace # Construction of the DOE fun = Sphere(ndim=2) @@ -548,8 +551,8 @@ def test_gekpls(self): NO_MATPLOTLIB or not GPX_AVAILABLE, "Matplotlib or egobox not installed" ) def test_gpx(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import GPX @@ -587,10 +590,11 @@ def test_gpx(self): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_mgp(self): - import numpy as np import matplotlib.pyplot as plt - from smt.surrogate_models import MGP + import numpy as np + from smt.sampling_methods import LHS + from smt.surrogate_models import MGP # Construction of the DOE dim = 3 @@ -667,8 +671,8 @@ def fun(x): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_sgp_fitc(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import SGP @@ -722,8 +726,8 @@ def f_obj(x): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_sgp_vfe(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import SGP @@ -776,8 +780,8 @@ def f_obj(x): @unittest.skipIf(NO_MATPLOTLIB, "Matplotlib not installed") def test_genn(self): - import numpy as np import matplotlib.pyplot as plt + import numpy as np from smt.surrogate_models import GENN diff --git a/smt/tests/test_all.py b/smt/tests/test_all.py index 6bbc4240e..6f4f421a6 100644 --- a/smt/tests/test_all.py +++ b/smt/tests/test_all.py @@ -5,33 +5,32 @@ This package is distributed under New BSD license. """ -import numpy as np -import unittest import inspect - +import unittest from collections import OrderedDict +import numpy as np + from smt.problems import TensorProduct from smt.sampling_methods import LHS - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence -from smt.utils.misc import compute_rms_error from smt.surrogate_models import ( - LS, - QP, - KPLS, - KRG, - KPLSK, GEKPLS, - GPX, GENN, + GPX, + KPLS, + KPLSK, + KRG, + LS, + QP, DesignSpace, ) from smt.surrogate_models.gpx import GPX_AVAILABLE +from smt.utils.misc import compute_rms_error +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: - from smt.surrogate_models import IDW, RBF, RMTC, RMTB + from smt.surrogate_models import IDW, RBF, RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/tests/test_array_outputs.py b/smt/tests/test_array_outputs.py index 9a9c4d65e..65862592f 100644 --- a/smt/tests/test_array_outputs.py +++ b/smt/tests/test_array_outputs.py @@ -1,11 +1,12 @@ -import numpy as np import unittest -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence +import numpy as np + from smt.examples.rans_crm_wing.rans_crm_wing import ( get_rans_crm_wing, ) +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase def setup_sm(sm_name, settings={}): diff --git a/smt/tests/test_derivs.py b/smt/tests/test_derivs.py index 5408bdd1d..9aeb6c7c8 100644 --- a/smt/tests/test_derivs.py +++ b/smt/tests/test_derivs.py @@ -4,24 +4,22 @@ This package is distributed under New BSD license. """ -import numpy as np -import unittest import inspect - +import unittest from collections import OrderedDict +import numpy as np + +from smt.applications import MFK from smt.problems import Sphere from smt.sampling_methods import LHS - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence -from smt.utils.misc import compute_rms_error from smt.utils.design_space import DesignSpace - -from smt.applications import MFK +from smt.utils.misc import compute_rms_error +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: - from smt.surrogate_models import RBF, RMTC, RMTB + from smt.surrogate_models import RBF, RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/tests/test_extrap.py b/smt/tests/test_extrap.py index d2edec150..9167017eb 100644 --- a/smt/tests/test_extrap.py +++ b/smt/tests/test_extrap.py @@ -4,20 +4,19 @@ This package is distributed under New BSD license. """ -import numpy as np import unittest - from collections import OrderedDict +import numpy as np + from smt.problems import Sphere from smt.sampling_methods import LHS from smt.utils.design_space import DesignSpace - -from smt.utils.sm_test_case import SMTestCase from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: - from smt.surrogate_models import RMTC, RMTB + from smt.surrogate_models import RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/tests/test_high_dim.py b/smt/tests/test_high_dim.py index ef0f18193..ed0d4e27e 100644 --- a/smt/tests/test_high_dim.py +++ b/smt/tests/test_high_dim.py @@ -4,20 +4,19 @@ This package is distributed under New BSD license. """ +import inspect import os -import numpy as np import unittest -import inspect - from collections import OrderedDict +import numpy as np + from smt.problems import Sphere, TensorProduct from smt.sampling_methods import LHS - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence +from smt.surrogate_models import KPLS, KRG, LS, QP from smt.utils.misc import compute_rms_error -from smt.surrogate_models import LS, QP, KPLS, KRG +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: from smt.surrogate_models import IDW, RBF diff --git a/smt/tests/test_kpls_auto.py b/smt/tests/test_kpls_auto.py index df6c9223e..c06aa0f2a 100644 --- a/smt/tests/test_kpls_auto.py +++ b/smt/tests/test_kpls_auto.py @@ -4,19 +4,16 @@ This package is distributed under New BSD license. """ -import unittest import inspect - +import unittest from collections import OrderedDict -from smt.problems import Sphere, TensorProduct, Rosenbrock, Branin +from smt.problems import Branin, Rosenbrock, Sphere, TensorProduct from smt.sampling_methods import LHS - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence -from smt.utils.misc import compute_rms_error from smt.surrogate_models import KPLS - +from smt.utils.misc import compute_rms_error +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase print_output = False diff --git a/smt/tests/test_low_dim.py b/smt/tests/test_low_dim.py index 22b1603fe..f9c2b8ac0 100644 --- a/smt/tests/test_low_dim.py +++ b/smt/tests/test_low_dim.py @@ -4,23 +4,22 @@ This package is distributed under New BSD license. """ -import numpy as np -import unittest import inspect - +import unittest from collections import OrderedDict +import numpy as np + from smt.problems import Sphere, TensorProduct from smt.sampling_methods import LHS +from smt.surrogate_models import LS, QP from smt.utils.design_space import DesignSpace - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence from smt.utils.misc import compute_rms_error -from smt.surrogate_models import LS, QP +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: - from smt.surrogate_models import RMTC, RMTB + from smt.surrogate_models import RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/tests/test_output_derivs.py b/smt/tests/test_output_derivs.py index b9eca7c25..738ba04b5 100644 --- a/smt/tests/test_output_derivs.py +++ b/smt/tests/test_output_derivs.py @@ -4,20 +4,20 @@ This package is distributed under New BSD license. """ -import numpy as np -import unittest import inspect - +import unittest from collections import OrderedDict -from smt.utils.design_space import DesignSpace + +import numpy as np from smt.problems import Sphere from smt.sampling_methods import FullFactorial -from smt.utils.sm_test_case import SMTestCase +from smt.utils.design_space import DesignSpace from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: - from smt.surrogate_models import IDW, RBF, RMTC, RMTB + from smt.surrogate_models import IDW, RBF, RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/tests/test_problems.py b/smt/tests/test_problems.py index b57d6c611..af520d217 100644 --- a/smt/tests/test_problems.py +++ b/smt/tests/test_problems.py @@ -4,31 +4,28 @@ This package is distributed under New BSD license. """ -import numpy as np import unittest +import numpy as np + from smt.problems import ( + Branin, CantileverBeam, - Sphere, + LpNorm, + NdimCantileverBeam, + NdimRobotArm, + NdimRosenbrock, + NdimStepFunction, ReducedProblem, RobotArm, Rosenbrock, - Branin, - LpNorm, -) -from smt.problems import ( + Sphere, TensorProduct, TorsionVibration, WaterFlow, WeldedBeam, WingWeight, ) -from smt.problems import ( - NdimCantileverBeam, - NdimRobotArm, - NdimRosenbrock, - NdimStepFunction, -) from smt.utils.sm_test_case import SMTestCase diff --git a/smt/tests/test_training_derivs.py b/smt/tests/test_training_derivs.py index f792ec3cd..689f68d8a 100644 --- a/smt/tests/test_training_derivs.py +++ b/smt/tests/test_training_derivs.py @@ -4,22 +4,21 @@ This package is distributed under New BSD license. """ -import numpy as np -import unittest import inspect - +import unittest from collections import OrderedDict +import numpy as np + from smt.problems import Sphere, TensorProduct from smt.sampling_methods import FullFactorial from smt.utils.design_space import DesignSpace - -from smt.utils.sm_test_case import SMTestCase -from smt.utils.silence import Silence from smt.utils.misc import compute_rms_error +from smt.utils.silence import Silence +from smt.utils.sm_test_case import SMTestCase try: - from smt.surrogate_models import RMTC, RMTB + from smt.surrogate_models import RMTB, RMTC COMPILED_AVAILABLE = True except ImportError: diff --git a/smt/utils/caching.py b/smt/utils/caching.py index fd9645b5c..2af100674 100644 --- a/smt/utils/caching.py +++ b/smt/utils/caching.py @@ -8,8 +8,8 @@ import cPickle as pickle except ImportError: import pickle -import hashlib import contextlib +import hashlib @contextlib.contextmanager diff --git a/smt/utils/design_space.py b/smt/utils/design_space.py index df8406a99..2e6d1a2c6 100644 --- a/smt/utils/design_space.py +++ b/smt/utils/design_space.py @@ -4,24 +4,25 @@ This package is distributed under New BSD license. """ +from typing import List, Optional, Sequence, Tuple, Union + import numpy as np -from typing import List, Union, Tuple, Sequence, Optional from smt.sampling_methods import LHS try: from ConfigSpace import ( - ConfigurationSpace, - Configuration, - UniformIntegerHyperparameter, - UniformFloatHyperparameter, CategoricalHyperparameter, - OrdinalHyperparameter, + Configuration, + ConfigurationSpace, EqualsCondition, - InCondition, + ForbiddenAndConjunction, ForbiddenEqualsClause, ForbiddenInClause, - ForbiddenAndConjunction, + InCondition, + OrdinalHyperparameter, + UniformFloatHyperparameter, + UniformIntegerHyperparameter, ) from ConfigSpace.exceptions import ForbiddenValueError from ConfigSpace.util import get_random_neighbor diff --git a/smt/utils/krg_sampling.py b/smt/utils/krg_sampling.py index 92260bdf9..78356a85e 100644 --- a/smt/utils/krg_sampling.py +++ b/smt/utils/krg_sampling.py @@ -4,9 +4,10 @@ """ import numpy as np -from smt.utils.kriging import differences from scipy import linalg +from smt.utils.kriging import differences + def covariance_matrix(krg, X, conditioned=True): """ diff --git a/smt/utils/kriging.py b/smt/utils/kriging.py index 0860defc2..efca91bc7 100644 --- a/smt/utils/kriging.py +++ b/smt/utils/kriging.py @@ -4,15 +4,15 @@ This package is distributed under New BSD license. """ -import numpy as np -from enum import Enum import os -from sklearn.cross_decomposition import PLSRegression as pls +from enum import Enum +import numpy as np from pyDOE3 import bbdesign +from sklearn.cross_decomposition import PLSRegression as pls from sklearn.metrics.pairwise import check_pairwise_arrays -from smt.utils.design_space import CategoricalVariable +from smt.utils.design_space import CategoricalVariable USE_NUMBA_JIT = int(os.getenv("USE_NUMBA_JIT", 0)) prange = range diff --git a/smt/utils/linear_solvers.py b/smt/utils/linear_solvers.py index 3c682537d..559486fc3 100644 --- a/smt/utils/linear_solvers.py +++ b/smt/utils/linear_solvers.py @@ -4,10 +4,11 @@ This package is distributed under New BSD license. """ +import contextlib + import numpy as np -import scipy.sparse.linalg import scipy.linalg -import contextlib +import scipy.sparse.linalg from smt.utils.options_dictionary import OptionsDictionary diff --git a/smt/utils/misc.py b/smt/utils/misc.py index 899892527..e24a52319 100644 --- a/smt/utils/misc.py +++ b/smt/utils/misc.py @@ -5,9 +5,10 @@ """ import sys -import numpy as np from bisect import bisect_left +import numpy as np + def standardization(X, y): """ diff --git a/smt/utils/neural_net/data.py b/smt/utils/neural_net/data.py index a0548dba7..d3f94c715 100644 --- a/smt/utils/neural_net/data.py +++ b/smt/utils/neural_net/data.py @@ -6,9 +6,10 @@ This package is distributed under New BSD license. """ -import numpy as np -import os import math +import os + +import numpy as np def load_csv(file=None, inputs=None, outputs=None, partials=None): diff --git a/smt/utils/neural_net/model.py b/smt/utils/neural_net/model.py index c4f288c03..c1a5c4713 100644 --- a/smt/utils/neural_net/model.py +++ b/smt/utils/neural_net/model.py @@ -8,15 +8,13 @@ import numpy as np -from smt.utils.neural_net.data import random_mini_batches -from smt.utils.neural_net.optimizer import Adam -from smt.utils.neural_net.activation import Tanh, Linear +from smt.utils.neural_net.activation import Linear, Tanh from smt.utils.neural_net.bwd_prop import L_model_backward -from smt.utils.neural_net.fwd_prop import L_model_forward, L_grads_forward +from smt.utils.neural_net.data import load_csv, normalize_data, random_mini_batches +from smt.utils.neural_net.fwd_prop import L_grads_forward, L_model_forward from smt.utils.neural_net.loss import lse from smt.utils.neural_net.metrics import rsquare -from smt.utils.neural_net.data import normalize_data, load_csv - +from smt.utils.neural_net.optimizer import Adam # TODO: implement batch-norm (deeper networks might suffer from exploding/vanishing gradients during training) @@ -440,8 +438,8 @@ def gradient(self, X): return J def goodness_of_fit(self, X_test, Y_test, J_test=None, response=0, partial=0): - import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec + import matplotlib.pyplot as plt assert X_test.shape[1] == Y_test.shape[1] assert Y_test.shape[0] == Y_test.shape[0] diff --git a/smt/utils/printer.py b/smt/utils/printer.py index 9377a600f..201ba49ac 100644 --- a/smt/utils/printer.py +++ b/smt/utils/printer.py @@ -4,8 +4,8 @@ This package is distributed under New BSD license. """ -import time import contextlib +import time class Printer(object): diff --git a/smt/utils/sm_test_case.py b/smt/utils/sm_test_case.py index d4c133ec7..5e75615a3 100644 --- a/smt/utils/sm_test_case.py +++ b/smt/utils/sm_test_case.py @@ -4,9 +4,10 @@ This package is distributed under New BSD license. """ -import numpy as np import unittest +import numpy as np + class SMTestCase(unittest.TestCase): def assert_error(self, computed, desired, atol=1e-15, rtol=1e-15): diff --git a/smt/utils/test/test_design_space.py b/smt/utils/test/test_design_space.py index aed18b896..fbe1d1de4 100644 --- a/smt/utils/test/test_design_space.py +++ b/smt/utils/test/test_design_space.py @@ -2,21 +2,23 @@ Author: Jasper Bussemaker """ -import unittest -import itertools import contextlib +import itertools +import unittest + import numpy as np + +import smt.utils.design_space as ds from smt.sampling_methods import LHS from smt.utils.design_space import ( + HAS_CONFIG_SPACE, + BaseDesignSpace, + CategoricalVariable, + DesignSpace, FloatVariable, IntegerVariable, OrdinalVariable, - CategoricalVariable, - BaseDesignSpace, - DesignSpace, - HAS_CONFIG_SPACE, ) -import smt.utils.design_space as ds @contextlib.contextmanager diff --git a/smt/utils/test/test_kriging_sampling_utils.py b/smt/utils/test/test_kriging_sampling_utils.py index dee5bbee3..db627b7bc 100644 --- a/smt/utils/test/test_kriging_sampling_utils.py +++ b/smt/utils/test/test_kriging_sampling_utils.py @@ -3,16 +3,18 @@ """ import unittest + import numpy as np + from smt.surrogate_models import KRG from smt.utils.krg_sampling import ( covariance_matrix, - sample_trajectory, + eig_grid, gauss_legendre_grid, rectangular_grid, - simpson_grid, - eig_grid, sample_eigen, + sample_trajectory, + simpson_grid, ) diff --git a/smt/utils/test/test_misc_utils.py b/smt/utils/test/test_misc_utils.py index 43934b1a3..2f49f3506 100644 --- a/smt/utils/test/test_misc_utils.py +++ b/smt/utils/test/test_misc_utils.py @@ -4,10 +4,12 @@ This package is distributed under New BSD license. """ -from smt.utils import misc import unittest + import numpy as np +from smt.utils import misc + class TestMisc(unittest.TestCase): def test_standardization(self):