-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqSOBO_assignment_test.py
More file actions
102 lines (73 loc) · 2.77 KB
/
qSOBO_assignment_test.py
File metadata and controls
102 lines (73 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import os
import warnings
from utils import set_seeds, measure_erosion
import numpy as np
from ax.service.ax_client import AxClient, ObjectiveProperties
import matplotlib.pyplot as plt
import pytest
@pytest.fixture(scope="session")
def get_namespace():
script_fname = "qSOBO_assignment_ans.py"
script_content = open(script_fname).read()
namespace = {}
exec(script_content, namespace)
return namespace
def test_task_a(get_namespace):
running_ax_client = get_namespace["ax_client"]
user_op_params = running_ax_client.experiment.parameters
assert len(user_op_params) == 6, "Expected 6 parameters, got {}".format(
len(user_op_params)
)
assert all(
[
param in ["pg_rate", "sg_rate", "current", "cg_rate", "pf_rate", "distance"]
for param in user_op_params
]
), "Expected parameters named ['pg_rate', 'sg_rate', 'current', 'cg_rate', 'pf_rate', 'distance'], got {}".format(
user_op_params.keys()
)
assert (
len(running_ax_client.get_trials_data_frame()) == 30
), "Expected optimization budget of 30 trials, got {}".format(
len(running_ax_client.get_trials_data_frame())
)
def test_task_b(get_namespace):
# optimal_params
# min_mass_loss
# device_stress_index
user_optimal_params = get_namespace["optimal_params"]
user_min_mass_loss = get_namespace["min_mass_loss"]
user_device_stress_index = get_namespace["device_stress_index"]
# assert optimal current is above 610
assert (
user_optimal_params["current"] > 610.0
), "Expected optimal current to be > 610, got {}".format(
user_optimal_params["current"]
)
# asset min mass loss less than 0.3
assert user_min_mass_loss < 0.3, "Expected min_mass_loss < 0.3, got {}".format(
user_min_mass_loss
)
# assert device stress index is less than 700
assert (
user_device_stress_index < 700
), "Expected device_stress_index < 700, got {}".format(user_device_stress_index)
def test_task_c(get_namespace):
user_high_stress_count = get_namespace["high_stress_count"]
assert user_high_stress_count == 1, "Expected high_stress_count: 1, got {}".format(
user_high_stress_count
)
def test_task_d(get_namespace):
user_avg_lower = get_namespace["avg_lower"]
assert user_avg_lower < 1.7, "Expected avg_lower < 1.7, got {}".format(
user_avg_lower
)
def test_task_e(get_namespace):
user_most_diverse = get_namespace["most_diverse"]
user_least_diverse = get_namespace["least_diverse"]
assert user_most_diverse == 4, "Expected most_diverse: 6, got {}".format(
user_most_diverse
)
assert user_least_diverse == 9, "Expected least_diverse: 9, got {}".format(
user_least_diverse
)