Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/version4' into feature/v…
Browse files Browse the repository at this point in the history
…ersion4
  • Loading branch information
dgiovanis committed Apr 5, 2022
2 parents bdab112 + d5987e3 commit 4fd9370
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
12 changes: 0 additions & 12 deletions tests/unit_tests/reliability/pfn.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import numpy as np

def Example1(samples=None):

x = np.zeros(samples.shape[0])

omega = 6.
epsilon = 0.0001

for i in range(samples.shape[0]):
add = samples[i][1] - samples[i][0]*(omega+epsilon)**2
diff = samples[i][0]*(omega-epsilon)**2 - samples[i][1]
x[i] = np.maximum(add, diff)

return x



Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/reliability/pfn5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np


def Example1(samples=None):

x = np.zeros(samples.shape[0])

omega = 6.
epsilon = 0.0001

for i in range(samples.shape[0]):
add = samples[i][1] - samples[i][0]*(omega+epsilon)**2
diff = samples[i][0]*(omega-epsilon)**2 - samples[i][1]
x[i] = np.maximum(add, diff)

return x
3 changes: 1 addition & 2 deletions tests/unit_tests/reliability/test_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def test_subset(): # Define the structural problem
n_variables = 2
model = 'pfn.py'
model = 'pfn5.py'
Example = 'Example1'

omega = 6
Expand Down Expand Up @@ -50,7 +50,6 @@ def test_subset(): # Define the structural problem

print(SuS_object.failure_probability)
assert SuS_object.failure_probability == 3.1200000000000006e-05
shutil.rmtree(RunModelObject_SuS.model_dir)



Expand Down
24 changes: 14 additions & 10 deletions tests/unit_tests/run_model/test_RunModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from beartype.roar import BeartypeCallHintPepParamException

from UQpy.run_model import ThirdPartyModel, RunModel_New
from UQpy.sampling import MonteCarloSampling
from UQpy.run_model.RunModel import RunModel
from UQpy.distributions import Normal
Expand All @@ -14,8 +15,8 @@
x_mcs_new = MonteCarloSampling(distributions=[d, d, d], nsamples=5, random_state=2345)
verbose_parameter = True

dir_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(dir_path)
os.chdir('./tests/unit_tests/run_model')


def test_div_zero():
print(os.getcwd())
Expand Down Expand Up @@ -138,13 +139,14 @@ def test_python_parallel_workflow_function():

def test_third_party_serial():
names = ['var1', 'var11', 'var111']
m = RunModel(ntasks=1, model_script='python_model_sum_scalar.py',
input_template='sum_scalar.py', var_names=names, model_object_name="matlab",
output_script='process_third_party_output.py', output_object_name='read_output',
resume=False, fmt="{:>10.4f}", delete_files=True)
model = ThirdPartyModel(model_script='python_model_sum_scalar.py',
input_template='sum_scalar.py', var_names=names, model_object_name="matlab",
output_script='process_third_party_output.py', output_object_name='read_output',
fmt="{:>10.4f}", delete_files=True)
m = RunModel_New(model=model)
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_dir)
shutil.rmtree(m.model.model_dir)


def test_third_party_serial_output_class():
Expand All @@ -170,9 +172,11 @@ def test_third_party_serial_no_output_class():

def test_third_party_serial_no_output_function():
names = ['var1', 'var11', 'var111']
m = RunModel(ntasks=1, model_script='python_model_sum_scalar.py', input_template='sum_scalar.py', var_names=names,
model_object_name="matlab", output_script='process_third_party_output.py', resume=False,
fmt="{:>10.4f}", verbose=verbose_parameter, delete_files=True)
model = ThirdPartyModel(model_script='python_model_sum_scalar.py',
input_template='sum_scalar.py', var_names=names, model_object_name="matlab",
output_script='process_third_party_output.py', output_object_name='read_output',
fmt="{:>10.4f}", delete_files=True)
m = RunModel_New(model=model)
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_dir)
Expand Down

0 comments on commit 4fd9370

Please sign in to comment.