tahamajs's picture
download
raw
20.9 kB
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
from typing import Dict, List, Tuple, Any, Optional
import os
from datetime import datetime
import json
import warnings
warnings.filterwarnings("ignore")
plt.style.use("seaborn-v0_8")
sns.set_palette("husl")
class MemoryVisualizer:
def __init__(self, output_dir: str = "visualizations"):
self.output_dir = output_dir
self._ensure_output_dir()
def _ensure_output_dir(self):
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
def plot_performance_comparison(
self, results_data: List[Dict], save: bool = True
) -> str:
df = pd.DataFrame(results_data)
fig, axes = plt.subplots(2, 2, figsize=(15, 12))
fig.suptitle(
"Memory Systems Performance Comparison", fontsize=16, fontweight="bold"
)
throughput_data = (
df.groupby(["system_name", "operation"])["throughput"].mean().unstack()
)
throughput_data.plot(kind="bar", ax=axes[0, 0], width=0.8)
axes[0, 0].set_title("Average Throughput by System and Operation")
axes[0, 0].set_ylabel("Operations per Second")
axes[0, 0].tick_params(axis="x", rotation=45)
axes[0, 0].legend(title="Operation")
latency_data = (
df.groupby(["system_name", "operation"])["latency"].mean().unstack()
)
latency_data.plot(kind="bar", ax=axes[0, 1], width=0.8)
axes[0, 1].set_title("Average Latency by System and Operation")
axes[0, 1].set_ylabel("Latency (seconds)")
axes[0, 1].tick_params(axis="x", rotation=45)
axes[0, 1].legend(title="Operation")
memory_data = df.groupby(["system_name"])["memory_usage"].mean()
memory_data.plot(kind="bar", ax=axes[1, 0], color="skyblue", width=0.8)
axes[1, 0].set_title("Average Memory Usage by System")
axes[1, 0].set_ylabel("Memory Usage (bytes)")
axes[1, 0].tick_params(axis="x", rotation=45)
success_data = (
df.groupby(["system_name", "operation"])["success_rate"].mean().unstack()
)
success_data.plot(kind="bar", ax=axes[1, 1], width=0.8)
axes[1, 1].set_title("Success Rate by System and Operation")
axes[1, 1].set_ylabel("Success Rate")
axes[1, 1].tick_params(axis="x", rotation=45)
axes[1, 1].legend(title="Operation")
axes[1, 1].set_ylim(0, 1.1)
plt.tight_layout()
if save:
filename = (
f"performance_comparison_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
)
filepath = os.path.join(self.output_dir, filename)
plt.savefig(filepath, dpi=300, bbox_inches="tight")
print(f"๐Ÿ“Š Performance comparison chart saved to {filepath}")
return filepath
plt.show()
return ""
def plot_scalability_analysis(
self, scalability_data: Dict[str, List[Dict]], save: bool = True
) -> str:
fig, axes = plt.subplots(2, 2, figsize=(15, 12))
fig.suptitle(
"Memory Systems Scalability Analysis", fontsize=16, fontweight="bold"
)
all_data = []
for system_name, results in scalability_data.items():
for result in results:
all_data.append(
{
"system": system_name,
"size": result["dataset_size"],
"operation": result["operation"],
"time": result["execution_time"],
"throughput": result["throughput"],
"latency": result["latency"],
"memory": result["memory_usage"],
}
)
df = pd.DataFrame(all_data)
for system in df["system"].unique():
system_data = df[df["system"] == system]
store_data = system_data[system_data["operation"] == "store"]
retrieve_data = system_data[system_data["operation"] == "retrieve"]
axes[0, 0].plot(
store_data["size"],
store_data["time"],
marker="o",
label=f"{system} (store)",
linestyle="-",
)
axes[0, 0].plot(
retrieve_data["size"],
retrieve_data["time"],
marker="s",
label=f"{system} (retrieve)",
linestyle="--",
)
axes[0, 0].set_title("Execution Time vs Dataset Size")
axes[0, 0].set_xlabel("Dataset Size")
axes[0, 0].set_ylabel("Execution Time (seconds)")
axes[0, 0].legend()
axes[0, 0].grid(True, alpha=0.3)
for system in df["system"].unique():
system_data = df[df["system"] == system]
store_data = system_data[system_data["operation"] == "store"]
retrieve_data = system_data[system_data["operation"] == "retrieve"]
axes[0, 1].plot(
store_data["size"],
store_data["throughput"],
marker="o",
label=f"{system} (store)",
linestyle="-",
)
axes[0, 1].plot(
retrieve_data["size"],
retrieve_data["throughput"],
marker="s",
label=f"{system} (retrieve)",
linestyle="--",
)
axes[0, 1].set_title("Throughput vs Dataset Size")
axes[0, 1].set_xlabel("Dataset Size")
axes[0, 1].set_ylabel("Throughput (ops/sec)")
axes[0, 1].legend()
axes[0, 1].grid(True, alpha=0.3)
for system in df["system"].unique():
system_data = df[df["system"] == system]
axes[1, 0].plot(
system_data["size"], system_data["memory"], marker="o", label=system
)
axes[1, 0].set_title("Memory Usage vs Dataset Size")
axes[1, 0].set_xlabel("Dataset Size")
axes[1, 0].set_ylabel("Memory Usage (bytes)")
axes[1, 0].legend()
axes[1, 0].grid(True, alpha=0.3)
for system in df["system"].unique():
system_data = df[df["system"] == system]
store_data = system_data[system_data["operation"] == "store"]
retrieve_data = system_data[system_data["operation"] == "retrieve"]
axes[1, 1].plot(
store_data["size"],
store_data["latency"],
marker="o",
label=f"{system} (store)",
linestyle="-",
)
axes[1, 1].plot(
retrieve_data["size"],
retrieve_data["latency"],
marker="s",
label=f"{system} (retrieve)",
linestyle="--",
)
axes[1, 1].set_title("Latency vs Dataset Size")
axes[1, 1].set_xlabel("Dataset Size")
axes[1, 1].set_ylabel("Latency (seconds)")
axes[1, 1].legend()
axes[1, 1].grid(True, alpha=0.3)
plt.tight_layout()
if save:
filename = (
f"scalability_analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
)
filepath = os.path.join(self.output_dir, filename)
plt.savefig(filepath, dpi=300, bbox_inches="tight")
print(f"๐Ÿ“ˆ Scalability analysis chart saved to {filepath}")
return filepath
plt.show()
return ""
def plot_workload_pattern_analysis(
self, pattern_data: Dict[str, Dict[str, List[Dict]]], save: bool = True
) -> str:
fig, axes = plt.subplots(2, 2, figsize=(15, 12))
fig.suptitle("Workload Pattern Analysis", fontsize=16, fontweight="bold")
all_data = []
for system_name, patterns in pattern_data.items():
for pattern_name, results in patterns.items():
for result in results:
all_data.append(
{
"system": system_name,
"pattern": pattern_name,
"time": result["execution_time"],
"throughput": result["throughput"],
"latency": result["latency"],
}
)
df = pd.DataFrame(all_data)
pattern_time = df.groupby(["system", "pattern"])["time"].mean().unstack()
pattern_time.plot(kind="bar", ax=axes[0, 0], width=0.8)
axes[0, 0].set_title("Execution Time by Workload Pattern")
axes[0, 0].set_ylabel("Execution Time (seconds)")
axes[0, 0].tick_params(axis="x", rotation=45)
axes[0, 0].legend(title="Pattern")
pattern_throughput = (
df.groupby(["system", "pattern"])["throughput"].mean().unstack()
)
pattern_throughput.plot(kind="bar", ax=axes[0, 1], width=0.8)
axes[0, 1].set_title("Throughput by Workload Pattern")
axes[0, 1].set_ylabel("Throughput (ops/sec)")
axes[0, 1].tick_params(axis="x", rotation=45)
axes[0, 1].legend(title="Pattern")
pattern_latency = df.groupby(["system", "pattern"])["latency"].mean().unstack()
pattern_latency.plot(kind="bar", ax=axes[1, 0], width=0.8)
axes[1, 0].set_title("Latency by Workload Pattern")
axes[1, 0].set_ylabel("Latency (seconds)")
axes[1, 0].tick_params(axis="x", rotation=45)
axes[1, 0].legend(title="Pattern")
efficiency_data = (
df.groupby(["system", "pattern"])
.agg({"throughput": "mean", "latency": "mean"})
.reset_index()
)
efficiency_data["efficiency"] = (
efficiency_data["throughput"] / efficiency_data["latency"]
)
efficiency_pivot = efficiency_data.pivot(
index="system", columns="pattern", values="efficiency"
)
sns.heatmap(
efficiency_pivot, annot=True, fmt=".2f", ax=axes[1, 1], cmap="YlOrRd"
)
axes[1, 1].set_title("Pattern Efficiency Heatmap")
axes[1, 1].set_xlabel("Workload Pattern")
axes[1, 1].set_ylabel("Memory System")
plt.tight_layout()
if save:
filename = f"workload_pattern_analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
filepath = os.path.join(self.output_dir, filename)
plt.savefig(filepath, dpi=300, bbox_inches="tight")
print(f"๐ŸŽฏ Workload pattern analysis chart saved to {filepath}")
return filepath
plt.show()
return ""
def plot_memory_usage_breakdown(
self, memory_data: Dict[str, Dict], save: bool = True
) -> str:
fig, axes = plt.subplots(1, 2, figsize=(15, 6))
fig.suptitle("Memory Usage Analysis", fontsize=16, fontweight="bold")
systems = list(memory_data.keys())
usage_values = [memory_data[system]["total_usage"] for system in systems]
bars = axes[0].bar(systems, usage_values, color="lightcoral", alpha=0.7)
axes[0].set_title("Total Memory Usage by System")
axes[0].set_ylabel("Memory Usage (bytes)")
axes[0].tick_params(axis="x", rotation=45)
for bar, value in zip(bars, usage_values):
axes[0].text(
bar.get_x() + bar.get_width() / 2,
bar.get_height() + max(usage_values) * 0.01,
f"{value:,}",
ha="center",
va="bottom",
)
efficiency_values = [memory_data[system]["efficiency"] for system in systems]
bars = axes[1].bar(systems, efficiency_values, color="lightgreen", alpha=0.7)
axes[1].set_title("Memory Efficiency (Operations per Byte)")
axes[1].set_ylabel("Efficiency Score")
axes[1].tick_params(axis="x", rotation=45)
for bar, value in zip(bars, efficiency_values):
axes[1].text(
bar.get_x() + bar.get_width() / 2,
bar.get_height() + max(efficiency_values) * 0.01,
f"{value:.2f}",
ha="center",
va="bottom",
)
plt.tight_layout()
if save:
filename = (
f"memory_usage_breakdown_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
)
filepath = os.path.join(self.output_dir, filename)
plt.savefig(filepath, dpi=300, bbox_inches="tight")
print(f"๐Ÿ’พ Memory usage breakdown chart saved to {filepath}")
return filepath
plt.show()
return ""
def plot_performance_heatmap(
self, results_data: List[Dict], save: bool = True
) -> str:
df = pd.DataFrame(results_data)
throughput_pivot = df.pivot_table(
values="throughput",
index="system_name",
columns="operation",
aggfunc="mean",
)
fig, axes = plt.subplots(1, 2, figsize=(15, 6))
fig.suptitle("Performance Heatmaps", fontsize=16, fontweight="bold")
sns.heatmap(
throughput_pivot,
annot=True,
fmt=".2f",
ax=axes[0],
cmap="YlOrRd",
cbar_kws={"label": "Throughput (ops/sec)"},
)
axes[0].set_title("Throughput Heatmap")
axes[0].set_xlabel("Operation")
axes[0].set_ylabel("Memory System")
latency_pivot = df.pivot_table(
values="latency", index="system_name", columns="operation", aggfunc="mean"
)
sns.heatmap(
latency_pivot,
annot=True,
fmt=".6f",
ax=axes[1],
cmap="YlGnBu_r",
cbar_kws={"label": "Latency (seconds)"},
)
axes[1].set_title("Latency Heatmap")
axes[1].set_xlabel("Operation")
axes[1].set_ylabel("Memory System")
plt.tight_layout()
if save:
filename = (
f"performance_heatmap_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
)
filepath = os.path.join(self.output_dir, filename)
plt.savefig(filepath, dpi=300, bbox_inches="tight")
print(f"๐Ÿ”ฅ Performance heatmap saved to {filepath}")
return filepath
plt.show()
return ""
def plot_system_comparison_radar(
self, results_data: List[Dict], save: bool = True
) -> str:
df = pd.DataFrame(results_data)
systems = df["system_name"].unique()
metrics = ["throughput", "success_rate", "latency"]
normalized_data = {}
for system in systems:
system_data = df[df["system_name"] == system]
normalized_data[system] = {}
max_throughput = df["throughput"].max()
normalized_data[system]["throughput"] = (
system_data["throughput"].mean() / max_throughput
)
normalized_data[system]["success_rate"] = system_data["success_rate"].mean()
min_latency = df["latency"].min()
max_latency = df["latency"].max()
normalized_data[system]["latency"] = 1 - (
system_data["latency"].mean() - min_latency
) / (max_latency - min_latency)
fig, ax = plt.subplots(figsize=(10, 10), subplot_kw=dict(projection="polar"))
angles = np.linspace(0, 2 * np.pi, len(metrics), endpoint=False).tolist()
angles += angles[:1]
colors = plt.cm.Set3(np.linspace(0, 1, len(systems)))
for i, (system, color) in enumerate(zip(systems, colors)):
values = [normalized_data[system][metric] for metric in metrics]
values += values[:1]
ax.plot(angles, values, "o-", linewidth=2, label=system, color=color)
ax.fill(angles, values, alpha=0.25, color=color)
ax.set_xticks(angles[:-1])
ax.set_xticklabels(["Throughput", "Success Rate", "Latency"])
ax.set_ylim(0, 1)
ax.set_title(
"Memory Systems Performance Comparison\n(Radar Chart)",
size=16,
fontweight="bold",
pad=20,
)
ax.legend(loc="upper right", bbox_to_anchor=(1.3, 1.0))
ax.grid(True)
if save:
filename = f"system_comparison_radar_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
filepath = os.path.join(self.output_dir, filename)
plt.savefig(filepath, dpi=300, bbox_inches="tight")
print(f"๐ŸŽฏ System comparison radar chart saved to {filepath}")
return filepath
plt.show()
return ""
def create_comprehensive_report(
self,
results_data: List[Dict],
scalability_data: Dict[str, List[Dict]] = None,
pattern_data: Dict[str, Dict[str, List[Dict]]] = None,
memory_data: Dict[str, Dict] = None,
) -> str:
print("๐Ÿ“Š Creating comprehensive visualization report...")
generated_files = []
perf_file = self.plot_performance_comparison(results_data)
generated_files.append(perf_file)
heatmap_file = self.plot_performance_heatmap(results_data)
generated_files.append(heatmap_file)
radar_file = self.plot_system_comparison_radar(results_data)
generated_files.append(radar_file)
if scalability_data:
scal_file = self.plot_scalability_analysis(scalability_data)
generated_files.append(scal_file)
if pattern_data:
pattern_file = self.plot_workload_pattern_analysis(pattern_data)
generated_files.append(pattern_file)
if memory_data:
memory_file = self.plot_memory_usage_breakdown(memory_data)
generated_files.append(memory_file)
print(
f"โœ… Comprehensive report created with {len(generated_files)} visualizations"
)
return generated_files
def load_and_visualize_results(self, results_file: str) -> List[str]:
print(f"๐Ÿ“ Loading results from {results_file}")
with open(results_file, "r") as f:
results_data = json.load(f)
print(f"๐Ÿ“Š Loaded {len(results_data)} benchmark results")
generated_files = self.create_comprehensive_report(results_data)
return generated_files
def create_sample_visualizations():
print("๐ŸŽจ Creating sample visualizations...")
sample_data = [
{
"system_name": "Sequential Memory",
"operation": "store",
"dataset_size": 1000,
"execution_time": 0.05,
"throughput": 20000,
"latency": 0.000025,
"memory_usage": 1024000,
"success_rate": 1.0,
},
{
"system_name": "Sequential Memory",
"operation": "retrieve",
"dataset_size": 1000,
"execution_time": 0.08,
"throughput": 12500,
"latency": 0.00008,
"memory_usage": 1024000,
"success_rate": 1.0,
},
{
"system_name": "Associative Memory",
"operation": "store",
"dataset_size": 1000,
"execution_time": 0.02,
"throughput": 50000,
"latency": 0.00002,
"memory_usage": 2048000,
"success_rate": 1.0,
},
{
"system_name": "Associative Memory",
"operation": "retrieve",
"dataset_size": 1000,
"execution_time": 0.01,
"throughput": 100000,
"latency": 0.00001,
"memory_usage": 2048000,
"success_rate": 1.0,
},
{
"system_name": "Adaptive LRU Cache",
"operation": "store",
"dataset_size": 1000,
"execution_time": 0.015,
"throughput": 66667,
"latency": 0.000015,
"memory_usage": 1536000,
"success_rate": 0.95,
},
{
"system_name": "Adaptive LRU Cache",
"operation": "retrieve",
"dataset_size": 1000,
"execution_time": 0.008,
"throughput": 125000,
"latency": 0.000008,
"memory_usage": 1536000,
"success_rate": 0.95,
},
]
visualizer = MemoryVisualizer()
generated_files = visualizer.create_comprehensive_report(sample_data)
print(f"โœ… Sample visualizations created: {len(generated_files)} files")
return generated_files
if __name__ == "__main__":
files = create_sample_visualizations()
print("\n๐Ÿ“ Generated visualization files:")
for file in files:
print(f" ๐Ÿ“Š {file}")
print(f"\n๐Ÿ“‚ All visualizations saved to: visualizations/")

Xet Storage Details

Size:
20.9 kB
ยท
Xet hash:
4787bb3a85fc0f8f8de5a2d9ca03786d959bad628a44e8e06b67c88ade630a9f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.