diff options
| author | Martin Fink <martin@finkmartin.com> | 2025-05-12 08:14:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-12 08:14:08 +0200 |
| commit | 0866a557ac461a1b345dd9ff1e13b01105458ef8 (patch) | |
| tree | 483f44335b623c1f2a8ba911d1feb776eb3df642 /archive/2024/winter/bsc_dichler/scripts/experiments.py | |
| parent | e546f71869e32e88716c4ad05e0254ea3352a668 (diff) | |
| parent | f60cf8c4ba75eee2b25ffbeea2330206b257aae9 (diff) | |
| download | research-work-archive-artifacts-0866a557ac461a1b345dd9ff1e13b01105458ef8.tar.gz research-work-archive-artifacts-0866a557ac461a1b345dd9ff1e13b01105458ef8.zip | |
Merge pull request #2 from raphaeldichler/main
Add source code of 'Evaluation of the Performance of the Memory Tagging Extensions'
Diffstat (limited to 'archive/2024/winter/bsc_dichler/scripts/experiments.py')
| -rw-r--r-- | archive/2024/winter/bsc_dichler/scripts/experiments.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/archive/2024/winter/bsc_dichler/scripts/experiments.py b/archive/2024/winter/bsc_dichler/scripts/experiments.py new file mode 100644 index 000000000..c3779f7e1 --- /dev/null +++ b/archive/2024/winter/bsc_dichler/scripts/experiments.py @@ -0,0 +1,84 @@ +from typing import Callable, Literal +import matplotlib as mpl +import matplotlib.pyplot as plt +from pathlib import Path + +import importlib +import importlib.util + +Experiments = Literal[ + "cas", + "contiguous", + "non_contiguous", + "contiguous_tagging", + "malloc", + "parallel_non_contiguous", +] +PlottingFunction = Callable[[Path, str], None] +experiments: dict[str, PlottingFunction] | None = None + + +def set_experiments(discovered_experiments: dict[str, PlottingFunction]): + global experiments + experiments = discovered_experiments + + +def plot(output_root: Path, experiment: Experiments, format: Literal["pdf", "png"]): + assert experiment, "invalid state, experiment discovery was not executed" + rcParams = { + "font.family": "serif", + "font.size": 11, + "pgf.rcfonts": False, + } + + if format == "pdf": + mpl.use("pdf") + plt.rcParams["text.latex.preamble"] = r"\renewcommand{\mathdefault}[1][]{}" + rcParams["pgf.texsystem"] = "pdflatex" + + mpl.rcParams.update(rcParams) + experiments[experiment](output_root, format) + + +def verify_experiment(experiment_base: Path, experiment_name: str) -> None: + experiment_directory = experiment_base / Path(experiment_name) + if not experiment_directory.exists(): + raise Exception(f"Invalid state - cannot find experiment '{experiment_name}'.") + + makefile = experiment_directory / Path("Makefile") + if not makefile.exists(): + raise Exception( + f"Invalid state - cannot find Makefile for '{experiment_name}'." + ) + + evaluation_script = ( + Path(__file__).parent / Path("plot") / Path(f"{experiment_name}.py") + ) + if not evaluation_script.exists(): + raise Exception( + f"Invalid state - cannot find evaluation script for '{experiment_name}'." + ) + + +def discover_experiments(base: Path): + experiments = {} + + evaluation_script = Path(__file__).parent / Path("plot") + for file in evaluation_script.glob("*.py"): + if file.name == "__init__.py": + continue + module_name = file.stem + spec = importlib.util.spec_from_file_location(module_name, file) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + if hasattr(module, "plot"): + experiments[module_name] = module.plot + else: + print("foo") + + experiment_source = set() + for experiment in base.iterdir(): + if experiment.is_dir(): + experiment_source.add(experiment.name) + + return {k: v for k, v in experiments.items() if k in experiment_source} |