diff --git a/Examples/index.json b/Examples/index.json index c613a293..7ced79e9 100644 --- a/Examples/index.json +++ b/Examples/index.json @@ -363,6 +363,7 @@ "qfem-0017/src/UQpySimpleExample.json", "qfem-0017/figures/CUS_UQtab.png", "qfem-0017/figures/CUS_UQtab2.png", + "qfem-0017/figures/CUS_UQtab3.png", "qfem-0017/figures/CUS_FEMtab.png" ], "entry_point": "qfem-0017/./input.json", diff --git a/Examples/qfem-0007/figures/qfem-0007-FEM.png b/Examples/qfem-0007/figures/qfem-0007-FEM.png index d1be9f7e..a41cd64c 100644 Binary files a/Examples/qfem-0007/figures/qfem-0007-FEM.png and b/Examples/qfem-0007/figures/qfem-0007-FEM.png differ diff --git a/Examples/qfem-0007/figures/qfem-0007-QoI.png b/Examples/qfem-0007/figures/qfem-0007-QoI.png index df2c9906..58ce9543 100644 Binary files a/Examples/qfem-0007/figures/qfem-0007-QoI.png and b/Examples/qfem-0007/figures/qfem-0007-QoI.png differ diff --git a/Examples/qfem-0007/figures/qfem-0007-RES1.png b/Examples/qfem-0007/figures/qfem-0007-RES1.png index 09b60181..471cee55 100644 Binary files a/Examples/qfem-0007/figures/qfem-0007-RES1.png and b/Examples/qfem-0007/figures/qfem-0007-RES1.png differ diff --git a/Examples/qfem-0007/figures/qfem-0007-RES2.png b/Examples/qfem-0007/figures/qfem-0007-RES2.png index 1475da35..8879d137 100644 Binary files a/Examples/qfem-0007/figures/qfem-0007-RES2.png and b/Examples/qfem-0007/figures/qfem-0007-RES2.png differ diff --git a/Examples/qfem-0007/figures/qfem-0007-RV.png b/Examples/qfem-0007/figures/qfem-0007-RV.png index 0c5426e1..6272bbd3 100644 Binary files a/Examples/qfem-0007/figures/qfem-0007-RV.png and b/Examples/qfem-0007/figures/qfem-0007-RV.png differ diff --git a/Examples/qfem-0007/figures/qfem-0007-UQ.png b/Examples/qfem-0007/figures/qfem-0007-UQ.png index c94dafca..f0dc4803 100644 Binary files a/Examples/qfem-0007/figures/qfem-0007-UQ.png and b/Examples/qfem-0007/figures/qfem-0007-UQ.png differ diff --git a/Examples/qfem-0014/README.rst b/Examples/qfem-0014/README.rst index 7bbeb38e..8dbe79e0 100644 --- a/Examples/qfem-0014/README.rst +++ b/Examples/qfem-0014/README.rst @@ -195,7 +195,7 @@ For each variable, specify the prior probability distribution - from the **Distr .. note:: - For this particular problem setup in which the user is not using a postprocessing script, the user may specify any names for the QoI variables. They are only being used by Dakota to return information on the results. + For this particular problem setup in which the user is not using a postprocessing script, the user may specify any names for the QoI variables. They are only being used by the UCSD_UQ engine to return information on the results. 5. Next click on the **Run** button. This will cause the backend application to launch the **UCSD_UQ** engine, which performs Bayesian calibration using the TMCMC algorithm. When done, the **RES** tab will be selected and the results will be displayed as shown in the figure below. The results show the first four moments of the posterior marginal probability distribution of :math:`k_1` and :math:`k_2`. The true value of both :math:`k_1` and :math:`k_2` is **958.61 kips/in**. @@ -227,7 +227,7 @@ Various views of the graphical display can be obtained by left and right clickin :figclass: align-center :width: 600 -If a singular column of the tabular data is pressed with both right and left buttons a histogram and CDF will be displayed, as shown in the figures below. +If a single column of the tabular data is pressed with both right and left buttons a histogram and CDF will be displayed, as shown in the figures below. .. figure:: figures/qfem-0014-RES4.png :align: center diff --git a/Examples/qfem-0014/figures/qfem-0014-FEM.png b/Examples/qfem-0014/figures/qfem-0014-FEM.png index a2f1ba52..946aa26d 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-FEM.png and b/Examples/qfem-0014/figures/qfem-0014-FEM.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-QoI.png b/Examples/qfem-0014/figures/qfem-0014-QoI.png index 0eb0f20a..0aa8e36c 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-QoI.png and b/Examples/qfem-0014/figures/qfem-0014-QoI.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RES1.png b/Examples/qfem-0014/figures/qfem-0014-RES1.png index b458e764..2ee96f09 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RES1.png and b/Examples/qfem-0014/figures/qfem-0014-RES1.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RES2.png b/Examples/qfem-0014/figures/qfem-0014-RES2.png index 656dddd2..fe636d6c 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RES2.png and b/Examples/qfem-0014/figures/qfem-0014-RES2.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RES3.png b/Examples/qfem-0014/figures/qfem-0014-RES3.png index 13577598..93d4f557 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RES3.png and b/Examples/qfem-0014/figures/qfem-0014-RES3.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RES4.png b/Examples/qfem-0014/figures/qfem-0014-RES4.png index 3c19354e..04ea4bd7 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RES4.png and b/Examples/qfem-0014/figures/qfem-0014-RES4.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RES5.png b/Examples/qfem-0014/figures/qfem-0014-RES5.png index 16b46692..44be0d74 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RES5.png and b/Examples/qfem-0014/figures/qfem-0014-RES5.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RES6.png b/Examples/qfem-0014/figures/qfem-0014-RES6.png index 5ffcc86a..5c963ec9 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RES6.png and b/Examples/qfem-0014/figures/qfem-0014-RES6.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-RV.png b/Examples/qfem-0014/figures/qfem-0014-RV.png index c1a3d3e3..551de707 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-RV.png and b/Examples/qfem-0014/figures/qfem-0014-RV.png differ diff --git a/Examples/qfem-0014/figures/qfem-0014-UQ.png b/Examples/qfem-0014/figures/qfem-0014-UQ.png index 806aba4b..e5bc5e4a 100644 Binary files a/Examples/qfem-0014/figures/qfem-0014-UQ.png and b/Examples/qfem-0014/figures/qfem-0014-UQ.png differ diff --git a/Examples/qfem-0017/README.rst b/Examples/qfem-0017/README.rst index dbb3de46..6b9099a1 100644 --- a/Examples/qfem-0017/README.rst +++ b/Examples/qfem-0017/README.rst @@ -26,7 +26,7 @@ Cross sectional area of the upper three bars, Au 400 600 Cross sectional area of the other six bars, Ao 200 300 ================================================ ============ ========= -The goal of the exercise is to implement UQpy as a **custom UQ engine** and estimate the mean and standard deviation of the vertical displacement at node2. +The goal of the exercise is to implement UQpy as a **custom UQ engine** and estimate the mean and standard deviation of the vertical displacement at node 3. .. note:: The UQpy_ python package is required to be installed to run this example, e.g. pip install UQpy @@ -35,28 +35,31 @@ The goal of the exercise is to implement UQpy as a **custom UQ engine** and esti UQ Workflow ------------- -1. Start the application and the **UQ** Selection will be highlighted. In the panel for the UQ selection, change the UQ Engine to **CustomUQ**. In UQ Application Name, type **Other-UQ**. +1. Start the application and the **UQ** Selection will be highlighted. In the panel for the UQ selection, change the UQ Engine to **CustomUQ**. .. figure:: figures/CUS_UQtab.png :align: center :figclass: align-center -Next, provide the configuration input file path. In the configuration file, users specify the interface for the parameters (type, name, values of each parameters) required for the custom UQ analysis. The provided script will generate 1 combo box to define sample types, 4 spin boxes to define number of samples, concurrent tasks, and notes, and 1 line edit field to specify the UQ Driver. +Next, provide the configuration input file path. In the configuration file, users specify the interface for the parameters (type, name, values of each parameters) required for the custom UQ analysis. The provided script will generate 1 combo box to define sample types, 2 line edit fields to define the number of samples and seed, 3 spin boxes to define number of concurrent tasks, nodes, and cores per task, and 1 line edit field to specify the UQ Driver. .. literalinclude:: src/UQpySimpleExample.json :language: json :caption: UQpySimpleExample.json -Note that configuration input file specifies the front-end interfaces while the back-end interface should be modified in the backend directory (See Section 2.1.4.1. Custom Uncertainty Quantification Engine Input). As an example, UQpy has been already implemented in the customized backend where users can find at ``{Backend Applications Directory}/applications/performUQ/other``, where the ``{Backend Applications Directory}`` is specified from the file-preference in the menu bar). Once the ``UQpySimpleExample.json`` is called, the following customized user interface will appear in UQ panel. +Note that configuration input file specifies the front-end interfaces while the back-end interface should be modified in the backend directory (Refer the :ref:`Configuring CustomUQ Engine ` section for details). As an example, UQpy has been already implemented in the customized backend where users can find at ``{Backend Applications Directory}/applications/performUQ/other``, where the ``{Backend Applications Directory}`` is specified from the file-preference in the menu bar). Once the ``UQpySimpleExample.json`` is called, the following customized user interface will appear in UQ panel. .. figure:: figures/CUS_UQtab2.png :align: center :figclass: align-center -Let us sample 50 samples by latine hypercube sampling (LHS). +Let us sample 50 samples by Latin hypercube sampling (LHS). The UQ Driver field must be filled in as **UQpy**, as shown in the following figure. +.. figure:: figures/CUS_UQtab3.png + :align: center + :figclass: align-center -2. Select the **FEM** tab from the input panel. For the main script copy the path to the ``TrussModel.tcl`` or select choose and navigate to the file. For the post-process script field, repeat the same procedure for the ``TrussPost.tcl script``. (See example 'q0001:Two-Dimensional Truss: Sampling, Reliability and Sensitivity' for the model details) +2. Select the **FEM** tab from the input panel. For the main script copy the path to the ``TrussModel.tcl`` or select choose and navigate to the file. For the post-process script field, repeat the same procedure for the ``TrussPost.tcl script``. (See example :ref:`Two-Dimensional Truss: Sampling, Reliability and Sensitivity ` for the model details) .. figure:: figures/CUS_FEMtab.png @@ -64,7 +67,7 @@ Let us sample 50 samples by latine hypercube sampling (LHS). :figclass: align-center -3. Select the **RV** tab from the input panel. This should be pre-populated with four random variables with same names as those having ``pset`` in the tcl script. For each variable, from the drop down menu change them uniform one and then provide the lower and upper bounds specified for the problem. +3. Select the **RV** tab from the input panel. This should be pre-populated with four random variables with same names as those having ``pset`` in the tcl script. For each variable, from the drop down menu change them to uniform and provide the lower and upper bounds specified for the problem. .. figure:: figures/CUS_RVtab.png :align: center @@ -73,23 +76,23 @@ Let us sample 50 samples by latine hypercube sampling (LHS). .. note:: Only **uniform distribution** is supported in this preliminary example. -4. Next select the **QoI** tab. Here enter ``Node_2_Disp_2`` for the one variable. +4. Next select the **QoI** tab. Here enter ``Node_3_Disp_2`` for the one variable. .. figure:: figures/CUS_QoItab.png :align: center :figclass: align-center -5. Next click on the **Run** button. This will cause the backend application to launch dakota. +5. Next click on the **Run** button. This will cause the backend application to launch the CustomUQ engine which will run UQpy. 6. When done the **RES** panel will be selected and the results will be displayed. The results show the values the mean and standard deviation. Summary: -* Mean = 7.322 -* Std = 4.29 -* Skewness = 1.89 -* Kurtosis = 7.13 +* Mean = 5.77619 +* Std = 2.4664 +* Skewness = 0.456808 +* Kurtosis = 2.7146 Data Table: diff --git a/Examples/qfem-0017/figures/CUS_FEMtab.png b/Examples/qfem-0017/figures/CUS_FEMtab.png index 971b73df..b7971991 100644 Binary files a/Examples/qfem-0017/figures/CUS_FEMtab.png and b/Examples/qfem-0017/figures/CUS_FEMtab.png differ diff --git a/Examples/qfem-0017/figures/CUS_QOItab.png b/Examples/qfem-0017/figures/CUS_QOItab.png index c996695a..67c79047 100644 Binary files a/Examples/qfem-0017/figures/CUS_QOItab.png and b/Examples/qfem-0017/figures/CUS_QOItab.png differ diff --git a/Examples/qfem-0017/figures/CUS_REStab.png b/Examples/qfem-0017/figures/CUS_REStab.png index 84ba63ed..b228732d 100644 Binary files a/Examples/qfem-0017/figures/CUS_REStab.png and b/Examples/qfem-0017/figures/CUS_REStab.png differ diff --git a/Examples/qfem-0017/figures/CUS_RVtab.png b/Examples/qfem-0017/figures/CUS_RVtab.png index 6b8eb274..0a05dfc6 100644 Binary files a/Examples/qfem-0017/figures/CUS_RVtab.png and b/Examples/qfem-0017/figures/CUS_RVtab.png differ diff --git a/Examples/qfem-0017/figures/CUS_UQtab.png b/Examples/qfem-0017/figures/CUS_UQtab.png index b68d8230..d8793ab8 100644 Binary files a/Examples/qfem-0017/figures/CUS_UQtab.png and b/Examples/qfem-0017/figures/CUS_UQtab.png differ diff --git a/Examples/qfem-0017/figures/CUS_UQtab2.png b/Examples/qfem-0017/figures/CUS_UQtab2.png index a4905a59..8b0769d4 100644 Binary files a/Examples/qfem-0017/figures/CUS_UQtab2.png and b/Examples/qfem-0017/figures/CUS_UQtab2.png differ diff --git a/Examples/qfem-0017/figures/CUS_UQtab3.png b/Examples/qfem-0017/figures/CUS_UQtab3.png new file mode 100644 index 00000000..5d108805 Binary files /dev/null and b/Examples/qfem-0017/figures/CUS_UQtab3.png differ diff --git a/Examples/qfem-0017/src/UQpySimpleExample.json b/Examples/qfem-0017/src/UQpySimpleExample.json index d0ff5a25..dc35682a 100644 --- a/Examples/qfem-0017/src/UQpySimpleExample.json +++ b/Examples/qfem-0017/src/UQpySimpleExample.json @@ -1,33 +1,33 @@ { "Parameters" : [ { - "type" : "ComboBox", - "name" : "Sampling Method", - "values" : ["LHS"] + "type" : "ComboBox", + "name" : "Sampling Method", + "values" : ["LHS"] }, { - "type" : "LineEdit", - "name" : "Number of Samples" + "type" : "LineEdit", + "name" : "Number of Samples" }, { "type" : "LineEdit", "name" : "Seed" }, { - "type" : "SpinBox", - "name" : "Number of Concurrent Tasks" + "type" : "SpinBox", + "name" : "Number of Concurrent Tasks" }, { - "type" : "SpinBox", - "name" : "Number of Nodes" + "type" : "SpinBox", + "name" : "Number of Nodes" }, { - "type" : "SpinBox", - "name" : "Cores per Task" + "type" : "SpinBox", + "name" : "Cores per Task" }, { - "type" : "LineEdit", - "name" : "UQ Driver" + "type" : "LineEdit", + "name" : "UQ Driver" } ] } diff --git a/Examples/qfem-0019/figures/qf-0018-FEM.png b/Examples/qfem-0019/figures/qf-0018-FEM.png index cc69ff7f..7bf8ca14 100644 Binary files a/Examples/qfem-0019/figures/qf-0018-FEM.png and b/Examples/qfem-0019/figures/qf-0018-FEM.png differ diff --git a/Examples/qfem-0019/figures/qf-0018-QoI.png b/Examples/qfem-0019/figures/qf-0018-QoI.png index cab70875..29057f6f 100644 Binary files a/Examples/qfem-0019/figures/qf-0018-QoI.png and b/Examples/qfem-0019/figures/qf-0018-QoI.png differ diff --git a/Examples/qfem-0019/figures/qf-0018-RES1.png b/Examples/qfem-0019/figures/qf-0018-RES1.png index b121c816..230744b0 100644 Binary files a/Examples/qfem-0019/figures/qf-0018-RES1.png and b/Examples/qfem-0019/figures/qf-0018-RES1.png differ diff --git a/Examples/qfem-0019/figures/qf-0018-RV.png b/Examples/qfem-0019/figures/qf-0018-RV.png index 45e39a59..dbf800ef 100644 Binary files a/Examples/qfem-0019/figures/qf-0018-RV.png and b/Examples/qfem-0019/figures/qf-0018-RV.png differ diff --git a/Examples/qfem-0019/figures/qf-0018-UQ.png b/Examples/qfem-0019/figures/qf-0018-UQ.png index 6017711b..c376afca 100644 Binary files a/Examples/qfem-0019/figures/qf-0018-UQ.png and b/Examples/qfem-0019/figures/qf-0018-UQ.png differ diff --git a/Examples/qfem-0019/figures/qf-0019-FEM.png b/Examples/qfem-0019/figures/qf-0019-FEM.png index 14593a66..0f746cce 100644 Binary files a/Examples/qfem-0019/figures/qf-0019-FEM.png and b/Examples/qfem-0019/figures/qf-0019-FEM.png differ diff --git a/Examples/qfem-0019/figures/qf-0019-QoI.png b/Examples/qfem-0019/figures/qf-0019-QoI.png index 9e0ddbc7..45b7a564 100644 Binary files a/Examples/qfem-0019/figures/qf-0019-QoI.png and b/Examples/qfem-0019/figures/qf-0019-QoI.png differ diff --git a/Examples/qfem-0019/figures/qf-0019-RES1.png b/Examples/qfem-0019/figures/qf-0019-RES1.png index 7c6ef72b..64f495ca 100644 Binary files a/Examples/qfem-0019/figures/qf-0019-RES1.png and b/Examples/qfem-0019/figures/qf-0019-RES1.png differ diff --git a/Examples/qfem-0019/figures/qf-0019-RES2.png b/Examples/qfem-0019/figures/qf-0019-RES2.png index ae2ca645..6b48b571 100644 Binary files a/Examples/qfem-0019/figures/qf-0019-RES2.png and b/Examples/qfem-0019/figures/qf-0019-RES2.png differ diff --git a/Examples/qfem-0019/figures/qf-0019-RV.png b/Examples/qfem-0019/figures/qf-0019-RV.png index 5ec5c040..39c7ed62 100644 Binary files a/Examples/qfem-0019/figures/qf-0019-RV.png and b/Examples/qfem-0019/figures/qf-0019-RV.png differ diff --git a/Examples/qfem-0019/figures/qf-0019-UQ.png b/Examples/qfem-0019/figures/qf-0019-UQ.png index 42784900..030e783b 100644 Binary files a/Examples/qfem-0019/figures/qf-0019-UQ.png and b/Examples/qfem-0019/figures/qf-0019-UQ.png differ diff --git a/Examples/qfem-0020/src/templatedir/ConfigHeirBayes.json b/Examples/qfem-0020/src/templatedir/ConfigHierBayes.json similarity index 100% rename from Examples/qfem-0020/src/templatedir/ConfigHeirBayes.json rename to Examples/qfem-0020/src/templatedir/ConfigHierBayes.json diff --git a/Examples/qfem-0020/src/templatedir/HierBayesRunner.py b/Examples/qfem-0020/src/templatedir/HierBayesRunner.py new file mode 100644 index 00000000..8903700c --- /dev/null +++ b/Examples/qfem-0020/src/templatedir/HierBayesRunner.py @@ -0,0 +1,240 @@ +# written: Aakash Bangalore Satish @ NHERI SimCenter, UC Berkeley + +import json +import os +import sys +import time +import importlib + +from uqRunner import UqRunner + + +class HierBayesRunner(UqRunner): + def __init__(self) -> None: + super().__init__() + self.n_samples = 0 + self.n_burn_in = 0 + self.tuning_interval = 0 + self.seed = 0 + + def storeUQData(self, uqData): + for val in uqData["Parameters"]: + if val["name"] == "File To Run": + self.file_to_run = val["value"] + elif val["name"] == "# Samples": + self.n_samples = int(val["value"]) + elif val["name"] == "# Burn-in": + self.n_burn_in = int(val["value"]) + elif val["name"] == "Tuning Interval": + self.tuning_interval = int(val["value"]) + elif val["name"] == "Seed": + self.seed = int(val["value"]) + + def performHierBayesSampling(self): + self.dir_name = os.path.dirname(self.file_to_run) + sys.path.append(self.dir_name) + module_name = os.path.basename(self.file_to_run) + module = importlib.import_module(module_name[:-3]) + self.heir_code = module.HierBayesSampler() + + self.trace, self.time_taken, self.inf_object = self.heir_code.perform_sampling( + n_samples=self.n_samples, + n_burn_in=self.n_burn_in, + tuning_interval=self.tuning_interval, + seed=self.seed + ) + + def saveResultsToPklFile(self): + self.saved_pickle_filename = self.heir_code.save_results( + self.trace, self.time_taken, self.inf_object, prefix="realdata_filtered" + ) + + def createHeadingStringsList(self): + self.params = ["fy", "E", "b", "cR1", "cR2", "a1", "a3"] + self.num_params = len(self.params) + self.num_coupons = 34 + + # self.heading_list = ["interface"] + self.heading_list = ["Sample#", "interface"] + for i in range(self.num_coupons): + for j in range(self.num_params): + self.heading_list.append( + "".join(["Coupon_", str(i + 1), "_", self.params[j]]) + ) + + for row in range(self.num_params): + for col in range(row + 1): + self.heading_list.append("".join(["Cov_", str(row + 1), str(col + 1)])) + + for par in self.params: + self.heading_list.append("".join(["Mean_", par])) + + for sig in range(self.num_coupons): + self.heading_list.append("".join(["ErrorVariance_", str(sig + 1)])) + + def makeHeadingRow(self, separator="\t"): + self.headingRow = separator.join([item for item in self.heading_list]) + + def makeOneRowString(self, sample_num, sample, separator="\t"): + initial_string = separator.join([str(sample_num), "1"]) + coupon_string = separator.join( + [ + str(sample[i][j]) + for i in range(self.num_coupons) + for j in range(self.num_params) + ] + ) + cov_string = separator.join( + [ + str(sample[self.num_coupons][row][col]) + for row in range(self.num_params) + for col in range(row + 1) + ] + ) + mean_string = separator.join( + [ + str(sample[self.num_coupons + 1][par_num]) + for par_num in range(self.num_params) + ] + ) + error_string = separator.join( + [str(sample[-1][coupon_num]) for coupon_num in range(self.num_coupons)] + ) + row_string = separator.join( + [initial_string, coupon_string, cov_string, mean_string, error_string] + ) + return row_string + + def makeTabularResultsFile(self, save_file_name="tabularResults.out", separator="\t"): + self.createHeadingStringsList() + self.makeHeadingRow(separator=separator) + + cwd = os.getcwd() + save_file_dir = os.path.dirname(cwd) + save_file_full_path = os.path.join(save_file_dir, save_file_name) + with open(save_file_full_path, "w") as f: + f.write(self.headingRow) + f.write("\n") + for sample_num, sample in enumerate(self.trace): + row = self.makeOneRowString( + sample_num=sample_num, sample=sample, separator=separator + ) + f.write(row) + f.write("\n") + + # def makePlots(self): + # from temp_postprocess_real_data import make_plots + + # make_plots(self.saved_pickle_filename) + + def startTimer(self): + self.startingTime = time.time() + + def computeTimeElapsed(self): + self.timeElapsed = time.time() - self.startingTime + + def printTimeElapsed(self): + self.computeTimeElapsed() + print("Time elapsed: {:0.2f} minutes".format(self.timeElapsed / 60)) + + def startSectionTimer(self): + self.sectionStartingTime = time.time() + + def resetSectionTimer(self): + self.startSectionTimer() + + def computeSectionTimeElapsed(self): + self.sectionTimeElapsed = time.time() - self.sectionStartingTime + + def printSectionTimeElapsed(self): + self.computeSectionTimeElapsed() + print("Time elapsed: {:0.2f} minutes".format(self.sectionTimeElapsed / 60)) + + @staticmethod + def printEndMessages(): + print("Heirarchical Bayesian estimation done!") + + def runUQ( + self, + uqData, + simulationData, + randomVarsData, + demandParams, + workingDir, + runType, + localAppDir, + remoteAppDir, + ): + """ + This function configures and runs hierarchical Bayesian estimation based on the + input UQ configuration, simulation configuration, random variables, + and requested demand parameters + + Input: + uqData: JsonObject that UQ options as input into the quoFEM GUI + simulationData: JsonObject that contains information on the analysis package to run and its + configuration as input in the quoFEM GUI + randomVarsData: JsonObject that specifies the input random variables, their distributions, + and associated parameters as input in the quoFEM GUI + demandParams: JsonObject that specifies the demand parameters as input in the quoFEM GUI + workingDir: Directory in which to run simulations and store temporary results + runType: Specifies whether computations are being run locally or on an HPC cluster + localAppDir: Directory containing apps for local run + remoteAppDir: Directory containing apps for remote run + """ + self.startTimer() + self.storeUQData(uqData=uqData) + os.chdir(workingDir) + self.performHierBayesSampling() + self.saveResultsToPklFile() + self.makeTabularResultsFile() + # self.makePlots() + self.printTimeElapsed() + self.printEndMessages() + + +class testRunUQ: + def __init__(self, json_file_path_string) -> None: + self.json_file_path_string = json_file_path_string + self.getUQData() + self.createRunner() + self.runTest() + + def getUQData(self): + with open(os.path.abspath(self.json_file_path_string), "r") as f: + input_data = json.load(f) + + self.ApplicationData = input_data["Applications"] + self.uqData = input_data["UQ_Method"] + self.simulationData = self.ApplicationData["FEM"] + self.randomVarsData = input_data["randomVariables"] + self.demandParams = input_data["EDP"] + self.localAppDir = input_data["localAppDir"] + self.remoteAppDir = input_data["remoteAppDir"] + self.workingDir = input_data["workingDir"] + self.workingDir = os.path.join(self.workingDir, "tmp.SimCenter", "templateDir") + self.runType = "runningLocal" + + def createRunner(self): + self.runner = HierBayesRunner() + + def runTest(self): + self.runner.runUQ( + uqData=self.uqData, + simulationData=self.simulationData, + randomVarsData=self.randomVarsData, + demandParams=self.demandParams, + workingDir=self.workingDir, + runType=self.runType, + localAppDir=self.localAppDir, + remoteAppDir=self.remoteAppDir, + ) + + +def main(): + filename = "/Users/aakash/Desktop/SimCenter/Joel/heirarchical-refactor/scInput.json" + testRunUQ(filename) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Examples/qfem-0020/src/templatedir/main_synthetic_data.py b/Examples/qfem-0020/src/templatedir/main_synthetic_data.py index 8a4609e1..c5963481 100644 --- a/Examples/qfem-0020/src/templatedir/main_synthetic_data.py +++ b/Examples/qfem-0020/src/templatedir/main_synthetic_data.py @@ -15,7 +15,7 @@ from hierarchical_inference_sampling_v2 import HierarchicalInferenceSampling -class HeirBayesSampler(object): +class HierBayesSampler(object): def perform_sampling(self, n_samples=50, n_burn_in=20, tuning_interval=10, seed=1): DATA_LOCATION = os.path.abspath(os.path.join(__file__, "../synthetic_data")) @@ -72,8 +72,8 @@ def save_results(self, trace, time_taken, inf_object, prefix): def main(): t1 = time.time() - sampler = HeirBayesSampler() - trace, time_taken, inf_object = sampler.perform_sampling( + sampler = HierBayesSampler() + trace, time_taken, inf_object, _ = sampler.perform_sampling( n_samples=50, n_burn_in=20, tuning_interval=10, seed=1 ) filename = sampler.save_results( diff --git a/Examples/qfem-0020/src/templatedir/scInput.json b/Examples/qfem-0020/src/templatedir/scInput.json index 476ffa09..a50825f0 100644 --- a/Examples/qfem-0020/src/templatedir/scInput.json +++ b/Examples/qfem-0020/src/templatedir/scInput.json @@ -26,7 +26,7 @@ "FEM": { }, "UQ_Method": { - "Config File": "{Current_Dir}/ConfigHeirBayes.json", + "Config File": "{Current_Dir}/ConfigHierBayes.json", "Parameters": [ { "name": "File To Run", @@ -56,7 +56,7 @@ { "name": "UQ Driver", "type": "LineEdit", - "value": "HeirBayes" + "value": "HierBayes" } ], "uqEngine": "CustomUQ"