Skip to content
Snippets Groups Projects
Commit 37e1f530 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Move away from dataclass (python 3.7+)

parent 49397dc3
No related branches found
No related tags found
No related merge requests found
from dataclasses import dataclass
from pathlib import Path
from subprocess import PIPE, CalledProcessError
from typing import Iterable, List, Tuple, Union
......@@ -39,7 +38,12 @@ def profile_config_file(
raise ValueError("Config file with no configs is unsupported.")
# Modifies configs in place.
profile_configs(
binary_path, configs[1:], configs[0], progress_bar, profile_filename, qos_filename
binary_path,
configs[1:],
configs[0],
progress_bar,
profile_filename,
qos_filename,
)
write_hpvm_configs(header, configs, Path(output_config_path))
......@@ -57,10 +61,10 @@ def profile_configs(
from tqdm import tqdm
baseline_time, baseline_acc = profile_config(binary_path, baseline_config)
baseline_time, baseline_acc = measure_config(binary_path, baseline_config)
iterable = tqdm(configs, desc="Configs profiled") if progress_bar else configs
for idx in iterable:
time, acc = profile_config(binary_path, config, profile_filename, qos_filename)
for config in iterable:
time, acc = measure_config(binary_path, config, profile_filename, qos_filename)
speedup = baseline_time / time
config.update_profile_results(speedup, acc, baseline_acc)
return configs
......@@ -127,15 +131,23 @@ def plot_hpvm_configs(
return fig
@dataclass
class Config:
conf_name: str
speedup: float
energy: float
qos: float
qos_loss: float
# We don't care about the information in this part, and we don't parse this.
config_body: List[str]
def __init__(
self,
conf_name: str,
speedup: float,
energy: float,
qos: float,
qos_loss: float,
config_body: List[str],
):
self.conf_name = conf_name
self.speedup = speedup
self.energy = energy
self.qos = qos
self.qos_loss = qos_loss
# We don't care about the information in this part, and we don't parse this.
self.config_body = config_body
def update_profile_results(self, speedup: float, qos: float, base_qos: float):
recorded_base_qos = self.qos + self.qos_loss
......@@ -189,7 +201,6 @@ def write_hpvm_configs(header: str, configs: Iterable[Config], to_file: PathLike
f.flush()
def _read_profile_file(profile_file_path: Path):
with profile_file_path.open() as f:
target_lines = [line.strip() for line in f if "Total Time" in line]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment