Fix some tests and refactor simulation script
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from pathlib import Path
|
||||
from dataclasses import dataclass
|
||||
from simulation import (
|
||||
Simulation,
|
||||
Configuration,
|
||||
get_options_from_args,
|
||||
ConfigTokens,
|
||||
get_argparser,
|
||||
get_options,
|
||||
simulation_results,
|
||||
)
|
||||
|
||||
script_directory = os.path.dirname(os.path.abspath(__file__))
|
||||
base_config = os.path.join(script_directory, "example_ddr3_simulations.json")
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
SCRIPT_DIRECTORY = Path(__file__).parent.resolve()
|
||||
DEFAULT_BASE_CONFIG = SCRIPT_DIRECTORY / "example_ddr3_simulations.json"
|
||||
|
||||
simulations: list[Simulation] = []
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SchedulerBuffer:
|
||||
buffer: str
|
||||
@@ -35,7 +35,7 @@ for refresh_policy in refresh_policies:
|
||||
for pattern in patterns:
|
||||
PAGE_POLICY = "Open" if pattern == "sequential" else "Closed"
|
||||
|
||||
config = Configuration(
|
||||
config_tokens = ConfigTokens(
|
||||
f"{refresh_policy}_{scheduler_buffer.buffer}_{scheduler_buffer.size}_{pattern}",
|
||||
{
|
||||
"refresh_policy": refresh_policy,
|
||||
@@ -46,69 +46,39 @@ for refresh_policy in refresh_policies:
|
||||
},
|
||||
)
|
||||
|
||||
simulations.append(Simulation(config))
|
||||
simulations.append(Simulation(config_tokens))
|
||||
|
||||
|
||||
options = get_options_from_args()
|
||||
parser = get_argparser()
|
||||
options = get_options(parser.parse_args())
|
||||
|
||||
if options.base_config is None:
|
||||
options.base_config = base_config
|
||||
options.base_config = DEFAULT_BASE_CONFIG
|
||||
|
||||
dataframe = simulation_results(options, simulations)
|
||||
df = simulation_results(options, simulations)
|
||||
|
||||
# Generate interesting plots!
|
||||
for refresh_policy in refresh_policies:
|
||||
refresh_policy_filter = dataframe["refresh_policy"] == refresh_policy
|
||||
for name, data in df.group_by("refresh_policy", "scheduler_buffer_size", maintain_order=True):
|
||||
plt.figure(figsize=(8.0, 12.0))
|
||||
|
||||
for scheduler_buffer in scheduler_buffers:
|
||||
scheduler_buffer_filter = (
|
||||
dataframe["scheduler_buffer"] == scheduler_buffer.buffer
|
||||
)
|
||||
scheduler_buffer_size_filter = (
|
||||
dataframe["scheduler_buffer_size"] == scheduler_buffer.size
|
||||
)
|
||||
plt.bar(
|
||||
"pattern",
|
||||
"bandwidth",
|
||||
data=data,
|
||||
)
|
||||
|
||||
filters = (
|
||||
refresh_policy_filter
|
||||
& scheduler_buffer_filter
|
||||
& scheduler_buffer_size_filter
|
||||
)
|
||||
# Plot MAX bar
|
||||
plt.bar(
|
||||
"MAX",
|
||||
"max_bandwidth",
|
||||
data=data,
|
||||
color="darkgray",
|
||||
)
|
||||
|
||||
TEMP_DATAFRAME = dataframe[filters]
|
||||
plt.title(name)
|
||||
plt.axis(ymin=0, ymax=120)
|
||||
plt.xlabel("Access Pattern")
|
||||
plt.ylabel("Bandwidth [Gb/s]")
|
||||
|
||||
for pattern in patterns:
|
||||
pattern_filter = dataframe["pattern"] == pattern
|
||||
|
||||
plt.figure(figsize=(8.0, 12.0))
|
||||
|
||||
filters = (
|
||||
refresh_policy_filter
|
||||
& scheduler_buffer_filter
|
||||
& scheduler_buffer_size_filter
|
||||
)
|
||||
|
||||
TEMP_DATAFRAME = dataframe[filters]
|
||||
|
||||
plt.bar(
|
||||
"pattern",
|
||||
"bandwidth",
|
||||
data=TEMP_DATAFRAME,
|
||||
)
|
||||
|
||||
# Plot MAX line
|
||||
plt.bar(
|
||||
"MAX",
|
||||
"max_bandwidth",
|
||||
data=TEMP_DATAFRAME,
|
||||
color="darkgray",
|
||||
)
|
||||
|
||||
title = f"{refresh_policy} {scheduler_buffer.buffer} {scheduler_buffer.size}"
|
||||
|
||||
plt.title(title)
|
||||
plt.axis(ymin=0, ymax=120)
|
||||
plt.xlabel("Access Pattern")
|
||||
plt.ylabel("Bandwidth [Gb/s]")
|
||||
|
||||
plt.savefig(f"{options.out_dir}/{title}.png")
|
||||
plt.close()
|
||||
plt.savefig(options.out_dir / f"{name}.png")
|
||||
plt.close()
|
||||
|
||||
Reference in New Issue
Block a user