I am looking for efficient ways to wrap a computer simulation model in order to perform uncertainty quantification on it. More precisely, my numerical model uses input files containing input variables, after executing it, the model creates output repertories containing files with output variables of interest. My goal is to first wrap this process by a PythonFunction, second to distribute calls to this function. After an overview of the OT documentation and its modules, I used coupling_tools to create a wrapper which achieves my first goal but I struggle at finding efficient ways to distribute it which implies handling simultaneous writings on the input files and output repertory management. The otwrapy module seems to provide some complementary tools but I am looking for examples that combine these two modules or extended otwrapy examples.
To illustrate my issue, please find attached a mock Python script corresponding to my current developments.
import openturns as ot import openturns.coupling_tools as ct import numpy as np import os # This script is an illustration of a wrapper of two computer # chained simulation models (called code1 and code2). code1_command = "./code1.exe code1_input.inp" code2_command = "./code2.exe code2_main.par" def code1_code2_simulator(x): os.chdir("./ENVIR/") # Modify code1 input file code1_in_file = "code1_input.inp" code1_intemp_file = "code1_input_template.inp" # my_seed: random seed # x0: first variable # x1: second variable code1_replaced_tokens = ["@my_seed", "@x0", "@x1"] ct.replace(code1_intemp_file, code1_in_file, code1_replaced_tokens, x[:3]) # Execute code1 ct.execute(code1_command) print("Code1 done") # Modify code2 input files code2_in_file = "code2_input.dat" code2_intemp_file = "code2_input_template.dat" # x2: third variable code2_replaced_tokens = ["@x2"] ct.replace(code2_intemp_file, code2_in_file, code2_replaced_tokens, [x]) os.chdir("..") code2_main_file = "main.par" code2_maintemp_file = "main_template.par" # nout: output rep index (e.g. 34 for repertory /OUT34) code2_replaced_tokens = ["@nout"] ct.replace(code2_main_file, code2_maintemp_file, code2_replaced_tokens, [x]) # Exectue code2 ct.execute(code2_command) print("Code2 done") return None # My DoE : x_1 = [1, 12.6, 3, 1.6, 10] # Wrapper execution code1_code2_simulator(x_1)
Thanks in advance for any idea or suggestion regarding this topic.