QuAcc/quacc/main.py

74 lines
2.1 KiB
Python
Raw Normal View History

from sys import platform
2023-10-31 03:01:24 +01:00
from traceback import print_exception as traceback
import quacc.evaluation.comp as comp
from quacc.dataset import Dataset
from quacc.environment import env
2023-10-31 03:01:24 +01:00
from quacc.logger import Logger
from quacc.utils import create_dataser_dir
2023-11-04 00:06:40 +01:00
CE = comp.CompEstimator()
2023-05-17 14:02:29 +02:00
def toast():
if platform == "win32":
import win11toast
win11toast.notify("Comp", "Completed Execution")
2023-09-24 02:21:18 +02:00
def estimate_comparison():
2023-10-31 03:01:24 +01:00
log = Logger.logger()
for conf in env.get_confs():
dataset = Dataset(
env.DATASET_NAME,
target=env.DATASET_TARGET,
n_prevalences=env.DATASET_N_PREVS,
2023-10-28 16:14:37 +02:00
prevs=env.DATASET_PREVS,
)
2023-10-31 14:53:00 +01:00
create_dataser_dir(dataset.name, update=env.DATASET_DIR_UPDATE)
try:
2023-11-04 00:06:40 +01:00
dr = comp.evaluate_comparison(
dataset,
estimators=CE.name[env.COMP_ESTIMATORS],
)
except Exception as e:
2023-10-31 14:53:00 +01:00
log.error(f"Evaluation over {dataset.name} failed. Exception: {e}")
traceback(e)
2023-10-31 14:53:00 +01:00
for plot_conf in env.get_plot_confs():
for m in env.METRICS:
output_path = env.OUT_DIR / f"{plot_conf}_{m}.md"
try:
_repr = dr.to_md(
conf=plot_conf,
metric=m,
2023-11-04 00:06:40 +01:00
estimators=CE.name[env.PLOT_ESTIMATORS],
2023-10-31 14:53:00 +01:00
stdev=env.PLOT_STDEV,
)
with open(output_path, "w") as f:
f.write(_repr)
except Exception as e:
log.error(
f"Failed while saving configuration {plot_conf} of {dataset.name}. Exception: {e}"
)
traceback(e)
2023-09-24 02:21:18 +02:00
# print(df.to_latex(float_format="{:.4f}".format))
# print(utils.avg_group_report(df).to_latex(float_format="{:.4f}".format))
2023-09-24 02:21:18 +02:00
def main():
2023-10-31 03:01:24 +01:00
log = Logger.logger()
2023-10-28 16:14:37 +02:00
try:
estimate_comparison()
except Exception as e:
log.error(f"estimate comparison failed. Exceprion: {e}")
traceback(e)
toast()
2023-10-28 16:14:37 +02:00
Logger.close()
2023-05-17 14:02:29 +02:00
if __name__ == "__main__":
2023-09-24 02:21:18 +02:00
main()