compareDEVS.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python3
  2. """
  3. Compares DEVStone benchmark results from multiple DEVS variants
  4. (Classic, Parallel, Dynamic Structure, etc.).
  5. Each CSV must contain:
  6. model_type, depth, width, run, creation_time, setup_time, simulation_time
  7. Produces:
  8. - Plots of scalability (depth/width)
  9. - Overhead composition
  10. - Speedup ratios
  11. - A summary CSV table with average speedups
  12. """
  13. import pandas as pd
  14. import matplotlib.pyplot as plt
  15. import seaborn as sns
  16. from pathlib import Path
  17. # === CONFIGURATION ===
  18. FILES = {
  19. # "Classic": "./Results-PyPDEVS/DEVSTONE-classic.csv",
  20. "Parallel": "./Results-PyPDEVS/DEVSTONE.csv",
  21. # "Minimal": "./Results-PyPDEVS/DEVSTONE-minimal.csv",
  22. "Dynamic Structure": "./Results-PyPDEVS/DEVSTONE-dynamic.csv",
  23. # "DS-C": "./Results-PyPDEVS/DEVSTONE-classic-dynamic.csv",
  24. }
  25. OUTPUT_DIR = Path("./Results-PyPDEVS")
  26. OUTPUT_DIR.mkdir(exist_ok=True)
  27. # === LOAD & MERGE ===
  28. dfs = []
  29. for variant, path in FILES.items():
  30. df = pd.read_csv(path)
  31. df["variant"] = variant
  32. dfs.append(df)
  33. data = pd.concat(dfs, ignore_index=True)
  34. # === PROCESSING ===
  35. data["total_time"] = data["creation_time"] + data["setup_time"] + data["simulation_time"]
  36. agg = (
  37. data.groupby(["variant", "model_type", "depth", "width"], as_index=False)
  38. .agg({
  39. "creation_time": ["mean", "std"],
  40. "setup_time": ["mean", "std"],
  41. "simulation_time": ["mean", "std"],
  42. "total_time": ["mean", "std"]
  43. })
  44. )
  45. # Flatten multi-level columns
  46. agg.columns = ["_".join(col).rstrip("_") for col in agg.columns.values]
  47. sns.set_theme(style="whitegrid", font_scale=1.2)
  48. # === Scalability with Width ===
  49. for model in agg["model_type"].unique():
  50. subset = agg[agg["model_type"] == model]
  51. plt.figure(figsize=(7, 5))
  52. sns.lineplot(data=subset, x="width", y="simulation_time_mean", hue="variant", marker="o")
  53. plt.title(f"Scalability with Width – {model}")
  54. plt.xlabel("Width (# submodels per level)")
  55. plt.ylabel("Simulation time (s)")
  56. plt.tight_layout()
  57. plt.savefig(OUTPUT_DIR / f"scalability_width_{model}.png")
  58. plt.close()
  59. # === Scalability with Depth ===
  60. for model in agg["model_type"].unique():
  61. subset = agg[agg["model_type"] == model]
  62. plt.figure(figsize=(7, 5))
  63. sns.lineplot(data=subset, x="depth", y="simulation_time_mean", hue="variant", marker="o")
  64. plt.title(f"Scalability with Depth – {model}")
  65. plt.xlabel("Depth (levels)")
  66. plt.ylabel("Simulation time (s)")
  67. plt.tight_layout()
  68. plt.savefig(OUTPUT_DIR / f"scalability_depth_{model}.png")
  69. plt.close()
  70. # === Overhead Composition ===
  71. comp = data.melt(
  72. id_vars=["variant", "model_type", "depth", "width"],
  73. value_vars=["creation_time", "setup_time", "simulation_time"],
  74. var_name="phase",
  75. value_name="time"
  76. )
  77. plt.figure(figsize=(9, 6))
  78. sns.barplot(data=comp, x="variant", y="time", hue="phase", estimator="mean", errorbar="sd")
  79. plt.title("Average Overhead Composition by Variant")
  80. plt.ylabel("Mean time (s)")
  81. plt.tight_layout()
  82. plt.savefig(OUTPUT_DIR / "overhead_composition.png")
  83. plt.close()
  84. print(f"\nAnalysis complete. Plots and summary saved in: {OUTPUT_DIR}/")