test_prevs bug fixed, basedir added to TestReport, added load_results
This commit is contained in:
parent
5ee04a2a19
commit
dcbbaba361
|
|
@ -1,25 +1,33 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from quacc.experiments.util import getpath
|
from genericpath import isfile
|
||||||
from quacc.utils.commons import load_json_file, save_json_file
|
|
||||||
|
from quacc.utils.commons import get_results_path, load_json_file, save_json_file
|
||||||
|
|
||||||
|
|
||||||
class TestReport:
|
class TestReport:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
basedir,
|
||||||
cls_name,
|
cls_name,
|
||||||
acc_name,
|
acc_name,
|
||||||
dataset_name,
|
dataset_name,
|
||||||
method_name,
|
method_name,
|
||||||
):
|
):
|
||||||
|
self.basedir = basedir
|
||||||
self.cls_name = cls_name
|
self.cls_name = cls_name
|
||||||
self.acc_name = acc_name
|
self.acc_name = acc_name
|
||||||
self.dataset_name = dataset_name
|
self.dataset_name = dataset_name
|
||||||
self.method_name = method_name
|
self.method_name = method_name
|
||||||
|
|
||||||
def path(self, basedir):
|
@property
|
||||||
return getpath(
|
def path(self):
|
||||||
basedir, self.cls_name, self.acc_name, self.dataset_name, self.method_name
|
return get_results_path(
|
||||||
|
self.basedir,
|
||||||
|
self.cls_name,
|
||||||
|
self.acc_name,
|
||||||
|
self.dataset_name,
|
||||||
|
self.method_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_result(self, test_prevs, true_accs, estim_accs, t_train, t_test_ave):
|
def add_result(self, test_prevs, true_accs, estim_accs, t_train, t_test_ave):
|
||||||
|
|
@ -35,28 +43,31 @@ class TestReport:
|
||||||
raise AttributeError("Incomplete report cannot be dumped")
|
raise AttributeError("Incomplete report cannot be dumped")
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
"basedir": self.basedir,
|
||||||
"cls_name": self.cls_name,
|
"cls_name": self.cls_name,
|
||||||
"acc_name": self.acc_name,
|
"acc_name": self.acc_name,
|
||||||
"dataset_name": self.dataset_name,
|
"dataset_name": self.dataset_name,
|
||||||
"method_name": self.method_name,
|
"method_name": self.method_name,
|
||||||
"t_train": self.t_train,
|
"test_prevs": self.test_prevs,
|
||||||
"t_test_ave": self.t_test,
|
|
||||||
"true_accs": self.true_accs,
|
"true_accs": self.true_accs,
|
||||||
"estim_accs": self.estim_accs,
|
"estim_accs": self.estim_accs,
|
||||||
|
"t_train": self.t_train,
|
||||||
|
"t_test_ave": self.t_test_ave,
|
||||||
}
|
}
|
||||||
|
|
||||||
result_path = self.path(basedir)
|
save_json_file(self.path, result)
|
||||||
save_json_file(result_path, result)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_json(cls, path) -> "TestReport":
|
def load_json(cls, path) -> "TestReport":
|
||||||
def _test_report_hook(_dict):
|
def _test_report_hook(_dict):
|
||||||
return TestReport(
|
return TestReport(
|
||||||
|
basedir=_dict["basedir"],
|
||||||
cls_name=_dict["cls_name"],
|
cls_name=_dict["cls_name"],
|
||||||
acc_name=_dict["acc_name"],
|
acc_name=_dict["acc_name"],
|
||||||
dataset_name=_dict["dataset_name"],
|
dataset_name=_dict["dataset_name"],
|
||||||
method_name=_dict["method_name"],
|
method_name=_dict["method_name"],
|
||||||
).add_result(
|
).add_result(
|
||||||
|
test_prevs=_dict["test_prevs"],
|
||||||
true_accs=_dict["true_accs"],
|
true_accs=_dict["true_accs"],
|
||||||
estim_accs=_dict["estim_accs"],
|
estim_accs=_dict["estim_accs"],
|
||||||
t_train=_dict["t_train"],
|
t_train=_dict["t_train"],
|
||||||
|
|
@ -67,20 +78,28 @@ class TestReport:
|
||||||
|
|
||||||
|
|
||||||
class Report:
|
class Report:
|
||||||
def __init__(self, tests: list[TestReport]):
|
def __init__(self, results: list[TestReport]):
|
||||||
self.tests = tests
|
self.results = results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_tests(cls, path):
|
def load_results(cls, basedir):
|
||||||
if not os.path.isdir(path):
|
def walk_results(path):
|
||||||
raise ValueError("Cannot load test results: invalid directory")
|
results = []
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return results
|
||||||
|
|
||||||
_tests = []
|
|
||||||
for f in os.listdir(path):
|
for f in os.listdir(path):
|
||||||
if f.endswith(".json"):
|
n_path = os.path.join(path, f)
|
||||||
_tests.append(TestReport.load_json(f))
|
if os.path.isdir(n_path):
|
||||||
|
results += walk_results(n_path)
|
||||||
|
if os.path.isfile(n_path) and n_path.endswith(".json"):
|
||||||
|
results.append(TestReport.load_json(n_path))
|
||||||
|
|
||||||
return Report(_tests)
|
return results
|
||||||
|
|
||||||
|
_path = os.path.join("results", basedir)
|
||||||
|
_results = walk_results(_path)
|
||||||
|
return Report(results=_results)
|
||||||
|
|
||||||
def _filter_by_dataset(self):
|
def _filter_by_dataset(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue