From 5d514f59dd46984ce57ddd2c6398adbafc3a6928 Mon Sep 17 00:00:00 2001 From: Lorenzo Venerandi Date: Mon, 10 Mar 2025 23:00:38 +0100 Subject: [PATCH] updated plots --- plot_compared_metrics.py | 92 ++++++++++++++++++++++++++++++++++++++++ plot_metrics.py | 21 ++++++--- 2 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 plot_compared_metrics.py diff --git a/plot_compared_metrics.py b/plot_compared_metrics.py new file mode 100644 index 0000000..c586af3 --- /dev/null +++ b/plot_compared_metrics.py @@ -0,0 +1,92 @@ +import seaborn as sns +import matplotlib.pyplot as plt +import yaml +import pandas as pd +import numpy as np +import os + +# Function to read and parse a metric file +def read_metrics(file_path, label): + with open(file_path, 'r') as file: + data = yaml.safe_load(file) + runs = data['runs'] + + extracted_data = [] + for run in runs: + if 'build' in run: + extracted_data.append({'Task': run['n_task'], 'Type': 'Build Time', 'Time': float(run['build']['components_build_time']), 'Source': label}) + + if 'code_gen' in run: + extracted_data.append({'Task': run['n_task'], 'Type': 'Generation Time', 'Time': float(run['code_gen']['gen_time']), 'Source': label}) + + if 'deploy' in run: + extracted_data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time']), 'Source': label}) + + if 'time_total' in run: + extracted_data.append({'Task': run['n_task'], 'Type': 'Total Time', 'Time': float(run['time_total']), 'Source': label}) + + return extracted_data + +# Paths for the two metric files +file_path_1 = 'project/metrics.yaml' # First metrics file +file_path_2 = 'auga/metrics.yaml' # Second metrics file + +# Read and combine the data +data1 = read_metrics(file_path_1, 'Parallel') +data2 = read_metrics(file_path_2, 'Sequential') + +df = pd.DataFrame(data1 + data2) + +# Ensure benchmark directory exists +os.makedirs('benchmark', exist_ok=True) + +# Function to plot boxplot +def plot_boxplot(metric, filename): + subset = df[df['Type'] == metric] + plt.figure(figsize=(10, 6)) + sns.boxplot(x='Task', y='Time', hue='Source', data=subset, showfliers=False) + + plt.ylabel('Time (seconds)') + plt.grid(True, linestyle='--', alpha=0.7) + plt.legend(title='Source') + plt.tight_layout() + plt.savefig(f'benchmark/{filename}') + plt.close() + +# Function to plot line plot with confidence intervals +def plot_lineplot(metric, filename): + subset = df[df['Type'] == metric] + plt.figure(figsize=(10, 6)) + sns.lineplot(x='Task', y='Time', hue='Source', data=subset, errorbar=('ci', 95), linewidth=2, marker='o') + + plt.xlabel('Number of Tasks') + plt.ylabel('Time (seconds)') + plt.grid(True, linestyle='--', alpha=0.7) + plt.legend(title='Source') + plt.tight_layout() + plt.savefig(f'benchmark/{filename}') + plt.close() + +# Function to plot bar plot with confidence intervals +def plot_barplot(metric, filename): + subset = df[df['Type'] == metric] + plt.figure(figsize=(10, 6)) + sns.barplot(x='Task', y='Time', hue='Source', data=subset, errorbar=('ci', 95)) + + plt.ylabel('Time (seconds)') + plt.grid(True, linestyle='--', alpha=0.7) + plt.legend(title='Source') + plt.tight_layout() + plt.savefig(f'benchmark/{filename}') + plt.close() + +# Generate plots for each metric +metrics = ['Build Time', 'Generation Time', 'Deployment Time', 'Total Time'] +filenames = ['build_time', 'gen_time', 'deploy_time', 'total_time'] + +for metric, filename in zip(metrics, filenames): + #plot_boxplot(metric, f'{filename}_boxplot.png') + #plot_lineplot(metric, f'{filename}_lineplot.png') + plot_barplot(metric, f'{filename}_paired_barplot.png') + +print('Comparison plots saved successfully in "benchmark" directory!') diff --git a/plot_metrics.py b/plot_metrics.py index 02d1327..8d13763 100644 --- a/plot_metrics.py +++ b/plot_metrics.py @@ -12,7 +12,7 @@ def read_metrics(file_path): return data['runs'] # Read metrics from the file -file_path = 'project/metrics.yaml' # Replace with your file path +file_path = 'res/metrics-parallel.yaml' # Replace with your file path runs = read_metrics(file_path) # Flatten data into a list of dictionaries @@ -26,6 +26,9 @@ for run in runs: if 'deploy' in run: data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time'])}) + + if 'time_total' in run: + data.append({'Task': run['n_task'], 'Type': 'Total Time', 'Time': float(run['time_total'])}) # Convert to DataFrame df = pd.DataFrame(data) @@ -91,16 +94,20 @@ def plot_barplot(metric, filename, color): plt.close() # Plot each metric separately -plot_boxplot('Build Time', 'build_time_boxplot.png', 'skyblue') -plot_lineplot('Build Time', 'build_time_lineplot.png', 'skyblue') +#plot_boxplot('Build Time', 'build_time_boxplot.png', 'skyblue') +#plot_lineplot('Build Time', 'build_time_lineplot.png', 'skyblue') plot_barplot('Build Time', 'build_time_barplot.png', 'skyblue') -plot_boxplot('Generation Time', 'gen_time_boxplot.png', 'lightgreen') -plot_lineplot('Generation Time', 'gen_time_lineplot.png', 'lightgreen') +#plot_boxplot('Generation Time', 'gen_time_boxplot.png', 'lightgreen') +#plot_lineplot('Generation Time', 'gen_time_lineplot.png', 'lightgreen') plot_barplot('Generation Time', 'gen_time_barplot.png', 'lightgreen') -plot_boxplot('Deployment Time', 'deploy_time_boxplot.png', 'salmon') -plot_lineplot('Deployment Time', 'deploy_time_lineplot.png', 'salmon') +#plot_boxplot('Deployment Time', 'deploy_time_boxplot.png', 'salmon') +#plot_lineplot('Deployment Time', 'deploy_time_lineplot.png', 'salmon') plot_barplot('Deployment Time', 'deploy_time_barplot.png', 'salmon') +#plot_boxplot('Total Time', 'total_time_boxplot.png', 'purple') +#plot_lineplot('Total Time', 'total_time_lineplot.png', 'purple') +plot_barplot('Total Time', 'total_time_barplot.png', 'orange') + print('Plots saved successfully in "benchmark" directory!')