diff --git a/docs/code/RunModel/abaqus_example.py b/docs/code/RunModel/abaqus_example.py index 211c1e4be..9ee8baaa7 100644 --- a/docs/code/RunModel/abaqus_example.py +++ b/docs/code/RunModel/abaqus_example.py @@ -15,7 +15,7 @@ import time from UQpy.distributions import Normal, Uniform -from UQpy.run_model.RunModel import * +from UQpy.run_model.RunModel_New import * from UQpy.sampling import MonteCarloSampling calling_directory = os.getcwd() diff --git a/docs/code/RunModel/ls_dyna_example_multijob.py b/docs/code/RunModel/ls_dyna_example_multijob.py index 7294caa56..0df185daa 100644 --- a/docs/code/RunModel/ls_dyna_example_multijob.py +++ b/docs/code/RunModel/ls_dyna_example_multijob.py @@ -11,7 +11,7 @@ # %% from UQpy.distributions import Uniform -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.sampling import MonteCarloSampling # %% md diff --git a/docs/code/RunModel/ls_dyna_example_singlejob.py b/docs/code/RunModel/ls_dyna_example_singlejob.py index 486b2fd00..e1243cf19 100644 --- a/docs/code/RunModel/ls_dyna_example_singlejob.py +++ b/docs/code/RunModel/ls_dyna_example_singlejob.py @@ -11,7 +11,7 @@ # %% from UQpy.distributions import Uniform -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.sampling import MonteCarloSampling # %% md diff --git a/docs/code/RunModel/matlab_example.py b/docs/code/RunModel/matlab_example.py index a85fa287f..e5bd71bcc 100644 --- a/docs/code/RunModel/matlab_example.py +++ b/docs/code/RunModel/matlab_example.py @@ -63,7 +63,7 @@ # %% from UQpy.sampling import MonteCarloSampling -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Normal import time import numpy as np diff --git a/docs/code/RunModel/opensees_example.py b/docs/code/RunModel/opensees_example.py index 21af0b8cc..9d8c2cd89 100644 --- a/docs/code/RunModel/opensees_example.py +++ b/docs/code/RunModel/opensees_example.py @@ -13,7 +13,7 @@ import numpy as np from UQpy.distributions import Uniform -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.sampling import MonteCarloSampling # %% md diff --git a/docs/code/RunModel/python_example.py b/docs/code/RunModel/python_example.py index 55ae35916..42931b000 100644 --- a/docs/code/RunModel/python_example.py +++ b/docs/code/RunModel/python_example.py @@ -69,7 +69,7 @@ # %% from UQpy.sampling import MonteCarloSampling -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Normal import time import numpy as np diff --git a/docs/code/inference/bayes_model_selection/bayes_model_selection.py b/docs/code/inference/bayes_model_selection/bayes_model_selection.py index c5981af66..4d71d5cfa 100644 --- a/docs/code/inference/bayes_model_selection/bayes_model_selection.py +++ b/docs/code/inference/bayes_model_selection/bayes_model_selection.py @@ -30,7 +30,7 @@ import matplotlib.pyplot as plt from UQpy.sampling.mcmc import MetropolisHastings from UQpy.inference import BayesModelSelection, BayesParameterEstimation, ComputationalModel -from UQpy.run_model.RunModel import RunModel # required to run the quadratic model +from UQpy.run_model.RunModel_New import RunModel_New # required to run the quadratic model from UQpy.distributions import Normal, JointIndependent from scipy.stats import multivariate_normal, norm diff --git a/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_IS_regression.py b/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_IS_regression.py index 5539ebd69..d03b06c34 100644 --- a/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_IS_regression.py +++ b/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_IS_regression.py @@ -24,7 +24,7 @@ from UQpy.sampling.ImportanceSampling import ImportanceSampling from UQpy.inference import BayesParameterEstimation, ComputationalModel -from UQpy.run_model.RunModel import RunModel # required to run the quadratic model +from UQpy.run_model.RunModel_New import RunModel_New # required to run the quadratic model from sklearn.neighbors import KernelDensity # for the plots from UQpy.distributions import JointIndependent, Normal diff --git a/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_MCMC_regression.py b/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_MCMC_regression.py index 6fd895c45..fcbb2285d 100644 --- a/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_MCMC_regression.py +++ b/docs/code/inference/bayes_parameter_estimation/plot_bayes_parameter_MCMC_regression.py @@ -24,7 +24,7 @@ from UQpy.sampling.mcmc.MetropolisHastings import MetropolisHastings from UQpy.inference.inference_models.ComputationalModel import ComputationalModel -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.inference import BayesParameterEstimation from sklearn.neighbors import KernelDensity # for the plots from UQpy.distributions import JointIndependent, Normal diff --git a/docs/code/inference/info_model_selection/plot_selection_regression_model.py b/docs/code/inference/info_model_selection/plot_selection_regression_model.py index 89824be82..c7350543d 100644 --- a/docs/code/inference/info_model_selection/plot_selection_regression_model.py +++ b/docs/code/inference/info_model_selection/plot_selection_regression_model.py @@ -26,7 +26,7 @@ import shutil from UQpy.inference import InformationModelSelection, MLE -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New import numpy as np from UQpy.inference import BIC import matplotlib.pyplot as plt diff --git a/docs/code/inference/mle/plot_regression_model.py b/docs/code/inference/mle/plot_regression_model.py index 12fe84ae5..5b513c499 100644 --- a/docs/code/inference/mle/plot_regression_model.py +++ b/docs/code/inference/mle/plot_regression_model.py @@ -25,7 +25,7 @@ from UQpy.inference import ComputationalModel, MLE from UQpy.distributions import Normal from UQpy.inference import MinimizeOptimizer -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New #%% md # diff --git a/docs/code/reliability/subset_simulation/plot_subset_resonance.py b/docs/code/reliability/subset_simulation/plot_subset_resonance.py index 7cf90e08f..742356704 100644 --- a/docs/code/reliability/subset_simulation/plot_subset_resonance.py +++ b/docs/code/reliability/subset_simulation/plot_subset_resonance.py @@ -30,7 +30,7 @@ import shutil from UQpy.reliability import SubsetSimulation -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.sampling import Stretch, ModifiedMetropolisHastings, MonteCarloSampling import numpy as np import scipy.stats as stats diff --git a/docs/code/reliability/subset_simulation/plot_subset_rosenbrock.py b/docs/code/reliability/subset_simulation/plot_subset_rosenbrock.py index bc6d35305..08c1568a1 100644 --- a/docs/code/reliability/subset_simulation/plot_subset_rosenbrock.py +++ b/docs/code/reliability/subset_simulation/plot_subset_rosenbrock.py @@ -22,7 +22,7 @@ import numpy as np # Import this newly defined Rosenbrock distribution into the Distributions module from UQpy.distributions import Normal -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New import scipy.stats as stats # %% md diff --git a/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_branin_hoo.py b/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_branin_hoo.py index 69900dec5..855de8060 100644 --- a/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_branin_hoo.py +++ b/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_branin_hoo.py @@ -42,7 +42,7 @@ from UQpy.surrogates import GaussianProcessRegression from UQpy.sampling import MonteCarloSampling, AdaptiveKriging -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Uniform from local_BraninHoo import function import time diff --git a/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_normal.py b/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_normal.py index 7cf5b6afb..66559afa2 100644 --- a/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_normal.py +++ b/docs/code/sampling/adaptive_kriging/plot_adaptive_kriging_normal.py @@ -18,7 +18,7 @@ from UQpy.surrogates.gaussian_process import GaussianProcessRegression from UQpy.sampling import MonteCarloSampling, AdaptiveKriging -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Normal from local_series import series import matplotlib.pyplot as plt diff --git a/docs/code/sampling/refined_stratified_sampling/refined_stratified_rectangular_gradient.py b/docs/code/sampling/refined_stratified_sampling/refined_stratified_rectangular_gradient.py index 97eb7fcee..584d29c1f 100644 --- a/docs/code/sampling/refined_stratified_sampling/refined_stratified_rectangular_gradient.py +++ b/docs/code/sampling/refined_stratified_sampling/refined_stratified_rectangular_gradient.py @@ -18,7 +18,7 @@ from UQpy.sampling import TrueStratifiedSampling, RefinedStratifiedSampling from UQpy.surrogates import GaussianProcessRegression -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Uniform import matplotlib.pyplot as plt from matplotlib import cm diff --git a/docs/code/sampling/refined_stratified_sampling/refined_stratified_voronoi_gradient.py b/docs/code/sampling/refined_stratified_sampling/refined_stratified_voronoi_gradient.py index fab7765ce..9f67143cf 100644 --- a/docs/code/sampling/refined_stratified_sampling/refined_stratified_voronoi_gradient.py +++ b/docs/code/sampling/refined_stratified_sampling/refined_stratified_voronoi_gradient.py @@ -18,7 +18,7 @@ from UQpy.sampling import TrueStratifiedSampling, RefinedStratifiedSampling from UQpy.sampling import VoronoiStrata -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Uniform import matplotlib.pyplot as plt from matplotlib import cm diff --git a/docs/code/surrogates/gpr/plot_gpr_custom2D.py b/docs/code/surrogates/gpr/plot_gpr_custom2D.py index 68e46eb2f..f68fb681d 100644 --- a/docs/code/surrogates/gpr/plot_gpr_custom2D.py +++ b/docs/code/surrogates/gpr/plot_gpr_custom2D.py @@ -25,7 +25,7 @@ from UQpy.surrogates.gaussian_process.regression_models import ConstantRegression from UQpy.sampling import RectangularStrata from UQpy.sampling import TrueStratifiedSampling -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Uniform import numpy as np import matplotlib.pyplot as plt diff --git a/docs/code/surrogates/gpr/plot_gpr_sine.py b/docs/code/surrogates/gpr/plot_gpr_sine.py index 4877e323f..601ebaaeb 100644 --- a/docs/code/surrogates/gpr/plot_gpr_sine.py +++ b/docs/code/surrogates/gpr/plot_gpr_sine.py @@ -24,7 +24,7 @@ from UQpy.sampling.stratified_sampling.strata import RectangularStrata from UQpy.sampling import TrueStratifiedSampling -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Gamma import numpy as np import matplotlib.pyplot as plt diff --git a/docs/code/surrogates/srom/plot_srom_eigenvalues.py b/docs/code/surrogates/srom/plot_srom_eigenvalues.py index 38478333c..77534e03e 100644 --- a/docs/code/surrogates/srom/plot_srom_eigenvalues.py +++ b/docs/code/surrogates/srom/plot_srom_eigenvalues.py @@ -21,7 +21,7 @@ from UQpy.sampling import RectangularStrata from UQpy.distributions import Gamma from UQpy.surrogates import SROM -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from scipy.stats import gamma import numpy as np import matplotlib.pyplot as plt diff --git a/src/UQpy/__init__.py b/src/UQpy/__init__.py index 7a0aad66f..e94f11278 100644 --- a/src/UQpy/__init__.py +++ b/src/UQpy/__init__.py @@ -10,7 +10,7 @@ import UQpy.dimension_reduction import UQpy.inference import UQpy.reliability -import UQpy.run_model.RunModel +import UQpy.run_model.RunModel_New import UQpy.sampling import UQpy.stochastic_process import UQpy.surrogates diff --git a/src/UQpy/inference/inference_models/ComputationalModel.py b/src/UQpy/inference/inference_models/ComputationalModel.py index cbeefdbf9..9c3e83d2c 100644 --- a/src/UQpy/inference/inference_models/ComputationalModel.py +++ b/src/UQpy/inference/inference_models/ComputationalModel.py @@ -2,7 +2,7 @@ from beartype import beartype -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions.baseclass import Distribution from UQpy.inference.inference_models.baseclass.InferenceModel import * from UQpy.distributions.collection.MultivariateNormal import MultivariateNormal @@ -16,7 +16,7 @@ class ComputationalModel(InferenceModel): @beartype - def __init__(self, n_parameters: PositiveInteger, runmodel_object: RunModel, + def __init__(self, n_parameters: PositiveInteger, runmodel_object: RunModel_New, error_covariance: Union[np.ndarray, float] = 1.0, name: str = "", prior: Distribution = None, log_likelihood: Callable = None): """ diff --git a/src/UQpy/reliability/taylor_series/SORM.py b/src/UQpy/reliability/taylor_series/SORM.py index dcac92934..e2acc9fef 100644 --- a/src/UQpy/reliability/taylor_series/SORM.py +++ b/src/UQpy/reliability/taylor_series/SORM.py @@ -5,7 +5,7 @@ import scipy.stats as stats from beartype import beartype -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions.baseclass import Distribution from UQpy.utilities.ValidationTypes import PositiveInteger from UQpy.reliability.taylor_series.FORM import FORM @@ -46,7 +46,7 @@ def __init__( def build_from_first_order( cls, distributions: Union[None, Distribution, list[Distribution]], - runmodel_object: RunModel, + runmodel_object: RunModel_New, seed_x: Union[list, np.ndarray] = None, seed_u: Union[list, np.ndarray] = None, df_step: Union[int, float] = 0.01, diff --git a/src/UQpy/run_model/__init__.py b/src/UQpy/run_model/__init__.py index 0dd69e82c..2ec714235 100644 --- a/src/UQpy/run_model/__init__.py +++ b/src/UQpy/run_model/__init__.py @@ -1,4 +1,3 @@ -from UQpy.run_model.RunModel import RunModel from UQpy.run_model.RunModel_New import RunModel_New from UQpy.run_model.model_execution import * diff --git a/src/UQpy/sampling/AdaptiveKriging.py b/src/UQpy/sampling/AdaptiveKriging.py index a6522c687..b2dd7ccb8 100644 --- a/src/UQpy/sampling/AdaptiveKriging.py +++ b/src/UQpy/sampling/AdaptiveKriging.py @@ -2,7 +2,7 @@ from beartype import beartype from sklearn.gaussian_process import GaussianProcessRegressor -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions.baseclass import Distribution from UQpy.sampling.stratified_sampling.LatinHypercubeSampling import LatinHypercubeSampling from UQpy.sampling.adaptive_kriging_functions.baseclass.LearningFunction import ( @@ -23,7 +23,7 @@ class AdaptiveKriging: def __init__( self, distributions: Union[Distribution, list[Distribution]], - runmodel_object: RunModel, + runmodel_object: RunModel_New, surrogate: SurrogateType, learning_function: LearningFunction, samples: Numpy2DFloatArray = None, diff --git a/src/UQpy/sampling/stratified_sampling/refinement/GradientEnhancedRefinement.py b/src/UQpy/sampling/stratified_sampling/refinement/GradientEnhancedRefinement.py index 584db1093..6d2d9d69f 100644 --- a/src/UQpy/sampling/stratified_sampling/refinement/GradientEnhancedRefinement.py +++ b/src/UQpy/sampling/stratified_sampling/refinement/GradientEnhancedRefinement.py @@ -3,7 +3,7 @@ from UQpy.surrogates.baseclass import Surrogate from UQpy.utilities.ValidationTypes import * -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.sampling.stratified_sampling.refinement.baseclass.Refinement import * from UQpy.utilities.Utilities import gradient from UQpy.sampling.stratified_sampling.strata.VoronoiStrata import VoronoiStrata @@ -17,7 +17,7 @@ class GradientEnhancedRefinement(Refinement): def __init__( self, strata: Strata, - runmodel_object: RunModel, + runmodel_object: RunModel_New, surrogate: Union[Surrogate, GaussianProcessRegressor, CompatibleSurrogate], nearest_points_number: int = None, qoi_name: str = None, diff --git a/src/UQpy/utilities/Utilities.py b/src/UQpy/utilities/Utilities.py index 8e7822ef8..fa5516c2b 100755 --- a/src/UQpy/utilities/Utilities.py +++ b/src/UQpy/utilities/Utilities.py @@ -2,7 +2,7 @@ import scipy.stats as stats from UQpy.utilities.ValidationTypes import RandomStateType -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New def svd(matrix, rank=None, tol=None): @@ -156,14 +156,12 @@ def gradient(runmodel_object=None, point=None, order="first", df_step=None): if len(df_step) == 1: df_step = [df_step[0]] * dimension - if not callable(runmodel_object) and not isinstance(runmodel_object, RunModel): - raise RuntimeError( - "A RunModel object or callable function must be provided as model." - ) + if not callable(runmodel_object) and not isinstance(runmodel_object, RunModel_New): + raise RuntimeError("A RunModel object or callable function must be provided as model.") def func(m): def func_eval(x): - if isinstance(m, RunModel): + if isinstance(m, RunModel_New): m.run(samples=x, append_samples=False) return np.array(m.qoi_list).flatten() else: diff --git a/tests/unit_tests/dimension_reduction/test_grassman.py b/tests/unit_tests/dimension_reduction/test_grassman.py index 1c28dd393..2c8d3e8a9 100644 --- a/tests/unit_tests/dimension_reduction/test_grassman.py +++ b/tests/unit_tests/dimension_reduction/test_grassman.py @@ -71,14 +71,11 @@ def test_parsimonious(): X, X_color = make_s_curve(n, random_state=3, noise=0) kernel = GaussianKernel() - dmaps_object = DiffusionMaps.build_from_data(data=X, - alpha=1.0, n_eigenvectors=9, - is_sparse=True, n_neighbors=100, - optimize_parameters=True, - kernel=kernel) + dmaps_object = DiffusionMaps(data=X, alpha=1.0, n_eigenvectors=9, + is_sparse=True, n_neighbors=100, + kernel=kernel) - dmaps_object.fit() - index, residuals = DiffusionMaps.parsimonious(dmaps_object.eigenvectors, 2) + dmaps_object.parsimonious(dim=2) - assert index[0] == 1 - assert index[1] == 5 + assert dmaps_object.parsimonious_indices[0] == 1 + assert dmaps_object.parsimonious_indices[1] == 5 diff --git a/tests/unit_tests/dimension_reduction/test_kernel.py b/tests/unit_tests/dimension_reduction/test_kernel.py index e0a958028..338614c6e 100644 --- a/tests/unit_tests/dimension_reduction/test_kernel.py +++ b/tests/unit_tests/dimension_reduction/test_kernel.py @@ -15,7 +15,9 @@ def test_kernel_projection(): xk = GrassmannPoint(np.array([[-0.69535592, -0.0546034], [-0.34016974, -0.85332868], [-0.63305978, 0.51850616]])) points = [xi, xj, xk] - kernel = np.matrix.round(ProjectionKernel().calculate_kernel_matrix(points), 4) + kernel = ProjectionKernel() + kernel.calculate_kernel_matrix(points) + kernel = np.matrix.round(kernel.kernel_matrix, 4) assert np.allclose(kernel, np.array([[2, 1.0063, 1.2345], [1.0063, 2, 1.0101], [1.2345, 1.0101, 2]])) @@ -26,7 +28,10 @@ def test_kernel_binet_cauchy(): xj = GrassmannPoint(np.array([[0, np.sqrt(2) / 2], [1, 0], [0, -np.sqrt(2) / 2]])) xk = GrassmannPoint(np.array([[-0.69535592, -0.0546034], [-0.34016974, -0.85332868], [-0.63305978, 0.51850616]])) points = [xi, xj, xk] - kernel = np.matrix.round(BinetCauchyKernel().calculate_kernel_matrix(points), 4) + + kernel = BinetCauchyKernel() + kernel.calculate_kernel_matrix(points) + kernel = np.matrix.round(kernel.kernel_matrix, 4) assert np.allclose(kernel, np.array([[1, 0.0063, 0.2345], [0.0063, 1, 0.0101], [0.2345, 0.0101, 1]])) @@ -37,10 +42,10 @@ def test_kernel_gaussian_1d(): xk = np.array([1, 2, 3, 4]) points = [xi, xj, xk] gaussian = GaussianKernel(epsilon=2.0) - kernel = gaussian.calculate_kernel_matrix(points) + gaussian.calculate_kernel_matrix(points) - assert np.allclose(np.matrix.round(kernel, 4), np.array([[1., 0.2645, 1.], [0.2645, 1., 0.2645], [1, 0.2645, 1]]), - atol=1e-04) + assert np.allclose(np.matrix.round(gaussian.kernel_matrix, 4), + np.array([[1., 0.2645, 1.], [0.2645, 1., 0.2645], [1, 0.2645, 1]]), atol=1e-04) assert np.round(gaussian.epsilon, 4) == 2 @@ -50,11 +55,11 @@ def test_kernel_gaussian_2d(): xk = np.array([[-0.69535592, -0.0546034], [-0.34016974, -0.85332868], [-0.63305978, 0.51850616]]) points = [xi, xj, xk] gaussian = GaussianKernel() - kernel = gaussian.calculate_kernel_matrix(points) + gaussian.calculate_kernel_matrix(points) - assert np.allclose(np.matrix.round(kernel, 4), np.array([[1., 0.628, 0.3912], - [0.628, 1., 0.2534], - [0.3912, 0.2534, 1.]])) + assert np.allclose(np.matrix.round(gaussian.kernel_matrix, 4), np.array([[1., 0.628, 0.3912], + [0.628, 1., 0.2534], + [0.3912, 0.2534, 1.]])) assert np.round(gaussian.epsilon, 4) == 1.0 @@ -88,11 +93,6 @@ def test_kernel_gaussian_2d(): def test_kernel(): - D1 = 6 - r0 = 2 # rank sample 0 - r1 = 3 # rank sample 1 - r2 = 4 # rank sample 2 - r3 = 3 # rank sample 2 np.random.seed(1111) # For reproducibility. from numpy.random import RandomState @@ -100,10 +100,9 @@ def test_kernel(): # Creating a list of solutions. Solutions = [sol0, sol1, sol2, sol3] - from UQpy.dimension_reduction.grassmann_manifold.GrassmannOperations import GrassmannOperations manifold_projection = SVDProjection(Solutions, p="max") kernel = ProjectionKernel() - kernel = kernel.calculate_kernel_matrix(manifold_projection.u) + kernel.calculate_kernel_matrix(manifold_projection.u) - assert np.round(kernel[0, 1], 8) == 6.0 + assert np.round(kernel.kernel_matrix[0, 1], 8) == 6.0 diff --git a/tests/unit_tests/inference/test_bayes_model_selection.py b/tests/unit_tests/inference/test_bayes_model_selection.py index c74d8e100..261d7e1f7 100644 --- a/tests/unit_tests/inference/test_bayes_model_selection.py +++ b/tests/unit_tests/inference/test_bayes_model_selection.py @@ -81,6 +81,3 @@ def test_models(): assert selection.candidate_models[1].name == 'model_cubic' assert selection.candidate_models[2].name == 'model_linear' - shutil.rmtree(runmodel4.model.model_dir) - shutil.rmtree(runmodel5.model.model_dir) - shutil.rmtree(runmodel6.model.model_dir) diff --git a/tests/unit_tests/inference/test_inference_runmodel.py b/tests/unit_tests/inference/test_inference_runmodel.py index 9c714de6f..2c5f85969 100644 --- a/tests/unit_tests/inference/test_inference_runmodel.py +++ b/tests/unit_tests/inference/test_inference_runmodel.py @@ -3,7 +3,7 @@ from UQpy.inference.MLE import * from UQpy.distributions import * import pytest -import shutil +from UQpy.run_model.model_execution.PythonModel import PythonModel import numpy as np data = [0., 1., -1.5, -0.2] @@ -11,10 +11,10 @@ @pytest.fixture def setup(): - h_func = RunModel(model_script='pfn_models.py', model_object_name='model_quadratic', vec=False, + model = PythonModel(model_script='pfn_models.py', model_object_name='model_quadratic', var_names=['theta_0', 'theta_1'], delete_files=True) + h_func = RunModel_New(model=model) yield h_func - shutil.rmtree(h_func.model_dir) def user_log_likelihood(data, model_outputs, params=None): diff --git a/tests/unit_tests/inference/test_mle.py b/tests/unit_tests/inference/test_mle.py index b3260a982..f49d74b41 100644 --- a/tests/unit_tests/inference/test_mle.py +++ b/tests/unit_tests/inference/test_mle.py @@ -5,7 +5,7 @@ from UQpy.inference.inference_models.DistributionModel import DistributionModel from UQpy.inference.inference_models.ComputationalModel import ComputationalModel from UQpy.inference import MLE -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New import shutil @@ -25,9 +25,10 @@ def test_simple_probability_model(): def test_regression_model(): param_true = np.array([1.0, 2.0]).reshape((1, -1)) - - h_func = RunModel(model_script='pfn_models.py', model_object_name='model_quadratic', vec=False, + from UQpy.run_model.model_execution.PythonModel import PythonModel + model = PythonModel(model_script='pfn_models.py', model_object_name='model_quadratic', var_names=['theta_0', 'theta_1']) + h_func = RunModel_New(model=model) h_func.run(samples=param_true) # Add noise @@ -45,4 +46,3 @@ def test_regression_model(): assert ml_estimator.mle[0] == 0.8689097631871134 assert ml_estimator.mle[1] == 2.0030767805841143 - shutil.rmtree(h_func.model_dir) diff --git a/tests/unit_tests/reliability/test_subset.py b/tests/unit_tests/reliability/test_subset.py index d00d295de..bf35276d9 100644 --- a/tests/unit_tests/reliability/test_subset.py +++ b/tests/unit_tests/reliability/test_subset.py @@ -2,7 +2,7 @@ import numpy as np -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions.collection.Normal import Normal from UQpy.distributions.collection.JointIndependent import JointIndependent from UQpy.sampling.MonteCarloSampling import MonteCarloSampling diff --git a/tests/unit_tests/run_model/test_RunModel.py b/tests/unit_tests/run_model/test_RunModel.py index f9a7693d7..bf2926c32 100644 --- a/tests/unit_tests/run_model/test_RunModel.py +++ b/tests/unit_tests/run_model/test_RunModel.py @@ -4,7 +4,7 @@ from UQpy.run_model import ThirdPartyModel, RunModel_New from UQpy.sampling import MonteCarloSampling -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions import Normal import pytest import os diff --git a/tests/unit_tests/sampling/test_adaptive_kriging.py b/tests/unit_tests/sampling/test_adaptive_kriging.py index 53516102e..92751b7b7 100644 --- a/tests/unit_tests/sampling/test_adaptive_kriging.py +++ b/tests/unit_tests/sampling/test_adaptive_kriging.py @@ -1,10 +1,11 @@ import pytest +from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.utilities.MinimizeOptimizer import MinimizeOptimizer from UQpy.surrogates.kriging.Kriging import Kriging from UQpy.sampling import MonteCarloSampling, AdaptiveKriging -from UQpy.run_model.RunModel import RunModel +from UQpy.run_model.RunModel_New import RunModel_New from UQpy.distributions.collection import Normal from UQpy.sampling.adaptive_kriging_functions import * import shutil @@ -16,7 +17,8 @@ def test_akmcs_weighted_u(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=0) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -32,7 +34,6 @@ def test_akmcs_weighted_u(): assert a.samples[23, 0] == 1.083176685073489 assert a.samples[20, 1] == 0.20293978126855253 - shutil.rmtree(rmodel.model_dir) def test_akmcs_u(): @@ -41,7 +42,8 @@ def test_akmcs_u(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=1) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -57,7 +59,6 @@ def test_akmcs_u(): assert a.samples[23, 0] == -4.141979058326188 assert a.samples[20, 1] == -1.6476534435429009 - shutil.rmtree(rmodel.model_dir) def test_akmcs_expected_feasibility(): @@ -66,7 +67,8 @@ def test_akmcs_expected_feasibility(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=1) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -82,7 +84,6 @@ def test_akmcs_expected_feasibility(): assert a.samples[23, 0] == 1.366058523912817 assert a.samples[20, 1] == -12.914668932772358 - shutil.rmtree(rmodel.model_dir) def test_akmcs_expected_improvement(): @@ -91,7 +92,8 @@ def test_akmcs_expected_improvement(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=1) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -107,7 +109,6 @@ def test_akmcs_expected_improvement(): assert a.samples[23, 0] == 4.553078100499578 assert a.samples[20, 1] == -3.508949564718469 - shutil.rmtree(rmodel.model_dir) def test_akmcs_expected_improvement_global_fit(): @@ -116,7 +117,8 @@ def test_akmcs_expected_improvement_global_fit(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=1) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -132,7 +134,6 @@ def test_akmcs_expected_improvement_global_fit(): assert a.samples[23, 0] == 11.939859785098493 assert a.samples[20, 1] == -8.429899469300118 - shutil.rmtree(rmodel.model_dir) def test_akmcs_samples_error(): from UQpy.surrogates.kriging.regression_models.LinearRegression import LinearRegression @@ -140,7 +141,8 @@ def test_akmcs_samples_error(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=0) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -153,7 +155,6 @@ def test_akmcs_samples_error(): learning_nsamples=10**3, n_add=1, learning_function=learning_function, random_state=2, samples=x.samples) - shutil.rmtree(rmodel.model_dir) def test_akmcs_u_run_from_init(): from UQpy.surrogates.kriging.regression_models.LinearRegression import LinearRegression @@ -161,7 +162,8 @@ def test_akmcs_u_run_from_init(): marginals = [Normal(loc=0., scale=4.), Normal(loc=0., scale=4.)] x = MonteCarloSampling(distributions=marginals, nsamples=20, random_state=1) - rmodel = RunModel(model_script='series.py', vec=False) + model = PythonModel(model_script='series.py', model_object_name="series") + rmodel = RunModel_New(model=model) regression_model = LinearRegression() correlation_model = ExponentialCorrelation() K = Kriging(regression_model=regression_model, correlation_model=correlation_model, @@ -175,5 +177,3 @@ def test_akmcs_u_run_from_init(): assert a.samples[23, 0] == -4.141979058326188 assert a.samples[20, 1] == -1.6476534435429009 - - shutil.rmtree(rmodel.model_dir) \ No newline at end of file diff --git a/tests/unit_tests/sampling/test_refined_stratified.py b/tests/unit_tests/sampling/test_refined_stratified.py index 763dc086c..b6b0cd287 100644 --- a/tests/unit_tests/sampling/test_refined_stratified.py +++ b/tests/unit_tests/sampling/test_refined_stratified.py @@ -1,13 +1,14 @@ import pytest from beartype.roar import BeartypeCallHintPepParamException +from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.utilities.MinimizeOptimizer import MinimizeOptimizer from UQpy.sampling.stratified_sampling.refinement.GradientEnhancedRefinement import GradientEnhancedRefinement from UQpy.distributions.collection.Uniform import Uniform from UQpy.sampling.stratified_sampling.RefinedStratifiedSampling import * from UQpy.sampling.stratified_sampling.refinement.RandomRefinement import * from UQpy.sampling.stratified_sampling.strata.VoronoiStrata import * -from UQpy.run_model.RunModel import * +from UQpy.run_model.RunModel_New import * from UQpy.surrogates.kriging.Kriging import Kriging @@ -69,7 +70,8 @@ def test_rect_gerss(): marginals = [Uniform(loc=0., scale=2.), Uniform(loc=0., scale=1.)] strata = RectangularStrata(strata_number=[2, 2], random_state=1) x = TrueStratifiedSampling(distributions=marginals, strata_object=strata, nsamples_per_stratum=1) - rmodel = RunModel(model_script='python_model_function.py', vec=False) + model = PythonModel(model_script='python_model_function.py', model_object_name="y_func") + rmodel = RunModel_New(model=model) from UQpy.surrogates.kriging.regression_models import LinearRegression from UQpy.surrogates.kriging.correlation_models import ExponentialCorrelation @@ -124,15 +126,16 @@ def test_vor_gerss(): x_vor = TrueStratifiedSampling(distributions=marginals, strata_object=strata_vor, nsamples_per_stratum=1, ) from UQpy.surrogates.kriging.regression_models.LinearRegression import LinearRegression from UQpy.surrogates.kriging.correlation_models.ExponentialCorrelation import ExponentialCorrelation - rmodel_ = RunModel(model_script='python_model_function.py', vec=False) + model = PythonModel(model_script='python_model_function.py', model_object_name="y_func") + rmodel = RunModel_New(model=model) K_ = Kriging(regression_model=LinearRegression(), correlation_model=ExponentialCorrelation(), optimizations_number=20, optimizer=MinimizeOptimizer('l-bfgs-b'), random_state=0, correlation_model_parameters=[1, 1]) - K_.fit(samples=x_vor.samples, values=rmodel_.qoi_list) + K_.fit(samples=x_vor.samples, values=rmodel.qoi_list) z_vor = RefinedStratifiedSampling(stratified_sampling=x_vor, nsamples=6, random_state=x_vor.random_state, refinement_algorithm=GradientEnhancedRefinement(strata=x_vor.strata_object, - runmodel_object=rmodel_, + runmodel_object=rmodel, surrogate=K_, nearest_points_number=4)) assert np.allclose(z_vor.samples, np.array([[1.78345908, 0.01640854], [1.46201137, 0.70862104], @@ -167,7 +170,8 @@ def test_rss_runmodel_object(): K = Kriging(regression_model=LinearRegression(), correlation_model=ExponentialCorrelation(), optimizations_number=20, correlation_model_parameters=[1, 1], optimizer=MinimizeOptimizer('l-bfgs-b'), ) - rmodel = RunModel(model_script='python_model_function.py', vec=False) + model = PythonModel(model_script='python_model_function.py', model_object_name="y_func") + rmodel = RunModel_New(model=model) K.fit(samples=x.samples, values=rmodel.qoi_list) with pytest.raises(BeartypeCallHintPepParamException): refinement = GradientEnhancedRefinement(strata=x.strata_object, runmodel_object='abc', @@ -183,9 +187,10 @@ def test_rss_kriging_object(): marginals = [Uniform(loc=0., scale=2.), Uniform(loc=0., scale=1.)] strata = RectangularStrata(strata_number=[2, 2]) x = TrueStratifiedSampling(distributions=marginals, strata_object=strata, nsamples_per_stratum=1, random_state=1) - rmodel_ = RunModel(model_script='python_model_function.py', vec=False) + model = PythonModel(model_script='python_model_function.py', model_object_name="y_func") + rmodel = RunModel_New(model=model) with pytest.raises(NotImplementedError): - refinement = GradientEnhancedRefinement(strata=x.strata_object, runmodel_object=rmodel_, + refinement = GradientEnhancedRefinement(strata=x.strata_object, runmodel_object=rmodel, surrogate="abc") RefinedStratifiedSampling(stratified_sampling=x, nsamples=6, samples_per_iteration=2, refinement_algorithm=refinement)