-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ITISFoundation/add_postinstall_tests
Add tests after building the wheel
- Loading branch information
Showing
17 changed files
with
440 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ dakota | |
dakota_wheel-* | ||
wheelhouse | ||
itis_dakota/_version.py | ||
/wheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
environment | ||
tabular_data | ||
tabular_data_file | ||
'dakota_tabular.dat' | ||
top_method_pointer = 'ADAPTIVE_SAMPLING' | ||
|
||
method | ||
id_method = 'ADAPTIVE_SAMPLING' | ||
adaptive_sampling | ||
max_iterations 5 | ||
samples_on_emulator 20 | ||
fitness_metric gradient | ||
initial_samples = 1 | ||
model_pointer = "TRUE_MODEL" | ||
seed 41 | ||
batch_selection | ||
naive | ||
misc_options | ||
'batch_size=10' | ||
|
||
model | ||
id_model = 'TRUE_MODEL' | ||
single | ||
interface_pointer = 'INTERFACE' | ||
variables_pointer = 'VARIABLES' | ||
responses_pointer = 'RESPONSES' | ||
|
||
variables | ||
id_variables = 'VARIABLES' | ||
continuous_design = 2 | ||
descriptors 'PARAM1' 'PARAM2' | ||
initial_point 0.5 1.0 | ||
lower_bounds 0.0 0.0 | ||
upper_bounds 1.0 2.0 | ||
|
||
interface, | ||
id_interface = 'INTERFACE' | ||
batch | ||
python | ||
analysis_drivers | ||
'evaluator' | ||
|
||
responses | ||
id_responses = 'RESPONSES' | ||
descriptors 'OBJ1' 'OBJ2' | ||
objective_functions = 2 | ||
no_gradients | ||
no_hessians |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
import pathlib as pl | ||
|
||
import dakota.environment as dakenv | ||
|
||
script_dir = pl.Path(__file__).parent | ||
|
||
|
||
def evaluator(inputs): | ||
# Get the continuous variables out of the input provided by dakota | ||
params = inputs["cv"] | ||
print(f"Evaluating {params}") | ||
|
||
# Put the objective in the dakota 'fns' field of the output | ||
outputs = {"fns": params} | ||
return outputs | ||
|
||
|
||
def batch_evaluator(batch_input): | ||
return map(evaluator, batch_input) | ||
|
||
|
||
def test_adasampling(tmp_path): | ||
print("Starting dakota") | ||
os.chdir(tmp_path) | ||
dakota_conf_path = script_dir / "adasampling.in" | ||
dakota_conf = dakota_conf_path.read_text() | ||
study = dakenv.study( | ||
callbacks={"evaluator": batch_evaluator}, input_string=dakota_conf | ||
) | ||
|
||
study.execute() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_adasampling() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Specify the output file for tabular data | ||
environment | ||
tabular_data | ||
tabular_data_file | ||
'dakota_tabular.dat' | ||
top_method_pointer = 'MULTIOBJ_OPTIMIZATION' | ||
|
||
# Define the optimization method | ||
method | ||
id_method = 'MULTIOBJ_OPTIMIZATION' | ||
moga # Multi-Objective Genetic Algorithm | ||
model_pointer = "TRUE_MODEL" | ||
seed 1234 # Set random seed for reproducibility | ||
max_function_evaluations 100 # Maximum number of function evaluations | ||
|
||
# Define the model | ||
model | ||
id_model = 'TRUE_MODEL' | ||
single | ||
interface_pointer = 'INTERFACE' | ||
variables_pointer = 'VARIABLES' | ||
responses_pointer = 'RESPONSES' | ||
|
||
# Define the variables | ||
variables | ||
id_variables = 'VARIABLES' | ||
continuous_design = 3 # Number of continuous design variables | ||
descriptors 'PARAM1' 'PARAM2' 'PARAM3' | ||
initial_point 2.0 3.0 4.0 | ||
lower_bounds 0.0 0.0 0.0 | ||
upper_bounds 10.0 10.0 10.0 | ||
|
||
# Define the interface | ||
interface | ||
id_interface = 'INTERFACE' | ||
python | ||
analysis_drivers | ||
'evaluator' # Python script to evaluate the objectives | ||
|
||
# Define the responses | ||
responses | ||
id_responses = 'RESPONSES' | ||
descriptors 'OBJ1' 'OBJ2' | ||
objective_functions = 2 # Number of objective functions | ||
no_gradients # Gradients will not be provided | ||
no_hessians # Hessians will not be provided |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import pathlib as pl | ||
|
||
import dakota.environment as dakenv | ||
|
||
script_dir = pl.Path(__file__).parent | ||
|
||
def evaluate(x, y, z): | ||
# Objective 1: Minimize the sum of squares | ||
obj1 = x**2 + y**2 + z**2 | ||
|
||
# Objective 2: Maximize the product | ||
obj2 = -(x * y * z) # Negated because we conventionally minimize | ||
|
||
return obj1, obj2 | ||
|
||
|
||
def evaluator(inputs): | ||
# Get the continuous variables out of the input provided by dakota | ||
params = inputs["cv"] | ||
#print(f"Evaluating {params}") | ||
|
||
# Put the objective in the dakota 'fns' field of the output | ||
outputs = {"fns": evaluate(*params)} | ||
return outputs | ||
|
||
|
||
def test_moga(tmp_path): | ||
print("Starting dakota") | ||
|
||
os.chdir(tmp_path) | ||
dakota_conf_path = script_dir / "moga.in" | ||
dakota_conf = dakota_conf_path.read_text() | ||
study = dakenv.study( | ||
callbacks={"evaluator": evaluator}, | ||
input_string=dakota_conf, | ||
) | ||
|
||
study.execute() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_moga() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
environment | ||
tabular_data | ||
tabular_data_file | ||
'dakota_tabular.dat' | ||
top_method_pointer = 'SAMPLING' | ||
|
||
method | ||
id_method = 'SAMPLING' | ||
sampling | ||
sample_type lhs | ||
samples 10 | ||
model_pointer = "TRUE_MODEL" | ||
seed 1234 | ||
|
||
model | ||
id_model = 'TRUE_MODEL' | ||
single | ||
interface_pointer = 'INTERFACE' | ||
variables_pointer = 'VARIABLES' | ||
responses_pointer = 'RESPONSES' | ||
|
||
variables | ||
id_variables = 'VARIABLES' | ||
continuous_design = 2 | ||
descriptors 'PARAM1' 'PARAM2' | ||
initial_point 0.5 1.0 | ||
lower_bounds 0.0 0.0 | ||
upper_bounds 1.0 2.0 | ||
|
||
interface, | ||
id_interface = 'INTERFACE' | ||
python | ||
analysis_drivers | ||
'evaluator' | ||
failure_capture | ||
recover | ||
NaN NaN | ||
|
||
responses | ||
id_responses = 'RESPONSES' | ||
descriptors 'OBJ1' 'OBJ2' | ||
objective_functions = 2 | ||
no_gradients | ||
no_hessians |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import pathlib as pl | ||
|
||
import dakota.environment as dakenv | ||
|
||
script_dir = pl.Path(__file__).parent | ||
|
||
|
||
def evaluator(inputs): | ||
# Get the continuous variables out of the input provided by dakota | ||
params = inputs["cv"] | ||
print(f"Evaluating {params}") | ||
|
||
# Put the objective in the dakota 'fns' field of the output | ||
outputs = {"fns": params, "failure": 1} | ||
|
||
#return Exception() | ||
return outputs | ||
|
||
|
||
def test_simple(tmp_path): | ||
os.chdir(tmp_path) | ||
|
||
print("Starting dakota") | ||
|
||
dakota_conf_path = script_dir / "simple.in" | ||
dakota_conf = dakota_conf_path.read_text() | ||
study = dakenv.study( | ||
callbacks={"evaluator": evaluator}, | ||
input_string=dakota_conf, | ||
) | ||
|
||
study.execute() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_simple() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
environment | ||
tabular_data | ||
tabular_data_file | ||
'dakota_tabular.dat' | ||
top_method_pointer = 'SAMPLING' | ||
|
||
method | ||
id_method = 'SAMPLING' | ||
sampling | ||
sample_type lhs | ||
samples 10 | ||
model_pointer = "TRUE_MODEL" | ||
seed 1234 | ||
|
||
model | ||
id_model = 'TRUE_MODEL' | ||
single | ||
interface_pointer = 'INTERFACE' | ||
variables_pointer = 'VARIABLES' | ||
responses_pointer = 'RESPONSES' | ||
|
||
variables | ||
id_variables = 'VARIABLES' | ||
continuous_design = 2 | ||
descriptors 'PARAM1' 'PARAM2' | ||
initial_point 0.5 1.0 | ||
lower_bounds 0.0 0.0 | ||
upper_bounds 1.0 2.0 | ||
|
||
interface, | ||
id_interface = 'INTERFACE' | ||
batch | ||
python | ||
analysis_drivers | ||
'evaluator' | ||
|
||
responses | ||
id_responses = 'RESPONSES' | ||
descriptors 'OBJ1' 'OBJ2' | ||
objective_functions = 2 | ||
no_gradients | ||
no_hessians |
Oops, something went wrong.