Skip to content
Snippets Groups Projects
Commit 5c4985c4 authored by Hans-Jörg's avatar Hans-Jörg
Browse files

Remove old GridTPT parser

parent 813ebec6
No related branches found
No related tags found
No related merge requests found
import re
import pandas as pd
class GridTPTResult:
__type_re = r"^Type +: (\w+)$"
__options_re = r"^Options +: (.*)$"
__cpu_limit_re = r"^CPU limit +: ([0-9]+)s"
__header_re = r"^Name +total_time +result"
__data_re = r"^([^ ]+) +([-0-9\.]+) +([^ ]+)"
def __init__(self, path, logics=None):
results = []
if logics:
logics = list(map(lambda s: s.strip(), logics))
with path.open() as f:
for line in f:
m = re.match(self.__data_re, line)
if m:
r = m.group(3).strip()
if r == "1" or r == "0":
time = float(m.group(2))
else:
time = float("inf") # unsolved
if logics:
exp_logic = m.group(1).split("/")[0]
if exp_logic in logics:
results.append((m.group(1), time))
else:
results.append((m.group(1), time))
continue
m = re.match(self.__type_re, line)
if m:
r = m.group(1).strip()
if not r == "perf":
raise ValueError("Experiment type not 'perf'.")
else:
continue
m = re.match(self.__options_re, line)
if m:
self.options = m.group(1)
continue
m = re.match(self.__cpu_limit_re, line)
if m:
self.cpu_limit = int(m.group(1))
if not hasattr(self, "cpu_limit"):
raise ValueError("Could not parse cpu limit.")
if not hasattr(self, "options"):
raise ValueError("Could not parse strategy.")
r = [list(t) for t in zip(*results)]
if len(r) != 2:
raise ValueError("Could not get any solved benchmarks.")
[names, times] = r
self.results = pd.DataFrame(times, index=names, columns=["Time"])
def remove_results(self, index):
self.old_results = self.results.copy()
new_idx = self.results.index.difference(index)
self.results = self.results.reindex(new_idx)
def restore_results(self):
self.results = self.old_results
def solves_in(self, benchmark, time_slice):
try:
return self.results.loc[benchmark].Time <= time_slice
except KeyError:
return False
""" Returns the indices of the time slices that solve it. Assumes
time_slices is sorted in acending order. """
def solve_index(self, benchmark, time_slices, epsilon):
try:
time = self.results.loc[benchmark].Time
except KeyError:
return []
for i in range(len(time_slices)):
if time_slices[i] >= (time + epsilon):
return range(i, len(time_slices))
return []
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment