def test_python_serial_workflow_class(): model = PythonModel(model_script='python_model.py', model_object_name='SumRVs') model_python_serial_class = RunModel(model=model) model_python_serial_class.run(samples=x_mcs.samples) assert np.allclose( np.array(model_python_serial_class.qoi_list).flatten(), np.sum(x_mcs.samples, axis=1))
def test_python_serial_workflow_function_vectorized(): model = PythonModel(model_script='python_model.py', model_object_name='sum_rvs') model_python_serial_function = RunModel(model=model) model_python_serial_function.run(samples=x_mcs.samples) assert np.allclose( np.array(model_python_serial_function.qoi_list).flatten(), np.sum(x_mcs.samples, axis=1))
def test_python_parallel_workflow_function(): model = PythonModel(model_script='python_model.py', model_object_name='sum_rvs') model_python_parallel_function = RunModel(model=model, ntasks=3) model_python_parallel_function.run(samples=x_mcs.samples) assert np.allclose( np.array(model_python_parallel_function.qoi_list).flatten(), np.sum(x_mcs.samples, axis=1)) shutil.rmtree(model_python_parallel_function.model_dir)
def test_append_samples_true(): model = PythonModel(model_script='python_model.py', model_object_name='SumRVs') model_python_serial_class = RunModel(model=model, samples=x_mcs.samples) assert np.allclose( np.array(model_python_serial_class.qoi_list).flatten(), np.sum(x_mcs.samples, axis=1)) model_python_serial_class.run(x_mcs_new.samples, append_samples=True) assert np.allclose( np.array(model_python_serial_class.qoi_list).flatten(), np.sum(np.vstack((x_mcs.samples, x_mcs_new.samples)), axis=1))
def test_third_party_parallel(): names = ['var1', 'var11', 'var111'] model = ThirdPartyModel(model_script='python_model_sum_scalar.py', fmt="{:>10.4f}", delete_files=True, input_template='sum_scalar.py', var_names=names, model_object_name="matlab", output_script='process_third_party_output.py', output_object_name='read_output') m = RunModel(model=model, ntasks=3) m.run(x_mcs.samples) assert np.allclose(np.array(m.qoi_list).flatten(), np.sum(x_mcs.samples, axis=1), atol=1e-4) shutil.rmtree(m.model.model_dir)
# %% d_n = Normal(loc=50, scale=400) d_u = Uniform(location=2.50e8, scale=1.75e7) x_mcs = MonteCarloSampling(distributions=[d_n, d_u], samples_number=100, random_state=987979) # %% md # # Running simulations using the previously defined model object and samples # %% sample_points = x_mcs.samples abaqus_sfe_model.run(samples=sample_points) # %% md # # The outputs from the analysis are the values of the performance function. # %% qois = abaqus_sfe_model.qoi_list # %% md # # Save the samples and the qois in a dictionary called results with keys 'inputs' and 'outputs'. # %% results = {'inputs': sample_points, 'outputs': qois}