Skip to content

Commit

Permalink
connected the post processing to main app
Browse files Browse the repository at this point in the history
  • Loading branch information
dodu94 committed Jan 28, 2025
1 parent 23ab7ff commit 32999ca
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/jade/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ def main():
parser = argparse.ArgumentParser(description="JADE V&V")
parser.add_argument("--run", help="run benchmarks", action="store_true")
parser.add_argument("--raw", help="process raw results", action="store_true")
parser.add_argument("--pp", help="perform complete post-process of the results", action="store_true")
parser.add_argument("--gui", help="open the run configuration GUI", action="store_true")
parser.add_argument(
"--pp", help="perform complete post-process of the results", action="store_true"
)
parser.add_argument(
"--gui", help="open the run configuration GUI", action="store_true"
)

args = parser.parse_args()

Expand All @@ -22,7 +26,7 @@ def main():
if args.raw:
app.raw_process()
if args.pp:
raise NotImplementedError("JADE Post-processing not re-implemented yet")
app.post_process()


if __name__ == "__main__":
Expand Down
83 changes: 62 additions & 21 deletions src/jade/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
from tqdm import tqdm

import jade.resources as res
from jade import resources
from jade.app.fetch import fetch_iaea_inputs
from jade.config.paths_tree import PathsTree
from jade.config.pp_config import PostProcessConfig
from jade.config.raw_config import ConfigRawProcessor
from jade.config.run_config import RunConfig
from jade.config.status import GlobalStatus
from jade.gui.config_gui import ConfigGUI
from jade.gui.run_config_gui import ConfigGUI
from jade.helper.aux_functions import PathLike, get_code_lib, print_code_lib
from jade.helper.constants import CODE, FIRST_INITIALIZATION, JADE_TITLE
from jade.helper.constants import CODE, EXP_TAG, FIRST_INITIALIZATION, JADE_TITLE
from jade.post.atlas_processor import AtlasProcessor
from jade.post.excel_processor import ExcelProcessor
from jade.post.raw_processor import RawProcessor
from jade.run.benchmark import BenchmarkRunFactory
Expand All @@ -42,7 +44,8 @@ def __init__(self, root: PathLike | None = None, skip_init: bool = False):

# parse the config files
self.run_cfg = RunConfig.from_root(self.tree)
# TODO read here also the post-processing config
# parse the post-processing config
self.pp_cfg = PostProcessConfig(self.tree.cfg.bench_pp)

# Compute the global status
self.status = GlobalStatus(
Expand Down Expand Up @@ -173,27 +176,65 @@ def raw_process(self):
def post_process(self):
"""Post-process the data."""
logging.info("Post-processing data")
# recover the post-processing benchmark configurations
bench_cfg = PostProcessConfig(self.tree.cfg.bench_pp)
# load the pp code-lib requests
with open(self.tree.cfg.pp_cfg) as f:
pp_cfg = yaml.safe_load(f)
for benchmark, options in pp_cfg.items():
if options["process"]:
# prepare the new paths
pp_path = self.tree.get_new_post_bench_path(benchmark)
excel_folder = Path(pp_path, "excel")
os.mkdir(excel_folder)
# perform the excel processing
excel_cfg = bench_cfg.excel_cfgs[benchmark]
options["codelibs"]
processor = ExcelProcessor(
self.tree.raw,
excel_folder,
excel_cfg,
options["codelibs"],
to_pp = yaml.safe_load(f)
codelibs_tags = to_pp["code_libs"]
benchmarks = to_pp["benchmarks"]

for benchmark in benchmarks:
logging.info(f"Post-processing {benchmark}")
# get the benchmark configurations
excel_cfg = self.pp_cfg.excel_cfgs[benchmark]
atlas_cfg = self.pp_cfg.atlas_cfgs[benchmark]

code_libs = []
# if exp is in the libraries, put it always first
if EXP_TAG in codelibs_tags:
code_libs.remove(EXP_TAG)
code_libs.insert(0, EXP_TAG)

for codelib in code_libs:
# Check if the code-lib is available in this benchmark
# if yes, append it to the list
code, lib = get_code_lib(codelib)
if self.status.is_raw_available(codelib, benchmark):
code_libs.append((code, lib))
else:
logging.info(f"{codelib} is not available for {benchmark}")

# in case there are less than two code-libs skip the comparison
if len(code_libs) < 2:
logging.warning(
f"Less than two code-libs available for {benchmark}, skipped"
)
processor.process()
continue

# prepare the new paths
pp_path = self.tree.get_new_post_bench_path(benchmark)
excel_folder = Path(pp_path, "excel")
atlas_folder = Path(pp_path, "atlas")
os.mkdir(excel_folder)
os.mkdir(atlas_folder)

# perform the excel processing
excel_processor = ExcelProcessor(
self.tree.raw,
excel_folder,
excel_cfg,
code_libs,
)
excel_processor.process()

# perform the atlas processing
atlas_processor = AtlasProcessor(
self.tree.raw,
atlas_folder,
atlas_cfg,
code_libs,
files(resources).joinpath("atlas_template.docx"),
)
atlas_processor.process()

def start_config_gui(self):
"""Start the configuration GUI."""
Expand Down
9 changes: 8 additions & 1 deletion src/jade/config/pp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from pathlib import Path

from jade.config.atlas_config import ConfigAtlasProcessor
from jade.config.excel_config import ConfigExcelProcessor
from jade.helper.aux_functions import PathLike

Expand All @@ -16,4 +17,10 @@ def __init__(self, root_cfg_pp: PathLike):
cfg = ConfigExcelProcessor.from_yaml(Path(root_cfg_pp, file))
excel_cfgs[cfg.benchmark] = cfg
self.excel_cfgs = excel_cfgs
# TODO get all available config atlas processors
# Get all available config atlas processors
atlas_cfgs = {}
for file in os.listdir(Path(root_cfg_pp, "atlas")):
if file.endswith(".yaml") or file.endswith(".yml"):
cfg = ConfigAtlasProcessor.from_yaml(Path(root_cfg_pp, file))
atlas_cfgs[cfg.benchmark] = cfg
self.atlas_cfgs = atlas_cfgs
83 changes: 82 additions & 1 deletion src/jade/config/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CODE_CHECKERS,
PathLike,
get_code_lib,
print_code_lib,
)
from jade.helper.constants import CODE

Expand Down Expand Up @@ -124,7 +125,7 @@ def was_simulated(self, code: CODE, lib: str, benchmark: str) -> bool:
Returns
-------
bool
Treu if the simulation was performed and successful, False otherwise.
True if the simulation was performed and successful, False otherwise.
"""
try:
result = self.simulations[(code, lib, benchmark)]
Expand All @@ -149,6 +150,86 @@ def get_successful_simulations(

return successful_simulations

def get_all_raw(self) -> tuple[set[str], set[str]]:
"""Get all the code-libraries and benchmarks for which the
at least one raw data is available.
Returns
-------
set[str]
list of code-libraries for which the raw data was processed.
set[str]
list of benchmarks for which the raw data was processed.
"""
code_libs = []
benchmarks = []
for code, lib, benchmark in self.raw_data.keys():
code_libs.append(print_code_lib(code, lib))
benchmarks.append(benchmark)
return set(code_libs), set(benchmarks)

def get_codelibs_from_raw_benchmark(self, benchmarks: str | list[str]) -> set[str]:
"""Get the list of codelib for which the raw data of the requested benchmark
is available.
Parameters
----------
benchmark : str | list[str]
benchmark name.
Returns
-------
set[str]
list of codelib for which the raw data of the requested benchmark is available.
"""
if isinstance(benchmarks, str):
benchmarks = [benchmarks]

codelibs = []
for code, lib, bench in self.raw_data.keys():
if bench in benchmarks:
codelibs.append(print_code_lib(code, lib))
return set(codelibs)

def get_benchmark_from_raw_codelib(self, codelibs: str | list[str]) -> set[str]:
"""Get the list of benchmarks for which the raw data of the requested codelib
is available.
Parameters
----------
codelib : str | list[str]
codelib name.
Returns
-------
set[str]
list of benchmarks for which the raw data of the requested codelib is available.
"""
benchmarks = []
for code, lib, bench in self.raw_data.keys():
if print_code_lib(code, lib) in codelibs:
benchmarks.append(bench)
return set(benchmarks)

def is_raw_available(self, codelib: str, benchmark: str) -> bool:
"""Check if the raw data is available for the given codelib and benchmark.
Parameters
----------
codelib : str
codelib string.
benchmark : str
benchmark name.
Returns
-------
bool
True if the raw data is available, False otherwise.
"""
if codelib in self.get_codelibs_from_raw_benchmark(benchmark):
return True
return False


@dataclass
class CodeLibRunStatus:
Expand Down
Loading

0 comments on commit 32999ca

Please sign in to comment.