Exemplo n.º 1
0
def run():
    task = Othello(4)
    az = AlphaZero({
        "numEps": 100,
        "numMCTSSims": 3,
        "maxDepth": 300,
        "arenaCompare": 10,
        "startFromEp": 0,
        "load_checkpoint": True,
        "checkpoint": "checkpoint_28.pth.tar",
        "checkpoint_dir": "./az_checkpoints",
        "prevHistory": "checkpoint_10.pth.tar.examples",
    })

    ql = QLearning({
        "checkpoint_dir": "./ql_checkpoints",
        "lr": 0.2,
        "discount": 0.9
    })

    az.init_to_task(task)
    ql.init_to_task(task)
    ql.load_weights("checkpoint_1.pkl")

    for x in range(3):
        run_test.main(task, az, ql)
        run_test.main(task, ql, az)
Exemplo n.º 2
0
#! /usr/bin/env python3
# -*- coding: utf-8 -*-


"""
侏儒排序算法的python实现
"""


from run_test import main


def gnomesort(seq):
    i = 0
    while i < len(seq):
        if i == 0 or seq[i-1] <= seq[i]:
            i += 1
        else:
            seq[i-1], seq[i] = seq[i], seq[i-1]
            i -= 1
    return seq


if __name__ == '__main__':
    dtime = main(gnomesort, seq_len=10000)
    print(f"耗时:{dtime}")
Exemplo n.º 3
0
            line = line.strip()
            if not line or line.startswith('#'):
                continue
            test_and_comp_root = line.split(",")
            if len(test_and_comp_root) != 2:
                print("Invalid test entry: {}".format(test_and_comp_root))
                continue

            yield (test_and_comp_root[0].strip(), test_and_comp_root[1].strip())


total_tests = 0
test_passed = 0
for test_info in next_test():
    total_tests += 1
    pipeline_path = os.path.join(pipelines_root, test_info[0])
    comp_root_path = os.path.join(os.path.expanduser(test_info[1]))
    test_args = ["--test", pipeline_path, "--comps-root", comp_root_path]
    if args.local_cluster:
        test_args.append("--local-cluster")
    try:
        if args.verbose:
            print("Args (run_test.py):", colored("{}".format(" ".join(test_args)), "blue", "on_white", attrs=['bold']))
        run_test.main(test_args)
        test_passed += 1
    except:
        traceback.print_exc()

print(30 * "#", "\n")
cprint("{}/{} tests passed successfully!\n".format(test_passed, total_tests), "green" if test_passed == total_tests else "yellow", attrs=['bold'])
Exemplo n.º 4
0
class FakeSSH(object):
    def exec_command(self, cmd, **kwargs):
        return get_fake_out(cmd)

    def close(self):
        pass

    def open_sftp(self):
        return FakeSFTP()


class FakePopen(object):
    def __init__(self, cmd,
                 shell=True,
                 stdout=None,
                 stderr=None,
                 stdin=None):
        self.stdin, self.stdout, self.stderr = get_fake_out(cmd)

    def wait(self):
        return 0


if __name__ == '__main__':
    run_test.subprocess.Popen = FakePopen
    run_test.start_test_vms = fake_start_vms()
    run_test.ssh_runner.ssh_connect = fake_ssh_connect
    opts = run_test.parse_args(sys.argv[1:])
    tool = opts.tool_type
    exit(run_test.main(sys.argv[1:]))
Exemplo n.º 5
0
"""


from run_test import main


# 递归版本
def ins_sort_rec(seq, i):
    if i == 0:
        return
    ins_sort_rec(seq, i-1)
    j = i
    while j > 0 and seq[j-1] > seq[j]:
        seq[j-1], seq[j] = seq[j], seq[j-1]
        j -= 1
    return seq


# 迭代版本
def ins_sort(seq, i):
    for i in range(1, len(seq)):
        j = i
        while j > 0 and seq(j-1) > seq(j):
            seq[j-1], seq[j] = seq[j], seq[j-1]
            j -= 1
    return seq


if __name__ == '__main__':
    main(ins_sort_rec)
Exemplo n.º 6
0
import sys
import run_test as rt

rt.options.make = "C:/Qt/Qt5.6.0/Tools/mingw492_32/bin/mingw32-make.exe"
rt.options.qmake = "C:/Qt/Qt5.6.0/5.6/mingw49_32/bin/qmake.exe"

tests = [
    "../src/xx_test_0000/xx_test_0000.pro",
    "../src/xx_test_0001/xx_test_0001.pro",
]
failed = []
passed = []
for test in tests:
    rt.options.project = test
    if rt.main():
        failed.append(test)
    else:
        passed.append(test)

sys.stdout.write("PASSED:\n")
sys.stdout.write("\n".join(passed)+"\n")

if len(failed):
    sys.stderr.write("FAILED:\n")
    sys.stderr.write("\n".join(failed)+"\n")
    sys.exit(1)

sys.stdout.write("\nALL OK\n")
sys.exit(0)
Exemplo n.º 7
0
def run():
    task = Uno()
    ai1 = InteractivePlayer().init_to_task(task)
    ai2 = Random().init_to_task(task)

    main(task, ai1, ai2)
Exemplo n.º 8
0

from run_test import main


# 迭代实现
def ch_que(query):
    for i in range(len(query)-1):
        for j in range(i+1, len(query)):
            if query[i] > query[j]:
                query[i], query[j] = query[j], query[i]
    return query


# 递归实现
def ch_que_rec(seq, i):
    if i == 0:
        return
    j_max = i
    for j in range(i):
        if seq[j] > seq[j_max]:
            j_max = j
    seq[i], seq[j_max] = seq[j_max], seq[i]
    ch_que_rec(seq, i-1)
    return seq


if __name__ == '__main__':
    dtime = main(ch_que_rec)
    print(f"耗时: {dtime}s")
    
Exemplo n.º 9
0
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
#
#

import play_poker
import run_test

running = False
while not running:
    mode = int(raw_input("Play game(1), debug(2) or do a test run(3)?"))

    if mode == 1:
        running = True
        play_poker.main()
    elif mode == 2:
        running = True
        debug.main()
    elif mode == 3:
        running = True
        run_test.main()
    else:
        print "Please answer 1, 2 or 3"
Exemplo n.º 10
0
# -*- coding: utf-8 -*-


from run_test import main


def mergesort(seq):
    mid = len(seq)//2
    left, right = seq[:mid], seq[mid:]
    # print(f"left: {left}")
    # print(f"right: {right}")
    if len(left) > 1:
        left = mergesort(left)
        # print(f"after letf: {left}")
    if len(right) > 1:
        right = mergesort(right)
    
    res = []
    while left and right:
        if left[-1] >= right[-1]:
            res.append(left.pop())
        else:
            res.append(right.pop())

    res.reverse()
    return (left or right) + res


if __name__ == '__main__':
    dtime = main(mergesort, seq_len=10)
    print(f"耗时:{dtime}")
Exemplo n.º 11
0
def test_player_after_switch(arg_learning_mode, arg_player1_num_of_trains, arg_player2_num_of_trains):
    opponents_number = 0
    learning_mode = int(arg_learning_mode)
    player1_num_of_trains = int(arg_player1_num_of_trains)
    player2_num_of_trains = int(arg_player2_num_of_trains)
    test_player_folder_path = ''
    test_player_log_file = ''
    opponent = ''
    opponent_num_of_trains = 0

    if (learning_mode == 1):
        opponents_number = 2
        opponent = 'right'
        opponent_num_of_trains = player2_num_of_trains
        test_player_folder_path = "./trials_sequentially/" + "left_player" + \
                                  "_learning" + str(player1_num_of_trains)
        print ('DEBUG: test_player_folder_path: ', test_player_folder_path, '\n')

        test_player_log_file = "logs/" + "left_player" + \
                               "_learning" + str(player1_num_of_trains)

    elif (learning_mode == 2):
        opponents_number = 1
        opponent = 'left'
        opponent_num_of_trains = player1_num_of_trains
        test_player_folder_path = "./trials_sequentially/" + "right_player" + \
                                  "_learning" + str(player2_num_of_trains)
        test_player_log_file = "logs/" + "right_player" + \
                               "_learning" + str(player2_num_of_trains)

    # opponent_path_to_most_updated_weights_folder = "./trials_sequentially/" + opponent + "_player" + \
    #                                                "_learning" + str(opponent_num_of_trains)
    # opponent_path_to_most_updated_weights_folder = "./trials_sequentially/" + "player" + str(opponents_number) +\
    #                                               "learning" + str(opponent_num_of_trains)
    # list_of_files = glob.glob(opponent_path_to_most_updated_weights_folder + '/*/*')
    # opponent_most_updated_weights_file = max(list_of_files, key=os.path.getctime)

    opponent_most_updated_weights_file = 'model' + str(opponents_number) + '.h5'

    num_of_test = 0
    game_times = []
    game_numbers = []
    times = []
    scores = []
    game_scores = []
    left_player_q_max_list = []
    left_player_q_max_list = []

    for subdir, dirs, files in os.walk(test_player_folder_path):
        dirs.sort(key=lambda f: int(filter(str.isdigit, f)))
        for d in dirs:
            num_of_test += 1
            if learning_mode == 1:
                times, scores, left_player_q_max_list, right_player_q_max_list = \
                    run_test.main(1, test_player_folder_path + "/" + str(d) + "/model1.h5",
                                  opponent_most_updated_weights_file,
                                  num_of_test, test_player_log_file)
                game_times = game_times + times
                game_scores = game_scores + scores
            elif learning_mode == 2:
                times, scores, left_player_q_max_list, right_player_q_max_list = \
                    run_test.main(2, opponent_most_updated_weights_file,
                                  test_player_folder_path + "/" + str(d) + "/model2.h5",
                                  num_of_test, test_player_log_file)
                game_times = game_times + times
                game_scores = game_scores + scores

    game_numbers.extend(range(1, len(game_times) + 1))
    plot_qmax(test_player_log_file, test_player_log_file + '/qmax')
    plot_scores(game_numbers, game_scores, test_player_log_file)
    plot_times(game_numbers, game_times, test_player_log_file)
    print_average_game_time(test_player_log_file)
Exemplo n.º 12
0
import sys
import run_test as rt

rt.options.make = "C:/Qt/Qt5.6.0/Tools/mingw492_32/bin/mingw32-make.exe"
rt.options.qmake = "C:/Qt/Qt5.6.0/5.6/mingw49_32/bin/qmake.exe"

tests = [
    "../src/xx_test_0000/xx_test_0000.pro",
    "../src/xx_test_0001/xx_test_0001.pro",
]
failed = []
passed = []
for test in tests:
    rt.options.project = test
    if rt.main():
        failed.append(test)
    else:
        passed.append(test)

sys.stdout.write("PASSED:\n")
sys.stdout.write("\n".join(passed)+"\n")

if len(failed):
    sys.stderr.write("FAILED:\n")
    sys.stderr.write("\n".join(failed)+"\n")
    sys.exit(1)

sys.stdout.write("\nALL OK\n")
sys.exit(0)