Passed
Pull Request — master (#110)
by
unknown
01:23
created

tests.test_api.test_max_time.test_max_time_0()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
import time
2
import numpy as np
3
from hyperactive.optimizers import HillClimbingOptimizer
4
from hyperactive.experiment import BaseExperiment
5
from hyperactive.search_config import SearchConfig
6
7
8
class Experiment(BaseExperiment):
9
    def objective_function(self, para):
10
        score = -para["x1"] * para["x1"]
11
        return score
12
13
14
experiment = Experiment()
15
16
search_config = SearchConfig(
17
    x1=list(np.arange(0, 100000, 1)),
18
)
19
20
21
def test_max_time_0():
22
    c_time1 = time.perf_counter()
23
    hyper = HillClimbingOptimizer()
24
    hyper.add_search(experiment, search_config, n_iter=1000000)
25
    hyper.run(max_time=0.1)
26
    diff_time1 = time.perf_counter() - c_time1
27
28
    assert diff_time1 < 1
29
30
31
def test_max_time_1():
32
    c_time1 = time.perf_counter()
33
    hyper = HillClimbingOptimizer()
34
    hyper.add_search(experiment, search_config, n_iter=1000000)
35
    hyper.run(max_time=1)
36
    diff_time1 = time.perf_counter() - c_time1
37
38
    assert 0.3 < diff_time1 < 2
39