about summary refs log tree commit diff stats
path: root/archive/2024/winter/bsc_dichler/scripts/experiments.py
blob: 0077dbad26a111d9ba1e39de62e65895fb2f6884 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from typing import Callable, Literal
import matplotlib as mpl
import matplotlib.pyplot as plt
from pathlib import Path

from plot import parallel_non_contiguous
from plot import cas
from plot import non_contiguous
from plot import contiguous
from plot import malloc
from plot import contiguous_tagging

Experiments = Literal[
    "cas",
    "contiguous",
    "non_contiguous",
    "contiguous_tagging",
    "malloc",
    "parallel_non_contiguous",
]
PlottingFunction = Callable[[Path, str], None]

experiments: dict[str, PlottingFunction] = {
    "cas": lambda r, t: cas.plot(r, t),
    "contiguous": lambda r, t: contiguous.plot(r, t),
    "non_contiguous": lambda r, t: non_contiguous.plot(r, t),
    "contiguous_tagging": lambda r, t: contiguous_tagging.plot(r, t),
    "malloc": lambda r, t: malloc.plot(r, t),
    "parallel_non_contiguous": lambda r, t: parallel_non_contiguous.plot(r, t),
}


def experiment_choices() -> list[str]:
    return list(experiments.keys())


def plot(output_root: Path, experiment: Experiments, format: Literal["pdf", "png"]):
    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)