Skip to content

Commit

Permalink
add file sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
simon1hofmann committed Nov 28, 2023
1 parent 6c4a88b commit a35ea29
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 42 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = [
"importlib_resources>=5.9; python_version < '3.10'",
"requests>=2.31.0",
"openpyxl>=3.1.2",
"humanize>=4.9.0",
]

classifiers = [
Expand Down
72 changes: 45 additions & 27 deletions src/mnt/bench/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import TYPE_CHECKING, Any, cast
from zipfile import ZIP_DEFLATED, ZipFile

import humanize # type: ignore[import-not-found]
import pandas as pd
import requests
from packaging import version
Expand Down Expand Up @@ -54,9 +55,11 @@ class ParsedBenchmarkName:
physical_design_algorithm: str
optimized: str
ordered: str
x: str
y: str
area: str
x: int
y: int
area: int
size_uncompressed: int
size_compressed: int
filename: str


Expand Down Expand Up @@ -158,38 +161,47 @@ def filter_database(self, benchmark_config: BenchmarkConfiguration) -> pd.DataFr

if benchmark_config.gate:
db_tmp = db_tmp.loc[db_tmp["level"] == "gate"]
db_filtered = pd.concat([db_filtered, db_tmp])
db_filtered = pd.concat([db_filtered if not db_filtered.empty else None, db_tmp])

if benchmark_config.one and not benchmark_config.bestagon:
db_filtered = db_tmp.loc[db_tmp["library"] == "one"]

if not benchmark_config.one and benchmark_config.bestagon:
db_filtered = db_tmp.loc[db_tmp["library"] == "bestagon"]

if benchmark_config.best:
db_filtered = db_filtered.loc[db_filtered["clocking_scheme"] == "best"]

else:
if benchmark_config.one and not benchmark_config.bestagon:
db_filtered = db_tmp.loc[db_tmp["library"] == "one"]

if not benchmark_config.one and benchmark_config.bestagon:
db_filtered = db_tmp.loc[db_tmp["library"] == "bestagon"]

db_tmp_all_schemes = pd.DataFrame(columns=colnames)
if benchmark_config.twoddwave:
db_tmp = db_filtered.loc[db_filtered["clocking_scheme"] == "2ddwave"]
db_tmp_all_schemes = pd.concat([db_tmp_all_schemes, db_tmp])
db_tmp_all_schemes = pd.concat(
[db_tmp_all_schemes if not db_tmp_all_schemes.empty else None, db_tmp]
)

if benchmark_config.use:
db_tmp = db_filtered.loc[db_filtered["clocking_scheme"] == "use"]
db_tmp_all_schemes = pd.concat([db_tmp_all_schemes, db_tmp])
db_tmp_all_schemes = pd.concat(
[db_tmp_all_schemes if not db_tmp_all_schemes.empty else None, db_tmp]
)

if benchmark_config.res:
db_tmp = db_filtered.loc[db_filtered["clocking_scheme"] == "res"]
db_tmp_all_schemes = pd.concat([db_tmp_all_schemes, db_tmp])
db_tmp_all_schemes = pd.concat(
[db_tmp_all_schemes if not db_tmp_all_schemes.empty else None, db_tmp]
)

if benchmark_config.esr:
db_tmp = db_filtered.loc[db_filtered["clocking_scheme"] == "esr"]
db_tmp_all_schemes = pd.concat([db_tmp_all_schemes, db_tmp])
db_tmp_all_schemes = pd.concat(
[db_tmp_all_schemes if not db_tmp_all_schemes.empty else None, db_tmp]
)

if benchmark_config.row:
db_tmp = db_filtered.loc[db_filtered["clocking_scheme"] == "row"]
db_tmp_all_schemes = pd.concat([db_tmp_all_schemes, db_tmp])
db_tmp_all_schemes = pd.concat(
[db_tmp_all_schemes if not db_tmp_all_schemes.empty else None, db_tmp]
)

if not db_tmp_all_schemes.empty:
db_filtered = db_tmp_all_schemes
Expand All @@ -213,7 +225,7 @@ def filter_database(self, benchmark_config: BenchmarkConfiguration) -> pd.DataFr
db_filtered = db_filtered.loc[db_filtered["ordered"] == "ord"]

if benchmark_config.network:
db_filtered = pd.concat([db_filtered, db_networks])
db_filtered = pd.concat([db_filtered if not db_filtered.empty else None, db_networks])

return db_filtered.drop_duplicates()

Expand Down Expand Up @@ -298,6 +310,9 @@ def prettify_table(table: pd.DataFrame) -> pd.DataFrame:
ord_mapping = {"ord": "✓", "unord": "✗"}
table.replace({"ordered": ord_mapping}, inplace=True)

table["size_compressed"] = table["size_compressed"].apply(lambda x: humanize.naturalsize(x))
table["size_uncompressed"] = table["size_uncompressed"].apply(lambda x: humanize.naturalsize(x))

column_mapping = {
"benchmark": "Benchmark Function",
"level": "Abstraction Level",
Expand All @@ -309,6 +324,8 @@ def prettify_table(table: pd.DataFrame) -> pd.DataFrame:
"x": "Layout Width",
"y": "Layout Height",
"area": "Layout Area",
"size_uncompressed": "File Size (uncompressed)",
"size_compressed": "File Size (compressed)",
"filename": "Filename",
}
table.columns = [column_mapping.get(col, col) for col in table.columns]
Expand Down Expand Up @@ -377,12 +394,12 @@ def prepare_form_input(form_data: dict[str, str]) -> BenchmarkConfiguration:
res = "res" in k or res
esr = "esr" in k or esr
row = "row" in k or row
best = "best" in k or best
best = "best-layout" in k or best
exact = "exact" in k or exact
ortho = "ortho" in k or ortho
nanoplacer = "nanoplacer" in k or nanoplacer
optimized = ("post-layout" in k) or optimized
ordered = ("input-ordering" in k) or ordered
optimized = "post-layout" in k or optimized
ordered = "input-ordering" in k or ordered

return BenchmarkConfiguration(
indices_benchmarks=indices_benchmarks,
Expand Down Expand Up @@ -525,14 +542,12 @@ def parse_data(self, filename: str) -> ParsedBenchmarkName:
Returns:
ParsedBenchmarkName: Parsed data extracted from the filename.
"""
layout_dimensions: Any = {}
layout_dimensions: Any = next((entry for entry in self.layout_dimensions if filename in entry), {}) # type: ignore[union-attr]
layout_dimensions = layout_dimensions.get(filename, {})

if filename.endswith(".fgl"):
layout_dimensions = next((entry for entry in self.layout_dimensions if filename in entry), {}) # type: ignore[union-attr]

is_best_fgl = "best.fgl" in filename.lower()
filename = filename.split(".")[0]
specs = filename.lower().split("_")
specs = filename.split(".")[0].lower().split("_")

benchmark = "_".join(specs[0 : -(2 if is_best_fgl else 5)])
library, clocking_scheme, *additional_specs = specs[-2:] if is_best_fgl else specs[-5:]
Expand All @@ -541,8 +556,6 @@ def parse_data(self, filename: str) -> ParsedBenchmarkName:
level = "gate"
area = int(layout_dimensions.get("x", 0)) * int(layout_dimensions.get("y", 0)) if layout_dimensions else ""

filename = filename + ".fgl"

elif filename.endswith(".v"):
benchmark = filename.split(".")[0].lower()
library = clocking_scheme = physical_design_algorithm = optimized = ordered = ""
Expand All @@ -553,6 +566,9 @@ def parse_data(self, filename: str) -> ParsedBenchmarkName:
msg = "Unknown file type in MNTBench_all.zip"
raise RuntimeError(msg)

size_uncompressed = round(layout_dimensions.get("size_uncompressed", 0))
size_compressed = round(layout_dimensions.get("size_compressed", 0))

return ParsedBenchmarkName(
benchmark=benchmark,
level=level,
Expand All @@ -564,6 +580,8 @@ def parse_data(self, filename: str) -> ParsedBenchmarkName:
x=layout_dimensions.get("x", ""),
y=layout_dimensions.get("y", ""),
area=area, # type: ignore[arg-type]
size_uncompressed=size_uncompressed,
size_compressed=size_compressed,
filename=filename,
)

Expand Down
20 changes: 18 additions & 2 deletions src/mnt/bench/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime
from typing import TYPE_CHECKING

import humanize # type: ignore[import-not-found]
import pandas as pd
from flask import Flask, cli, jsonify, make_response, render_template, request, send_from_directory

Expand Down Expand Up @@ -195,11 +196,26 @@ def get_num_benchmarks() -> Response:
prepared_data = SERVER.backend.prepare_form_input(data)
raw_table = SERVER.backend.get_updated_table(prepared_data)
file_paths = SERVER.backend.get_selected_file_paths(raw_table)
size_compressed = humanize.naturalsize(raw_table["size_compressed"].sum())
size_uncompressed = humanize.naturalsize(raw_table["size_uncompressed"].sum())
table = SERVER.backend.prettify_table(raw_table)

return jsonify( # type: ignore[no-any-return]
{"num_selected": len(file_paths), "table": table.to_html(classes="data", header="true", index=False)}
{
"num_selected": len(file_paths),
"table": table.to_html(classes="data", header="true", index=False),
"size_compressed": size_compressed,
"size_uncompressed": size_uncompressed,
}
)
return jsonify({"num_selected": 0, "table": pd.DataFrame().to_html(classes="data", header="true", index=False)}) # type: ignore[no-any-return]
return jsonify( # type: ignore[no-any-return]
{
"num_selected": 0,
"table": pd.DataFrame().to_html(classes="data", header="true", index=False),
"size_compressed": 0,
"size_uncompressed": 0,
}
)


def start_server(
Expand Down
Binary file modified src/mnt/bench/static/abstraction_level.pdf
Binary file not shown.
Binary file modified src/mnt/bench/static/clocking_scheme.pdf
Binary file not shown.
Binary file modified src/mnt/bench/static/gate_library.pdf
Binary file not shown.
Binary file modified src/mnt/bench/static/optimization_algorithm.pdf
Binary file not shown.
Binary file modified src/mnt/bench/static/physical_design_algorithm.pdf
Binary file not shown.
23 changes: 16 additions & 7 deletions src/mnt/bench/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,10 @@ <h6>Clocking Scheme</h6>
class="form-check-input"
type="checkbox"
value="true"
id="best"
name="best"
id="best-layout"
name="best-layout"
/>
<label for="best">Best</label>
<label for="best-layout">Best</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -774,6 +774,13 @@ <h4>Download</h4>
<div class="d-flex">
<div class="same_row">Number of selected benchmarks: &nbsp;</div>
<div class="same_row" id="num_benchmarks">0</div>
<div class="same_row">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="same_row">File Size (compressed): &nbsp;</div>
<div class="same_row" id="size_compressed">0</div>
<div class="same_row">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<div class="same_row">File Size (uncompressed): &nbsp;</div>
<div class="same_row" id="size_uncompressed">0</div>
<div class="same_row">&nbsp;</div>
</div>
After the download button is clicked, all benchmark functions provided
as <span style="font-family: monospace">.v</span> files and selected
Expand Down Expand Up @@ -983,15 +990,15 @@ <h6>Selected Benchmarks:</h6>
setCheckboxState("use", false, false, false);
setCheckboxState("res", false, false, false);
setCheckboxState("esr", false, false, false);
setCheckboxState("best", false, false, false);
setCheckboxState("best-layout", false, false, false);
enable_physical_design_algorithm_selection();
}
else {
disable_clocking_scheme_selection(one=true, bestagon=false);
}
if (document.getElementById("bestagon").checked) {
setCheckboxState("row", false, false, false);
setCheckboxState("best", false, false, false);
setCheckboxState("best-layout", false, false, false);
enable_physical_design_algorithm_selection();
}
else {
Expand All @@ -1006,7 +1013,7 @@ <h6>Selected Benchmarks:</h6>
}

function enable_physical_design_algorithm_selection(){
if (!document.getElementById("best").checked){
if (!document.getElementById("best-layout").checked){
var ortho_possible = (document.getElementById("twoddwave").checked || document.getElementById("row").checked) && !(document.getElementById("use").checked || document.getElementById("res").checked || document.getElementById("esr").checked);
var exact_or_nanoplacer_possible = document.getElementById("twoddwave").checked || document.getElementById("row").checked || document.getElementById("use").checked || document.getElementById("res").checked || document.getElementById("esr").checked;
if (exact_or_nanoplacer_possible && !ortho_possible) {
Expand Down Expand Up @@ -1083,7 +1090,7 @@ <h6>Selected Benchmarks:</h6>
}

if (best) {
setCheckboxState("best", false, true, true);
setCheckboxState("best-layout", false, true, true);
}
}

Expand All @@ -1109,6 +1116,8 @@ <h6>Selected Benchmarks:</h6>
}).then(response => response.json())
.then(response => {
document.getElementById("num_benchmarks").innerHTML = response.num_selected;
document.getElementById("size_compressed").innerHTML = response.size_compressed;
document.getElementById("size_uncompressed").innerHTML = response.size_uncompressed;

// Check if the 'table' property exists in the response
if (response.table) {
Expand Down
14 changes: 8 additions & 6 deletions tests/test_benchviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@
("filename", "expected_res"),
[
(
"mux21_ONE_twoddwave_exact_UnOpt_UnOrd.fgl",
"mux21_ONE_2DDWave_exact_UnOpt_UnOrd.fgl",
backend.ParsedBenchmarkName(
benchmark="mux21",
level="gate",
library="one",
clocking_scheme="twoddwave",
clocking_scheme="2ddwave",
physical_design_algorithm="exact",
optimized="unopt",
ordered="unord",
x="",
y="",
area="",
filename="mux21_ONE_twoddwave_exact_UnOpt_UnOrd.fgl",
x=3,
y=4,
area=12,
size_compressed=1177,
size_uncompressed=3513,
filename="mux21_ONE_2DDWave_exact_UnOpt_UnOrd.fgl",
),
),
],
Expand Down

0 comments on commit a35ea29

Please sign in to comment.