diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_advanced.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_advanced.yml/snapshot.json new file mode 100644 index 00000000000..fba847b520a --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_advanced.yml/snapshot.json @@ -0,0 +1,389 @@ +{ + "batches": [ + 0, + 1, + 2, + 3, + 4, + 5 + ], + "control_names": [ + "point_x-0", + "point_x-1", + "point_x-2" + ], + "accepted_batches": [ + 0, + 1, + 2, + 3, + 4, + 5 + ], + "objective_function_names": [ + "distance" + ], + "output_constraint_names": [ + "x-0_coord" + ], + "realizations": [ + 0, + 2 + ], + "simulations": [ + 0, + 1 + ], + "control_values": [ + { + "control": "point_x-0", + "batch": 0, + "value": 0.25 + }, + { + "control": "point_x-1", + "batch": 0, + "value": 0.25 + }, + { + "control": "point_x-2", + "batch": 0, + "value": 0.25 + }, + { + "control": "point_x-0", + "batch": 0, + "value": 0.25 + }, + { + "control": "point_x-1", + "batch": 0, + "value": 0.25 + }, + { + "control": "point_x-2", + "batch": 0, + "value": 0.25 + }, + { + "control": "point_x-0", + "batch": 1, + "value": 0.25904478 + }, + { + "control": "point_x-1", + "batch": 1, + "value": 0.13792475 + }, + { + "control": "point_x-2", + "batch": 1, + "value": 0.17336687 + }, + { + "control": "point_x-0", + "batch": 1, + "value": 0.25904478 + }, + { + "control": "point_x-1", + "batch": 1, + "value": 0.13792475 + }, + { + "control": "point_x-2", + "batch": 1, + "value": 0.17336687 + }, + { + "control": "point_x-0", + "batch": 2, + "value": 0.31863568 + }, + { + "control": "point_x-1", + "batch": 2, + "value": 0.00504358 + }, + { + "control": "point_x-2", + "batch": 2, + "value": 0.13385209 + }, + { + "control": "point_x-0", + "batch": 2, + "value": 0.31863568 + }, + { + "control": "point_x-1", + "batch": 2, + "value": 0.00504358 + }, + { + "control": "point_x-2", + "batch": 2, + "value": 0.13385209 + }, + { + "control": "point_x-0", + "batch": 3, + "value": 0.24117771 + }, + { + "control": "point_x-1", + "batch": 3, + "value": 0.03015417 + }, + { + "control": "point_x-2", + "batch": 3, + "value": 0.24583776 + }, + { + "control": "point_x-0", + "batch": 3, + "value": 0.24117771 + }, + { + "control": "point_x-1", + "batch": 3, + "value": 0.03015417 + }, + { + "control": "point_x-2", + "batch": 3, + "value": 0.24583776 + }, + { + "control": "point_x-0", + "batch": 4, + "value": 0.15091481 + }, + { + "control": "point_x-1", + "batch": 4, + "value": -0.00394611 + }, + { + "control": "point_x-2", + "batch": 4, + "value": 0.36960914 + }, + { + "control": "point_x-0", + "batch": 4, + "value": 0.15091481 + }, + { + "control": "point_x-1", + "batch": 4, + "value": -0.00394611 + }, + { + "control": "point_x-2", + "batch": 4, + "value": 0.36960914 + }, + { + "control": "point_x-0", + "batch": 5, + "value": 0.1145273 + }, + { + "control": "point_x-1", + "batch": 5, + "value": 0.00635029 + }, + { + "control": "point_x-2", + "batch": 5, + "value": 0.38836369 + }, + { + "control": "point_x-0", + "batch": 5, + "value": 0.1145273 + }, + { + "control": "point_x-1", + "batch": 5, + "value": 0.00635029 + }, + { + "control": "point_x-2", + "batch": 5, + "value": 0.38836369 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": -1.6875, + "accepted": 1 + }, + { + "batch": 1, + "objective": -1.69281773, + "accepted": 1 + }, + { + "batch": 2, + "objective": -1.73561919, + "accepted": 1 + }, + { + "batch": 3, + "objective": -1.6236748, + "accepted": 1 + }, + { + "batch": 4, + "objective": -1.539793, + "accepted": 1 + }, + { + "batch": 5, + "objective": -1.52561897, + "accepted": 1 + } + ], + "gradient_values": [ + { + "batch": 0, + "function": "distance", + "control": "point_x-0", + "value": -0.49076627 + }, + { + "batch": 0, + "function": "distance", + "control": "point_x-1", + "value": -0.50191014 + }, + { + "batch": 0, + "function": "distance", + "control": "point_x-2", + "value": 0.50424549 + }, + { + "batch": 1, + "function": "distance", + "control": "point_x-0", + "value": -0.52209326 + }, + { + "batch": 1, + "function": "distance", + "control": "point_x-1", + "value": -0.28579331 + }, + { + "batch": 1, + "function": "distance", + "control": "point_x-2", + "value": 0.64869691 + }, + { + "batch": 2, + "function": "distance", + "control": "point_x-0", + "value": -0.64281291 + }, + { + "batch": 2, + "function": "distance", + "control": "point_x-1", + "value": -0.00521952 + }, + { + "batch": 2, + "function": "distance", + "control": "point_x-2", + "value": 0.73152662 + }, + { + "batch": 3, + "function": "distance", + "control": "point_x-0", + "value": -0.47276201 + }, + { + "batch": 3, + "function": "distance", + "control": "point_x-1", + "value": -0.0785477 + }, + { + "batch": 3, + "function": "distance", + "control": "point_x-2", + "value": 0.51539765 + }, + { + "batch": 4, + "function": "distance", + "control": "point_x-0", + "value": -0.30369426 + }, + { + "batch": 4, + "function": "distance", + "control": "point_x-1", + "value": 0.02314375 + }, + { + "batch": 4, + "function": "distance", + "control": "point_x-2", + "value": 0.25834193 + }, + { + "batch": 5, + "function": "distance", + "control": "point_x-0", + "value": -0.21656122 + }, + { + "batch": 5, + "function": "distance", + "control": "point_x-1", + "value": -0.00578828 + }, + { + "batch": 5, + "function": "distance", + "control": "point_x-2", + "value": 0.2172204 + } + ], + "input_constraint('point_x-0')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_x-1')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_x-2')": { + "min": -1.0, + "max": 1.0 + }, + "output_constraint('x-0_coord')": { + "type": "ge", + "right_hand_side": 0.1 + }, + "optimal_result_json": { + "batch": 5, + "controls": { + "point_x-0": 0.1145273, + "point_x-1": 0.00635029, + "point_x-2": 0.38836369 + }, + "total_objective": -1.52561897, + "expected_objectives": { + "distance": -1.52561897 + } + } +} diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_auto_scaled_controls.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_auto_scaled_controls.yml/snapshot.json new file mode 100644 index 00000000000..34def1be5da --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_auto_scaled_controls.yml/snapshot.json @@ -0,0 +1,200 @@ +{ + "batches": [ + 0, + 1, + 3, + 5, + 7, + 9 + ], + "control_names": [ + "point_x", + "point_y", + "point_z" + ], + "accepted_batches": [ + 0, + 1, + 3, + 5, + 7 + ], + "objective_function_names": [ + "distance" + ], + "output_constraint_names": [], + "realizations": [ + 0 + ], + "simulations": [ + 0 + ], + "control_values": [ + { + "control": "point_x", + "batch": 0, + "value": 0.2 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.2 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.2 + }, + { + "control": "point_x", + "batch": 1, + "value": -0.01613438 + }, + { + "control": "point_y", + "batch": 1, + "value": -0.01682551 + }, + { + "control": "point_z", + "batch": 1, + "value": 0.5571275 + }, + { + "control": "point_x", + "batch": 3, + "value": -0.02716208 + }, + { + "control": "point_y", + "batch": 3, + "value": -0.02686554 + }, + { + "control": "point_z", + "batch": 3, + "value": 0.32152608 + }, + { + "control": "point_x", + "batch": 5, + "value": 0.14271157 + }, + { + "control": "point_y", + "batch": 5, + "value": 0.14281097 + }, + { + "control": "point_z", + "batch": 5, + "value": 0.40830957 + }, + { + "control": "point_x", + "batch": 7, + "value": 0.2225664 + }, + { + "control": "point_y", + "batch": 7, + "value": 0.21233962 + }, + { + "control": "point_z", + "batch": 7, + "value": 0.49289096 + }, + { + "control": "point_x", + "batch": 9, + "value": 0.21940694 + }, + { + "control": "point_y", + "batch": 9, + "value": 0.26757899 + }, + { + "control": "point_z", + "batch": 9, + "value": 0.49314616 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": -0.27000001, + "accepted": 1 + }, + { + "batch": 1, + "objective": -0.53676701, + "accepted": 1 + }, + { + "batch": 3, + "objective": -0.58734, + "accepted": 1 + }, + { + "batch": 5, + "objective": -0.26364601, + "accepted": 1 + }, + { + "batch": 7, + "objective": -0.159768, + "accepted": 1 + }, + { + "batch": 9, + "objective": -0.132799, + "accepted": 0 + } + ], + "gradient_values": [ + { + "batch": 0, + "function": "distance", + "control": "point_x", + "value": 2.99973311 + }, + { + "batch": 0, + "function": "distance", + "control": "point_y", + "value": 2.99553111 + }, + { + "batch": 0, + "function": "distance", + "control": "point_z", + "value": 3.00247454 + } + ], + "input_constraint('point_x')": { + "min": 0.3, + "max": 0.7 + }, + "input_constraint('point_y')": { + "min": 0.3, + "max": 0.7 + }, + "input_constraint('point_z')": { + "min": 0.3, + "max": 0.7 + }, + "optimal_result_json": { + "batch": 7, + "controls": { + "point_x": 0.2225664, + "point_y": 0.21233962, + "point_z": 0.49289096 + }, + "total_objective": -0.159768, + "expected_objectives": { + "distance": -0.159768 + } + } +} diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_cvar.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_cvar.yml/snapshot.json new file mode 100644 index 00000000000..c7b6a104bdf --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_cvar.yml/snapshot.json @@ -0,0 +1,163 @@ +{ + "batches": [ + 0, + 2, + 3 + ], + "control_names": [ + "point_x", + "point_y", + "point_z" + ], + "accepted_batches": [ + 0, + 2, + 3 + ], + "objective_function_names": [ + "distance" + ], + "output_constraint_names": [], + "realizations": [ + 0, + 1 + ], + "simulations": [ + 0, + 1 + ], + "control_values": [ + { + "control": "point_x", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_x", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_x", + "batch": 2, + "value": 0.99589284 + }, + { + "control": "point_y", + "batch": 2, + "value": 0.98866227 + }, + { + "control": "point_z", + "batch": 2, + "value": 1.00465235 + }, + { + "control": "point_x", + "batch": 2, + "value": 0.99589284 + }, + { + "control": "point_y", + "batch": 2, + "value": 0.98866227 + }, + { + "control": "point_z", + "batch": 2, + "value": 1.00465235 + }, + { + "control": "point_x", + "batch": 3, + "value": 0.49972902 + }, + { + "control": "point_y", + "batch": 3, + "value": 0.49610079 + }, + { + "control": "point_z", + "batch": 3, + "value": 0.50412446 + }, + { + "control": "point_x", + "batch": 3, + "value": 0.49972902 + }, + { + "control": "point_y", + "batch": 3, + "value": 0.49610079 + }, + { + "control": "point_z", + "batch": 3, + "value": 0.50412446 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": -0.75, + "accepted": 1 + }, + { + "batch": 2, + "objective": -0.739375, + "accepted": 1 + }, + { + "batch": 3, + "objective": -0.00003229, + "accepted": 1 + } + ], + "gradient_values": [], + "input_constraint('point_x')": { + "min": -2.0, + "max": 2.0 + }, + "input_constraint('point_y')": { + "min": -2.0, + "max": 2.0 + }, + "input_constraint('point_z')": { + "min": -2.0, + "max": 2.0 + }, + "optimal_result_json": { + "batch": 3, + "controls": { + "point_x": 0.49972902, + "point_y": 0.49610079, + "point_z": 0.50412446 + }, + "total_objective": -0.00003229, + "expected_objectives": { + "distance": 0.0 + } + } +} diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_discrete.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_discrete.yml/snapshot.json new file mode 100644 index 00000000000..4f750cdcc28 --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_discrete.yml/snapshot.json @@ -0,0 +1,111 @@ +{ + "batches": [ + 0, + 1, + 2, + 3 + ], + "control_names": [ + "point_x", + "point_y" + ], + "accepted_batches": [ + 0, + 1, + 3 + ], + "objective_function_names": [ + "func" + ], + "output_constraint_names": [], + "realizations": [ + 0 + ], + "simulations": [ + 0 + ], + "control_values": [ + { + "control": "point_x", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_x", + "batch": 1, + "value": 6.0 + }, + { + "control": "point_y", + "batch": 1, + "value": 4.0 + }, + { + "control": "point_x", + "batch": 2, + "value": 3.0 + }, + { + "control": "point_y", + "batch": 2, + "value": 1.0 + }, + { + "control": "point_x", + "batch": 3, + "value": 3.0 + }, + { + "control": "point_y", + "batch": 3, + "value": 7.0 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": 0.0, + "accepted": 1 + }, + { + "batch": 1, + "objective": 4.0, + "accepted": 1 + }, + { + "batch": 2, + "objective": 1.0, + "accepted": 0 + }, + { + "batch": 3, + "objective": 7.0, + "accepted": 1 + } + ], + "gradient_values": [], + "input_constraint('point_x')": { + "min": 0.0, + "max": 10.0 + }, + "input_constraint('point_y')": { + "min": 0.0, + "max": 10.0 + }, + "optimal_result_json": { + "batch": 3, + "controls": { + "point_x": 3.0, + "point_y": 7.0 + }, + "total_objective": 7.0, + "expected_objectives": { + "func": 7.0 + } + } +} diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_minimal.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_minimal.yml/snapshot.json new file mode 100644 index 00000000000..c203e798f37 --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_minimal.yml/snapshot.json @@ -0,0 +1,134 @@ +{ + "batches": [ + 0, + 1, + 2 + ], + "control_names": [ + "point_x", + "point_y", + "point_z" + ], + "accepted_batches": [ + 0, + 2 + ], + "objective_function_names": [ + "distance" + ], + "output_constraint_names": [], + "realizations": [ + 0 + ], + "simulations": [ + 0 + ], + "control_values": [ + { + "control": "point_x", + "batch": 0, + "value": 0.1 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.1 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.1 + }, + { + "control": "point_x", + "batch": 1, + "value": 0.90038639 + }, + { + "control": "point_y", + "batch": 1, + "value": 0.90054756 + }, + { + "control": "point_z", + "batch": 1, + "value": 0.89933796 + }, + { + "control": "point_x", + "batch": 2, + "value": 0.50014777 + }, + { + "control": "point_y", + "batch": 2, + "value": 0.50022835 + }, + { + "control": "point_z", + "batch": 2, + "value": 0.49962361 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": -0.47999999, + "accepted": 1 + }, + { + "batch": 1, + "objective": -0.48021799, + "accepted": 0 + }, + { + "batch": 2, + "objective": -2.2e-7, + "accepted": 1 + } + ], + "gradient_values": [ + { + "batch": 0, + "function": "distance", + "control": "point_x", + "value": 0.80038641 + }, + { + "batch": 0, + "function": "distance", + "control": "point_y", + "value": 0.80054758 + }, + { + "batch": 0, + "function": "distance", + "control": "point_z", + "value": 0.79933798 + } + ], + "input_constraint('point_x')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_y')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_z')": { + "min": -1.0, + "max": 1.0 + }, + "optimal_result_json": { + "batch": 2, + "controls": { + "point_x": 0.50014777, + "point_y": 0.50022835, + "point_z": 0.49962361 + }, + "total_objective": -2.2e-7, + "expected_objectives": { + "distance": -2.2e-7 + } + } +} diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_multiobj.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_multiobj.yml/snapshot.json new file mode 100644 index 00000000000..55f31a1ec64 --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_multiobj.yml/snapshot.json @@ -0,0 +1,160 @@ +{ + "batches": [ + 0, + 1, + 2 + ], + "control_names": [ + "point_x", + "point_y", + "point_z" + ], + "accepted_batches": [ + 0, + 2 + ], + "objective_function_names": [ + "distance_p", + "distance_q" + ], + "output_constraint_names": [], + "realizations": [ + 0 + ], + "simulations": [ + 0 + ], + "control_values": [ + { + "control": "point_x", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_x", + "batch": 1, + "value": -0.00420218 + }, + { + "control": "point_y", + "batch": 1, + "value": -0.0112982 + }, + { + "control": "point_z", + "batch": 1, + "value": 1.0 + }, + { + "control": "point_x", + "batch": 2, + "value": -0.00210079 + }, + { + "control": "point_y", + "batch": 2, + "value": -0.00564829 + }, + { + "control": "point_z", + "batch": 2, + "value": 0.49992811 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": -2.33333333, + "accepted": 1, + "distance_p": -0.75, + "distance_q": -1.58333333 + }, + { + "batch": 1, + "objective": -2.33352598, + "accepted": 0, + "distance_p": -0.76564598, + "distance_q": -1.56787999 + }, + { + "batch": 2, + "objective": -2.00004834, + "accepted": 1, + "distance_p": -0.50778502, + "distance_q": -1.49226332 + } + ], + "gradient_values": [ + { + "batch": 0, + "function": "distance_p", + "control": "point_x", + "value": 0.99589284 + }, + { + "batch": 0, + "function": "distance_p", + "control": "point_y", + "value": 0.98866227 + }, + { + "batch": 0, + "function": "distance_p", + "control": "point_z", + "value": 1.00465235 + }, + { + "batch": 0, + "function": "distance_q", + "control": "point_x", + "value": -3.00456477 + }, + { + "batch": 0, + "function": "distance_q", + "control": "point_y", + "value": -3.011388 + }, + { + "batch": 0, + "function": "distance_q", + "control": "point_z", + "value": 1.0044895 + } + ], + "input_constraint('point_x')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_y')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_z')": { + "min": -1.0, + "max": 1.0 + }, + "optimal_result_json": { + "batch": 2, + "controls": { + "point_x": -0.00210079, + "point_y": -0.00564829, + "point_z": 0.49992811 + }, + "total_objective": -2.00004834, + "expected_objectives": { + "distance_p": -0.50778502, + "distance_q": -4.47678995 + } + } +} diff --git a/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_stddev.yml/snapshot.json b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_stddev.yml/snapshot.json new file mode 100644 index 00000000000..97408c90abe --- /dev/null +++ b/tests/everest/snapshots/test_api_snapshots/test_api_snapshots/config_stddev.yml/snapshot.json @@ -0,0 +1,171 @@ +{ + "batches": [ + 0, + 2, + 4 + ], + "control_names": [ + "point_x", + "point_y", + "point_z" + ], + "accepted_batches": [ + 0, + 2, + 4 + ], + "objective_function_names": [ + "distance", + "stddev" + ], + "output_constraint_names": [], + "realizations": [ + 0, + 1 + ], + "simulations": [ + 0, + 1 + ], + "control_values": [ + { + "control": "point_x", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_x", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_y", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_z", + "batch": 0, + "value": 0.0 + }, + { + "control": "point_x", + "batch": 2, + "value": 0.61224415 + }, + { + "control": "point_y", + "batch": 2, + "value": 0.62855608 + }, + { + "control": "point_z", + "batch": 2, + "value": 0.72543321 + }, + { + "control": "point_x", + "batch": 2, + "value": 0.61224415 + }, + { + "control": "point_y", + "batch": 2, + "value": 0.62855608 + }, + { + "control": "point_z", + "batch": 2, + "value": 0.72543321 + }, + { + "control": "point_x", + "batch": 4, + "value": 0.50351462 + }, + { + "control": "point_y", + "batch": 4, + "value": 0.50220467 + }, + { + "control": "point_z", + "batch": 4, + "value": 0.48265145 + }, + { + "control": "point_x", + "batch": 4, + "value": 0.50351462 + }, + { + "control": "point_y", + "batch": 4, + "value": 0.50220467 + }, + { + "control": "point_z", + "batch": 4, + "value": 0.48265145 + } + ], + "single_objective_values": [ + { + "batch": 0, + "objective": -0.53033009, + "accepted": 1, + "distance": 0.0, + "stddev": 0.0 + }, + { + "batch": 2, + "objective": -0.05653, + "accepted": 1, + "distance": 0.0, + "stddev": 0.0 + }, + { + "batch": 4, + "objective": -0.00022499, + "accepted": 1, + "distance": 0.0, + "stddev": 0.0 + } + ], + "gradient_values": [], + "input_constraint('point_x')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_y')": { + "min": -1.0, + "max": 1.0 + }, + "input_constraint('point_z')": { + "min": -1.0, + "max": 1.0 + }, + "optimal_result_json": { + "batch": 4, + "controls": { + "point_x": 0.50351462, + "point_y": 0.50220467, + "point_z": 0.48265145 + }, + "total_objective": -0.00022499, + "expected_objectives": { + "distance": 0.0, + "stddev": 0.0 + } + } +} diff --git a/tests/everest/test_api_snapshots.py b/tests/everest/test_api_snapshots.py new file mode 100644 index 00000000000..efb23a2d95d --- /dev/null +++ b/tests/everest/test_api_snapshots.py @@ -0,0 +1,91 @@ +from typing import Any, Dict + +import orjson +import pytest + +from ert.run_models.everest_run_model import EverestRunModel +from everest.api import EverestDataAPI +from everest.config import EverestConfig + + +# Utility to round all floats in an arbitrary json object +# (without tuples) +def _round_floats(obj, dec): + if isinstance(obj, float): + return round(obj, dec) + if isinstance(obj, dict): + return {k: _round_floats(v, dec) for k, v in obj.items()} + if isinstance(obj, list): + return [_round_floats(item, dec) for item in obj] + # Assume no tuples + return obj + + +def make_api_snapshot(api) -> Dict[str, Any]: + api_json = { + "batches": api.batches, + "control_names": api.control_names, + "accepted_batches": api.accepted_batches, + "objective_function_names": api.objective_function_names, + "output_constraint_names": api.output_constraint_names, + "realizations": api.realizations, + "simulations": api.simulations, + "control_values": api.control_values, + "single_objective_values": api.single_objective_values, + "gradient_values": api.gradient_values, + **{ + f"input_constraint('{control}')": api.input_constraint(control) + for control in api.control_names + }, + **{ + f"output_constraint('{constraint}')": api.output_constraint(constraint) + for constraint in api.output_constraint_names + }, + } + + return api_json + + +@pytest.mark.parametrize( + "config_file", + [ + "config_advanced.yml", + "config_minimal.yml", + "config_multiobj.yml", + "config_auto_scaled_controls.yml", + "config_cvar.yml", + "config_discrete.yml", + "config_stddev.yml", + ], +) +def test_api_snapshots( + config_file, + copy_math_func_test_data_to_tmp, + evaluator_server_config_generator, + snapshot, +): + config = EverestConfig.load_file(config_file) + run_model = EverestRunModel.create(config) + evaluator_server_config = evaluator_server_config_generator(run_model) + run_model.run_experiment(evaluator_server_config) + + optimal_result = run_model.result + optimal_result_json = { + "batch": optimal_result.batch, + "controls": optimal_result.controls, + "total_objective": optimal_result.total_objective, + "expected_objectives": optimal_result.expected_objectives, + } + + api = EverestDataAPI(config) + json_snapshot = make_api_snapshot(api) + json_snapshot["optimal_result_json"] = optimal_result_json + rounded_json_snapshot = _round_floats(json_snapshot, 8) + + snapshot_str = ( + orjson.dumps(rounded_json_snapshot, option=orjson.OPT_INDENT_2) + .decode("utf-8") + .strip() + + "\n" + ) + snapshot.assert_match(snapshot_str, "snapshot.json")