medianstop_assessor_test.py 1.64 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
Deshui Yu's avatar
Deshui Yu committed
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

import argparse
import logging
import random

from .medianstop_assessor import MedianstopAssessor
from nni.assessor import AssessResult

logger = logging.getLogger('nni.contrib.medianstop_assessor')
logger.debug('START')


def test():
    '''
    tests.
    '''
    parser = argparse.ArgumentParser(description='parse command line parameters.')
    parser.add_argument('--start_from', type=int, default=10, dest='start_step',
                        help='Assessing each trial from the step start_step.')
    parser.add_argument('--optimize_mode', type=str, default='maximize',
                        help='Select optimize mode for Tuner: minimize or maximize.')
    FLAGS, _ = parser.parse_known_args()

    lcs = [[1,1,1,1,1,1,1,1,1,1],
           [2,2,2,2,2,2,2,2,2,2],
           [3,3,3,3,3,3,3,3,3,3],
           [4,4,4,4,4,4,4,4,4,4]]
    #lcs = [[1,1,1,1,1,1,1,1,1,1],
    #       [1,1,1,1,1,1,1,1,1,1],
    #       [1,1,1,1,1,1,1,1,1,1]]

34
35
    assessor = MedianstopAssessor(FLAGS.optimize_mode, FLAGS.start_step)
    for i in range(len(lcs)):
Deshui Yu's avatar
Deshui Yu committed
36
37
        #lc = []
        to_complete = True
38
        for k in range(len(lcs[0])):
Deshui Yu's avatar
Deshui Yu committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
            #d = random.randint(i*100+0, i*100+100)
            #lc.append(d)
            ret = assessor.assess_trial(i, lcs[i][:k+1])
            print('result: %d', ret)
            if ret == AssessResult.Bad:
                assessor.trial_end(i, False)
                to_complete = False
                break
        if to_complete:
            assessor.trial_end(i, True)

try:
    test()
except Exception as exception:
    logger.exception(exception)
liuzhe-lz's avatar
liuzhe-lz committed
54
    raise