Skip to content

Commit

Permalink
Example updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed May 8, 2022
1 parent bc4648e commit eb64378
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 142 deletions.
16 changes: 8 additions & 8 deletions docs/code/RunModel/abaqus_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
==================================
"""


# %% md
#
# Import the necessary libraries.

# %%

import glob
import pickle
import time

import os
from UQpy.distributions import Normal, Uniform
from UQpy.run_model.RunModel import *
from UQpy.run_model.RunModel import RunModel
from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel
from UQpy.sampling import MonteCarloSampling

calling_directory = os.getcwd()
Expand All @@ -36,12 +36,12 @@

# %%

abaqus_sfe_model = RunModel(model_script='abaqus_fire_analysis.py', input_template='abaqus_input.py',
output_script='extract_abaqus_output.py', var_names=var_names, ntasks=24,
model_dir='SFE_MCS', verbose=True, cores_per_task=1)
m = ThirdPartyModel(model_script='abaqus_fire_analysis.py', input_template='abaqus_input.py',
output_script='extract_abaqus_output.py', var_names=var_names,
model_dir='SFE_MCS', )
abaqus_sfe_model = RunModel(cores_per_task=1, ntasks=24, model=m)
print('Example: Created the model object.')


# %% md
#
# Towards defining the sampling scheme
Expand Down
16 changes: 5 additions & 11 deletions docs/code/RunModel/ls_dyna_example_multijob.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
==================================
"""


# %% md
#
# Import the necessary libraries.

# %%
from UQpy.distributions import Uniform
from UQpy.run_model.RunModel import RunModel
from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel
from UQpy.sampling import MonteCarloSampling

# %% md
Expand Down Expand Up @@ -42,13 +42,7 @@
# Run the model.

# %%

run_ = RunModel(samples=x.samples, ntasks=6, model_script='dyna_script.py', input_template='dyna_input.k',
var_names=['x0', 'y0', 'z0', 'R0', 'x1', 'y1', 'z1', 'R1'], model_dir='dyna_test', cluster=True,
verbose=False, fmt='{:>10.4f}', cores_per_task=12)






m = ThirdPartyModel(model_script='dyna_script.py', input_template='dyna_input.k',
var_names=['x0', 'y0', 'z0', 'R0', 'x1', 'y1', 'z1', 'R1'], model_dir='dyna_test',
fmt='{:>10.4f}')
run_ = RunModel(samples=x.samples, ntasks=6, cores_per_task=12, model=m)
14 changes: 4 additions & 10 deletions docs/code/RunModel/ls_dyna_example_singlejob.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
==================================
"""


# %% md
#
# Import the necessary libraries.

# %%
from UQpy.distributions import Uniform
from UQpy.run_model.RunModel import RunModel
from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel
from UQpy.sampling import MonteCarloSampling

# %% md
Expand Down Expand Up @@ -40,12 +40,6 @@
# Run the model.

# %%
run_ = RunModel(samples=x.samples, ntasks=1, model_script='dyna_script.py', input_template='dyna_input.k',
var_names=['x0', 'y0', 'z0', 'R0', 'x1', 'y1', 'z1', 'R1'], model_dir='dyna_test', cluster=True,
verbose=False, fmt='{:>10.4f}', cores_per_task=48)






m = ThirdPartyModel(model_script='dyna_script.py', input_template='dyna_input.k',
var_names=['x0', 'y0', 'z0', 'R0', 'x1', 'y1', 'z1', 'R1'], model_dir='dyna_test', fmt='{:>10.4f}')
run_ = RunModel(samples=x.samples, ntasks=1, cores_per_task=48, model=m)
92 changes: 45 additions & 47 deletions docs/code/RunModel/matlab_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
==================================
"""


# %% md
#
# The RunModel class is capable of passing input in different formats into a single computational model. This means that
Expand Down Expand Up @@ -64,6 +63,7 @@

from UQpy.sampling import MonteCarloSampling
from UQpy.run_model.RunModel import RunModel
from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel
from UQpy.distributions import Normal
import time
import numpy as np
Expand Down Expand Up @@ -133,10 +133,11 @@
if pick_model == 'scalar' or pick_model == 'all':
# Call to RunModel - Here we run the model while instantiating the RunModel object.
t = time.time()
m = RunModel(ntasks=1, model_script='matlab_model_sum_scalar.py',
input_template='sum_scalar.m', var_names=names, model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model', fmt="{:>10.4f}", verbose=True)
model = ThirdPartyModel(model_script='matlab_model_sum_scalar.py',
input_template='sum_scalar.m', var_names=names, model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
model_dir='Matlab_Model', fmt="{:>10.4f}")
m = RunModel(ntasks=1, model=model)
m.run(x_mcs.samples)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
Expand All @@ -145,7 +146,6 @@
print("The values returned from the Matlab simulation:")
print(m.qoi_list)


# %% md
#
# 1.2 Samples passed as list, no format specification, parallel execution
Expand All @@ -161,18 +161,18 @@
if pick_model == 'scalar' or pick_model == 'all':
# Call to RunModel with samples as a list - Again we run the model while instantiating the RunModel object.
t = time.time()
m = RunModel(samples=x_mcs_list, ntasks=2, model_script='matlab_model_sum_scalar.py',
input_template='sum_scalar.m', var_names=names, model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output', resume=False,
model_dir='Matlab_Model', verbose=True)
model = ThirdPartyModel(model_script='matlab_model_sum_scalar.py',
input_template='sum_scalar.m', var_names=names, model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
model_dir='Matlab_Model')
m = RunModel(samples=x_mcs_list, ntasks=2, model=model)
t_par_matlab = time.time() - t
print("\nTime for parallel execution:")
print(t_par_matlab)
print()
print("The values retured from the Matlab simulation:")
print(m.qoi_list)


# %% md
#
# Example 2: Single tri-variate random variable
Expand Down Expand Up @@ -228,13 +228,12 @@

if pick_model == 'vector' or pick_model == 'all':
# Call to RunModel - Here we run the model while instantiating the RunModel object.
# Notice that we do not specify var_names. This will default to a single variable with name x0. In this case,
# we will read them in by indexing in the input_template.
t = time.time()
m = RunModel(samples=x_mcs_tri, ntasks=1, model_script='matlab_model_sum_vector_indexed.py',
input_template='sum_vector_indexed.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model', fmt="{:>10.4f}")
model = ThirdPartyModel(model_script='matlab_model_sum_vector_indexed.py',
input_template='sum_vector_indexed.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
model_dir='Matlab_Model', fmt="{:>10.4f}", var_names=['x0'])
m = RunModel(samples=x_mcs_tri, ntasks=1, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
Expand All @@ -255,13 +254,12 @@

if pick_model == 'vector' or pick_model == 'all':
# Call to RunModel - Here we run the model while instantiating the RunModel object.
# Notice that we do not specify var_names. This will default to a single variable with name x0. In this case,
# we will read them in by indexing in the input_template.
t = time.time()
m = RunModel(samples=x_mcs_tri_list, ntasks=2, model_script='matlab_model_sum_vector_indexed.py',
input_template='sum_vector_indexed.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model')
model = ThirdPartyModel(model_script='matlab_model_sum_vector_indexed.py',
input_template='sum_vector_indexed.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
model_dir='Matlab_Model', var_names=['x0'])
m = RunModel(samples=x_mcs_tri_list, ntasks=2, model=model)
t_ser_matlab = time.time() - t
print("\nTime for parallel execution:")
print(t_ser_matlab)
Expand All @@ -285,18 +283,18 @@
# Notice that we do not specify var_names. This will default to a single variable with name x0. In this case,
# we will read them in by indexing in the input_template.
t = time.time()
m = RunModel(samples=x_mcs_tri, ntasks=1, model_script='matlab_model_sum_vector.py',
input_template='sum_vector.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model', fmt="{:>10.4f}")
model = ThirdPartyModel(model_script='matlab_model_sum_vector.py',
input_template='sum_vector.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
model_dir='Matlab_Model', fmt="{:>10.4f}", var_names=['x0'])
m = RunModel(samples=x_mcs_tri, ntasks=1, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
print()
print("The values returned from the Matlab simulation:")
print(m.qoi_list)


# %% md
#
# Example 3: Passing a scalar and an array to RunModel
Expand Down Expand Up @@ -388,10 +386,11 @@
# case, x0 is a scalar and x1 is a 3x3 matrix. We will read the matrix in without indexing in the
# input_template.
t = time.time()
m = RunModel(samples=x_mixed_array, ntasks=1, model_script='matlab_model_det.py',
input_template='prod_determinant.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model', fmt="{:>10.4f}")
model = ThirdPartyModel(model_script='matlab_model_det.py',
input_template='prod_determinant.m', model_object_name="matlab", var_names=['x0', 'x1'],
output_script='process_matlab_output.py', output_object_name='read_output',
model_dir='Matlab_Model', fmt="{:>10.4f}")
m = RunModel(samples=x_mixed_array, ntasks=1, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
Expand All @@ -412,14 +411,13 @@

if pick_model == 'mixed' or pick_model == 'all':
# Call to RunModel - Here we run the model while instantiating the RunModel object.
# Notice that we do not specify var_names. This will default to two variables with names x0 and x1. In this
# case, x0 is a scalar and x1 is a 3x3 matrix. We will read the matrix in with indexing in the
# input_template.
# We will read the matrix in with indexing in the input_template.
t = time.time()
m = RunModel(samples=x_mixed_array, ntasks=1, model_script='matlab_model_det_index.py',
model = ThirdPartyModel(model_script='matlab_model_det_index.py',
input_template='prod_determinant_index.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model', fmt="{:>10.4f}")
model_dir='Matlab_Model', fmt="{:>10.4f}", var_names=['x0', 'x1'])
m = RunModel(samples=x_mixed_array, ntasks=1, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
Expand All @@ -442,14 +440,12 @@

if pick_model == 'mixed' or pick_model == 'all':
# Call to RunModel - Here we run the model while instantiating the RunModel object.
# Notice that we do not specify var_names. This will default to two variables with names x0 and x1. In this
# case, x0 is a scalar and x1 is a 3x3 matrix. We will read the matrix in without indexing in the
# input_template.
t = time.time()
m = RunModel(samples=x_mixed, ntasks=2, model_script='matlab_model_det.py',
model = ThirdPartyModel(model_script='matlab_model_det.py',
input_template='prod_determinant.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model')
model_dir='Matlab_Model', var_names=['x0', 'x1'])
m = RunModel(samples=x_mixed, ntasks=2, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
Expand Down Expand Up @@ -477,10 +473,11 @@
# case, x0 is a scalar and x1 is a 3x3 matrix. We will read the matrix in with indexing in the
# input_template.
t = time.time()
m = RunModel(samples=x_mixed, ntasks=2, model_script='matlab_model_det_index.py',
model = ThirdPartyModel(model_script='matlab_model_det_index.py',
input_template='prod_determinant_index.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model')
model_dir='Matlab_Model', var_names=['x0', 'x1'])
m = RunModel(samples=x_mixed, ntasks=2, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
Expand Down Expand Up @@ -508,13 +505,14 @@
# case, x0 is a scalar and x1 is a 3x3 matrix. We will read the matrix in with indexing in the
# input_template.
t = time.time()
m = RunModel(samples=x_mixed_array, ntasks=1, model_script='matlab_model_det_partial.py',
model = ThirdPartyModel(model_script='matlab_model_det_partial.py',
input_template='prod_determinant_partial.m', model_object_name="matlab",
output_script='process_matlab_output.py', output_object_name='read_output',
resume=False, model_dir='Matlab_Model', fmt="{:>10.4f}")
model_dir='Matlab_Model', fmt="{:>10.4f}", var_names=['x0', 'x1'])
m = RunModel(samples=x_mixed_array, ntasks=1, model=model)
t_ser_matlab = time.time() - t
print("\nTime for serial execution:")
print(t_ser_matlab)
print()
print("The values returned from the Python simulation:")
print(m.qoi_list)
print(m.qoi_list)
11 changes: 6 additions & 5 deletions docs/code/RunModel/opensees_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
==================================
"""


# %% md
#
# Import the necessary libraries.
Expand All @@ -14,6 +13,7 @@

from UQpy.distributions import Uniform
from UQpy.run_model.RunModel import RunModel
from UQpy.run_model.model_execution.ThirdPartyModel import ThirdPartyModel
from UQpy.sampling import MonteCarloSampling

# %% md
Expand Down Expand Up @@ -41,12 +41,13 @@

# %%

names_ = ['fc1', 'fy1', 'Es1', 'fc2', 'fy2', 'Es2', 'fc3', 'fy3', 'Es3', 'fc4', 'fy4', 'Es4', 'fc5', 'fy5', 'Es5',
names_ = ['fc1', 'fy1', 'Es1', 'fc2', 'fy2', 'Es2', 'fc3', 'fy3', 'Es3', 'fc4', 'fy4', 'Es4', 'fc5', 'fy5', 'Es5',
'fc6', 'fy6', 'Es6']

opensees_rc6_model = RunModel(samples=samples, ntasks=5, model_script='opensees_model.py',
input_template='import_variables.tcl', var_names=names_, model_object_name="opensees_run",
output_script='process_opensees_output.py', output_object_name='read_output')
m = ThirdPartyModel(model_script='opensees_model.py', input_template='import_variables.tcl', var_names=names_,
model_object_name="opensees_run", output_script='process_opensees_output.py',
output_object_name='read_output')
opensees_rc6_model = RunModel(samples=samples, ntasks=5, model=m)

outputs = opensees_rc6_model.qoi_list
print(outputs)
Loading

0 comments on commit eb64378

Please sign in to comment.