Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tools for comparing integration test runs
- Loading branch information
Michael Marte
committed
Jun 8, 2018
1 parent
d080016
commit 5cc0455
Showing
22 changed files
with
376 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#! /usr/bin/python3 | ||
|
||
# This script compares the performance of Yuck on two given test runs. | ||
# | ||
# The result database is expected to reside in the working directory under the name results.db. | ||
|
||
import argparse | ||
import json | ||
import numpy | ||
import sqlite3 | ||
import statistics | ||
import sys | ||
|
||
def computeSpeedups(cursor, run1, run2): | ||
tasks = list(cursor.execute('SELECT DISTINCT problem, model, instance, problem_type FROM result ORDER BY problem, model, instance')) | ||
resultQuery = 'SELECT solved, moves_per_second FROM result WHERE run = ? AND problem = ? AND model = ? AND instance = ?' | ||
for problem, model, instance, problemType in tasks: | ||
result1 = cursor.execute(resultQuery, (run1, problem, model, instance)) | ||
solved1, mps1 = result1.fetchone() | ||
result2 = cursor.execute(resultQuery, (run2, problem, model, instance)) | ||
solved2, mps2 = result2.fetchone() | ||
yield {'problem': problem, 'model': model, 'instance': instance, 'speedup': mps2 / mps1 if mps1 and mps2 else None} | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description = 'Compares the performance of Yuck on two given test runs') | ||
parser.add_argument('run1', metavar = 'run1') | ||
parser.add_argument('run2', metavar = 'run2') | ||
args = parser.parse_args() | ||
with sqlite3.connect("results.db") as conn: | ||
cursor = conn.cursor() | ||
results = list(computeSpeedups(cursor, args.run1, args.run2)) | ||
speedups = sorted([result['speedup'] for result in results]) | ||
stats = { | ||
'speedup-min': min(speedups), | ||
'speedup-max': max(speedups), | ||
'speedup-mean': statistics.mean(speedups), | ||
# harmonic mean might be more appropriate, but it is available only from Python 3.6 | ||
'speedup-pstdev': statistics.pstdev(speedups), | ||
'speedup-median': statistics.median(speedups), | ||
'speedup-histogram': numpy.histogram(speedups, 'auto')[0].tolist() | ||
} | ||
print(json.dumps(stats, sort_keys = True, indent = 4)) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /usr/bin/python3 | ||
|
||
# This script creates a database of Yuck integration test results (results.db). | ||
# | ||
# To import results, call the script with a list of JSON result files on the command line. | ||
# When the database already exists, the given results will be added unless they are | ||
# already in the database. | ||
|
||
import argparse | ||
import json | ||
import sqlite3 | ||
from itertools import repeat | ||
|
||
def createDb(cursor): | ||
cursor.execute('CREATE TABLE IF NOT EXISTS result (run TEXT NOT NULL, suite TEXT NOT NULL, problem TEXT NOT NULL, model TEXT NOT NULL, instance TEXT NOT NULL, problem_type TEXT NOT NULL CONSTRAINT result_problem_type_constraint CHECK (problem_type IN ("MIN", "MAX", "SAT")), optimum INT, high_score INT, solved INT NOT NULL CONSTRAINT result_solved_constraint CHECK (solved in (0, 1)), violation INT CONSTRAINT result_violation_constraint CHECK (violation >= 0), quality INT, runtime_in_seconds DOUBLE CONSTRAINT result_runtime_in_seconds_constraint CHECK (runtime_in_seconds >= 0), moves_per_second DOUBLE CONSTRAINT result_moves_per_second_constraint CHECK (moves_per_second >= 0), CONSTRAINT result_unique_constraint UNIQUE (run, problem, model, instance) ON CONFLICT IGNORE)') | ||
cursor.execute('CREATE INDEX IF NOT EXISTS result_index ON result(run, problem, model, instance)') | ||
|
||
def importResults(run, file, cursor): | ||
results = json.load(file) | ||
solverStatistics = results.get('solver-statistics') | ||
cursor.execute( | ||
'INSERT INTO result VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', | ||
(run, | ||
results['task']['suite'], | ||
results['task']['problem'], | ||
results['task']['model'], | ||
results['task']['instance'], | ||
results['task']['problem-type'], | ||
results['task'].get('optimum'), | ||
results['task'].get('high-score'), | ||
results['result']['solved'], | ||
results['result'].get('violation'), | ||
results['result'].get('quality'), | ||
solverStatistics['runtime-in-seconds'] if solverStatistics else None, | ||
solverStatistics['moves-per-second'] if solverStatistics else None)) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description = 'Puts Yuck integration test results into database') | ||
parser.add_argument('run', metavar = 'run') | ||
parser.add_argument('filenames', metavar = 'json-result-file', nargs = '+') | ||
args = parser.parse_args() | ||
with sqlite3.connect("results.db") as conn: | ||
cursor = conn.cursor() | ||
createDb(cursor) | ||
cursor.execute('PRAGMA foreign_keys = ON'); | ||
for filename in args.filenames: | ||
with open(filename) as file: | ||
importResults(args.run, file, cursor) | ||
conn.commit() | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#! /usr/bin/python3 | ||
|
||
# This script helps to evaluate a given set of Yuck integration test runs. | ||
# | ||
# For each instance, the script retrieves the objective value of the best solution | ||
# in order to compute, for each given run, a penalty between 0 and 1 (using feature | ||
# scaling) where 0 means the solution is one of the best and 1 means it is one of the | ||
# worst. (In case there is no solution, the penalty is 1.) | ||
# | ||
# In the end the script prints, for each given run, the number of instances it failed on, | ||
# and the penalties in terms of their mean, standard deviation, and median. | ||
# | ||
# The database is expected to reside in the working directory under the name results.db. | ||
# | ||
# Notice that, by default, feature scaling uses all results that the database provides. | ||
# To restrict the analysis to the given runs, use the -r option. | ||
|
||
import argparse | ||
import json | ||
import numpy | ||
import sqlite3 | ||
import statistics | ||
import sys | ||
|
||
def evalRuns(cursor, args): | ||
jobQuery = 'SELECT DISTINCT problem, model, instance, problem_type FROM result' | ||
if args.problemType: | ||
jobQuery += ' WHERE problem_type = ?' | ||
jobQuery += ' ORDER BY problem, model, instance'; | ||
jobs = list(cursor.execute(jobQuery, (args.problemType, )) if args.problemType else cursor.execute(jobQuery)) | ||
if not jobs: | ||
print('No results found', file = sys.stderr) | ||
return {} | ||
runsInScope = args.runs if args.ignoreOtherRuns else list(map(lambda result: result[0], cursor.execute('SELECT DISTINCT run from result'))); | ||
results = {} | ||
penalties = {} | ||
failures = {} | ||
for run in runsInScope: | ||
resultQuery = 'SELECT solved, quality FROM result WHERE run = ?'; | ||
if args.problemType: | ||
resultQuery += ' AND problem_type = ?' | ||
resultQuery += ' ORDER BY problem, model, instance'; | ||
results[run] = list(cursor.execute(resultQuery, (run, args.problemType)) if args.problemType else cursor.execute(resultQuery, (run,))) | ||
if len(results[run]) != len(jobs): | ||
print('Expected {} results for run {}, but found {}'.format(len(jobs), run, len(results[run])), file = sys.stderr) | ||
return {} | ||
for run in args.runs: | ||
penalties[run] = [] | ||
failures[run] = 0 | ||
for i in range(0, len(jobs)): | ||
(problem, model, instance, problemType) = jobs[i] | ||
qualities = [int(result[1]) for result in [results[run][i] for run in runsInScope] if result[0] and result[1]] | ||
optima = [int(result[0]) for result in cursor.execute('SELECT optimum FROM result WHERE problem = ? AND model = ? AND instance = ? AND optimum IS NOT NULL', (problem, model, instance))] | ||
qualities += optima | ||
highScores = [int(result[0]) for result in cursor.execute('SELECT high_score FROM result WHERE problem = ? AND model = ? AND instance = ? AND high_score IS NOT NULL', (problem, model, instance))] | ||
qualities += highScores | ||
(low, high) = (None, None) if not qualities else (min(qualities), max(qualities)) | ||
if args.verbose: | ||
print('-' * 80) | ||
print(problem, instance, problemType, low, high) | ||
for run in args.runs: | ||
(solved, quality) = results[run][i] | ||
if solved: | ||
if high == low: | ||
penalty = 0 | ||
elif problemType == 'MIN': | ||
penalty = (quality - low) / (high - low) | ||
else: | ||
penalty = 1 - ((quality - low) / (high - low)) | ||
if args.verbose: | ||
print(run, quality, penalty) | ||
else: | ||
failures[run] += 1 | ||
penalty = 1 | ||
penalties[run] += [penalty] | ||
return {run: {'failures': failures[run], 'penalties': penalties[run]} for run in args.runs} | ||
|
||
def postprocessResult(result): | ||
penalties = result['penalties'] | ||
return { | ||
'failures': result['failures'], | ||
'penalty-min': min(penalties), | ||
'penalty-max': max(penalties), | ||
'penalty-mean': statistics.mean(penalties), | ||
'penalty-pstdev': statistics.pstdev(penalties), | ||
'penalty-median': statistics.median(penalties), | ||
'penalty-histogram': numpy.histogram(penalties, 10, (0, 1))[0].tolist() | ||
} | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description = 'Helps to evaluate a given set of Yuck integration test runs') | ||
parser.add_argument('-v', '--verbose', action='store_true') | ||
parser.add_argument('-r', '--ignore-other-runs', dest = 'ignoreOtherRuns', action='store_true', help = 'Ignore results from runs other than the given ones') | ||
parser.add_argument('-t', '--problem-type', dest = 'problemType', choices = ['SAT', 'MIN', 'MAX'], help = 'Restrict analysis to given problem type') | ||
parser.add_argument('runs', metavar = 'run', nargs = '+') | ||
args = parser.parse_args() | ||
with sqlite3.connect("results.db") as conn: | ||
cursor = conn.cursor() | ||
results = evalRuns(cursor, args) | ||
if results: | ||
postprocessedResults = {run: postprocessResult(results[run]) for run in results} | ||
print(json.dumps(postprocessedResults, sort_keys = True, indent = 4)) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.