From 2efbc446f23f1e038a52a1070637c7572f166908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Tue, 22 May 2018 14:37:27 +0200 Subject: [PATCH 1/2] log git commit status in evaluation logs --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 53b0444..b79314a 100644 --- a/main.py +++ b/main.py @@ -110,7 +110,8 @@ def log_eval_outcomes(outcomes, trained_eps = 0, log_path = os.path.join(model_p """ for outcome in outcomes: scores = outcome[1] - format_vars = { 'trained_eps': trained_eps, + format_vars = { 'commit': os.system('git describe --first-parent --always'), + 'trained_eps': trained_eps, 'method': outcome[0], 'count': len(scores), 'sum': sum(scores), @@ -118,7 +119,7 @@ def log_eval_outcomes(outcomes, trained_eps = 0, log_path = os.path.join(model_p 'time': int(time.time()) } with open(log_path, 'a+') as f: - f.write("{time};{method};{trained_eps};{count};{sum};{mean}".format(**format_vars) + "\n") + f.write("{commit};{time};{method};{trained_eps};{count};{sum};{mean}".format(**format_vars) + "\n") def log_bench_eval_outcomes(outcomes, log_path, index, time, trained_eps = 0): for outcome in outcomes: From 5ab144cffca96e3ca3fb6eebada9a1bdebf69ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Tue, 22 May 2018 14:44:13 +0200 Subject: [PATCH 2/2] add git commit status to all logs --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 32ded14..44e6c1c 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import argparse import sys import os import time +import subprocess # Parse command line arguments parser = argparse.ArgumentParser(description="Backgammon games") @@ -79,16 +80,18 @@ if not os.path.isdir(log_path): # Define helper functions def log_train_outcome(outcome, diff_in_values, trained_eps = 0, log_path = os.path.join(model_path(), 'logs', "train.log")): + commit = subprocess.run(['git', 'describe', '--first-parent', '--always'], stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip() format_vars = { 'trained_eps': trained_eps, 'count': len(outcome), 'sum': sum(outcome), 'mean': sum(outcome) / len(outcome), 'time': int(time.time()), - 'average_diff_in_vals': diff_in_values/len(outcome) + 'average_diff_in_vals': diff_in_values/len(outcome), + 'commit': commit } with open(log_path, 'a+') as f: - f.write("{time};{trained_eps};{count};{sum};{mean};{average_diff_in_vals}".format(**format_vars) + "\n") + f.write("{time};{trained_eps};{count};{sum};{mean};{average_diff_in_vals};{commit}".format(**format_vars) + "\n") def log_eval_outcomes(outcomes, trained_eps = 0, log_path = os.path.join(model_path(), 'logs', "eval.log")): @@ -99,9 +102,11 @@ def log_eval_outcomes(outcomes, trained_eps = 0, log_path = os.path.join(model_p :param log_path: :return: """ + commit = subprocess.run(['git', 'describe', '--first-parent', '--always'], stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip() + for outcome in outcomes: scores = outcome[1] - format_vars = { 'commit': os.system('git describe --first-parent --always'), + format_vars = { 'commit': commit, 'trained_eps': trained_eps, 'method': outcome[0], 'count': len(scores), @@ -110,9 +115,10 @@ def log_eval_outcomes(outcomes, trained_eps = 0, log_path = os.path.join(model_p 'time': int(time.time()) } with open(log_path, 'a+') as f: - f.write("{commit};{time};{method};{trained_eps};{count};{sum};{mean}".format(**format_vars) + "\n") + f.write("{time};{method};{trained_eps};{count};{sum};{mean};{commit}".format(**format_vars) + "\n") def log_bench_eval_outcomes(outcomes, log_path, index, time, trained_eps = 0): + commit = subprocess.run(['git', 'describe', '--first-parent', '--always'], stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip() for outcome in outcomes: scores = outcome[1] format_vars = { 'trained_eps': trained_eps, @@ -122,9 +128,10 @@ def log_bench_eval_outcomes(outcomes, log_path, index, time, trained_eps = 0): 'mean': sum(scores) / len(scores), 'time': time, 'index': index, + 'commit': commit } with open(log_path, 'a+') as f: - f.write("{method};{count};{index};{time};{sum};{mean}".format(**format_vars) + "\n") + f.write("{method};{count};{index};{time};{sum};{mean};{commit}".format(**format_vars) + "\n") def find_board_rep(): checkpoint_path = os.path.join(config['model_storage_path'], config['model'])