Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into barbaros_transport
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyan1214 committed Nov 12, 2024
2 parents fe542be + a480daf commit f62d72b
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 120 deletions.
21 changes: 1 addition & 20 deletions modules/createEVENT/IsolatedBuildingCFD/setup_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,6 @@ def write_boundary_data_files(input_json_path, case_path):
foam.write_foam_field(wind_profiles[:, 8:17], bd_path + 'L')


<<<<<<< HEAD
def write_vtk_plane_file(input_json_path, template_dict_path, case_path):

#Read JSON data
Expand Down Expand Up @@ -2086,9 +2085,6 @@ def write_vtk_plane_file(input_json_path, template_dict_path, case_path):

if __name__ == '__main__': # noqa: W291
# noqa: W293
=======
if __name__ == '__main__':
>>>>>>> upstream/master
input_args = sys.argv

# Set filenames
Expand Down Expand Up @@ -2135,18 +2131,9 @@ def write_vtk_plane_file(input_json_path, template_dict_path, case_path):
# Write results to be monitored
write_base_forces_file(input_json_path, template_dict_path, case_path)
write_story_forces_file(input_json_path, template_dict_path, case_path)
<<<<<<< HEAD
write_generated_pressure_probes_file(input_json_path, template_dict_path, case_path)
write_imported_pressure_probes_file(input_json_path, template_dict_path, case_path)
write_vtk_plane_file(input_json_path, template_dict_path, case_path)
=======
write_generated_pressure_probes_file(
input_json_path, template_dict_path, case_path
)
write_imported_pressure_probes_file(
input_json_path, template_dict_path, case_path
)
>>>>>>> upstream/master

# Write fvSolution dict
write_fvSolution_file(input_json_path, template_dict_path, case_path)
Expand All @@ -2170,10 +2157,4 @@ def write_vtk_plane_file(input_json_path, template_dict_path, case_path):
# write_DFSRTurbDict_file(input_json_path, template_dict_path, case_path)

# Write TInf files
write_boundary_data_files(input_json_path, case_path)
<<<<<<< HEAD


# noqa: W293
=======
>>>>>>> upstream/master
write_boundary_data_files(input_json_path, case_path)
2 changes: 1 addition & 1 deletion modules/performFEM/OpenSeesPy/createOpenSeesPyDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int createDriver(int argc, const char **argv) {
std::ifstream modelFile(mainScript);
std::string line;
while (std::getline(modelFile, line)) {
std::cout << line << std::endl; // Print line to console
// std::cout << line << std::endl; // Print line to console
templateFile << line << std::endl; // Write line to template file
}
templateFile.close();
Expand Down
5 changes: 4 additions & 1 deletion modules/performUQ/UCSD_UQ/UCSD_UQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ def main(args): # noqa: D103
text=True,
check=False,
)
result.check_returncode()
result.check_returncode() # Raises CalledProcessError if return code is non-zero
except subprocess.CalledProcessError:
with open(err_file, 'a') as f: # noqa: PTH123
f.write(f'ERROR: {result.stderr}')
else:
# Print success if no error occurs
print('SUCCESS') # noqa: T201


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions modules/performUQ/UCSD_UQ/mainscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import shlex
import sys
import traceback
from pathlib import Path

path_to_common_uq = Path(__file__).parent.parent / 'common'
Expand Down Expand Up @@ -64,10 +65,11 @@ def main(input_args): # noqa: D103
# Try running the main_function and catch any exceptions
try:
main_function(command_list)
except Exception as e: # noqa: BLE001
except Exception: # noqa: BLE001
# Write the exception message to the .err file
with err_file.open('a') as f:
f.write(f'ERROR: {e!s}\n')
f.write('ERROR: An exception occurred:\n')
f.write(f'{traceback.format_exc()}\n')


# ======================================================================================================================
Expand Down
52 changes: 33 additions & 19 deletions modules/performUQ/UCSD_UQ/mainscript_hierarchical_bayesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def loglikelihood_function(residual, error_variance_sample): # noqa: D103
return ll


def main(input_args): # noqa: D103
def main(input_args): # noqa: C901, D103
# Initialize analysis
working_directory = Path(input_args[0]).resolve()
template_directory = Path(input_args[1]).resolve() # noqa: F841
Expand All @@ -78,24 +78,38 @@ def main(input_args): # noqa: D103

# input_file_full_path = template_directory / input_file

with open(input_file, encoding='utf-8') as f: # noqa: PTH123
inputs = json.load(f)

uq_inputs = inputs['UQ']
rv_inputs = inputs['randomVariables']
edp_inputs = inputs['EDP']

(
parallel_pool,
function_to_evaluate,
joint_distribution,
num_rv,
num_edp,
list_of_model_evaluation_functions,
list_of_datasets,
list_of_dataset_lengths,
restart_file,
) = preprocess_hierarchical_bayesian.preprocess_arguments(input_args)
try:
with open(input_file, encoding='utf-8') as f: # noqa: PTH123
inputs = json.load(f)

uq_inputs = inputs['UQ']
rv_inputs = inputs['randomVariables']
edp_inputs = inputs['EDP']
except FileNotFoundError as fnf_error:
msg = f"Input file '{input_file}' not found. Please check the file path."
raise FileNotFoundError(msg) from fnf_error
except json.JSONDecodeError as json_error:
msg = f"Error decoding JSON from file '{input_file}'. Ensure the file contains valid JSON."
raise ValueError(msg) from json_error
except KeyError as key_error:
msg = f'Missing required key in JSON data: {key_error}. Please check the input file format.'
raise KeyError(msg) from key_error

try:
(
parallel_pool,
function_to_evaluate,
joint_distribution,
num_rv,
num_edp,
list_of_model_evaluation_functions,
list_of_datasets,
list_of_dataset_lengths,
restart_file,
) = preprocess_hierarchical_bayesian.preprocess_arguments(input_args)
except Exception as e:
msg = "Error during the preprocessing of arguments in 'preprocess_hierarchical_bayesian'."
raise RuntimeError(msg) from e
transformation_function = joint_distribution.u_to_x

prior_inverse_gamma_parameters = uq_utilities.InverseGammaParameters(
Expand Down
7 changes: 6 additions & 1 deletion modules/performUQ/UCSD_UQ/runTMCMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ def run_TMCMC( # noqa: C901, N802, PLR0913
# Evaluate log-likelihood at current samples Sm
if run_type == 'runningLocal':
processor_count = mp.cpu_count()
if processor_count > 32: # noqa: PLR2004

max_num_processes = 32 # noqa: PLR2004 max number of processes to use for multiprocessing when running locally
if processor_count > max_num_processes:
processor_count = 8

pool = Pool(processes=processor_count)
write_eval_data_to_logfile(
logfile,
Expand All @@ -276,6 +279,7 @@ def run_TMCMC( # noqa: C901, N802, PLR0913
stage_num=stage_number,
)
outputs = pool.starmap(runFEM, iterables)

# pool does not start
# mp.set_start_method('forkserver', force=True)
# processor_count = mp.cpu_count()
Expand All @@ -299,6 +303,7 @@ def run_TMCMC( # noqa: C901, N802, PLR0913
# stage_num=stage_number,
# )
# outputs = pool.starmap(runFEM, iterables)

log_likelihoods_list = []
predictions_list = []
for output in outputs:
Expand Down
11 changes: 10 additions & 1 deletion modules/performUQ/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ target_include_directories(commonUQ PUBLIC ${CONAN_INCLUDE_DIRS_JANSSON})
simcenter_add_python_script(SCRIPT uq_utilities.py)
simcenter_add_python_script(SCRIPT quoFEM_RV_models.py)
simcenter_add_python_script(SCRIPT parallel_runner_mpi4py.py)
add_subdirectory(ERAClasses)
add_subdirectory(ERAClasses)

simcenter_add_python_script(SCRIPT adaptive_doe.py)
simcenter_add_python_script(SCRIPT common_datamodels.py)
simcenter_add_python_script(SCRIPT convergence_metrics.py)
simcenter_add_python_script(SCRIPT gp_ab_algorithm.py)
simcenter_add_python_script(SCRIPT gp_model.py)
simcenter_add_python_script(SCRIPT principal_component_analysis.py)
simcenter_add_python_script(SCRIPT space_filling_doe.py)
simcenter_add_python_script(SCRIPT tmcmc.py)
Loading

0 comments on commit f62d72b

Please sign in to comment.