From 103a8902a8f246ad6aee0bb8491931bc6d5201e1 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Fri, 7 Mar 2025 17:01:52 +0100
Subject: [PATCH] benchs: add a plot.py script to make some figures from the
 csv files

---
 .gitlab-ci.yml      |  5 +++--
 scripts/database.sh |  5 +++++
 scripts/plot.py     | 52 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 scripts/plot.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 41bff133d..73c869b68 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -97,8 +97,8 @@ benchmark:
   artifacts:
     when: always
     paths:
-      - ./*.log
       - ./*.csv
+      - ./*.log
       - ./scripts/results/
 
 database:
@@ -113,8 +113,9 @@ database:
   artifacts:
     when: always
     paths:
-      - ./*.sqlite3
       - ./*.csv
+      - ./*.png
+      - ./*.sqlite3
       - ./scripts/results/
 
 pages:
diff --git a/scripts/database.sh b/scripts/database.sh
index f2e95b87a..53d5741ef 100755
--- a/scripts/database.sh
+++ b/scripts/database.sh
@@ -36,3 +36,8 @@ fi
 python3 ./scripts/add_result.py -e https://elasticsearch.bordeaux.inria.fr -t concace -p scalfmm -n accuracy scalfmm_accuracy.csv
 python3 ./scripts/add_result.py -e https://elasticsearch.bordeaux.inria.fr -t concace -p scalfmm -n timeseq scalfmm_timeseq.csv
 python3 ./scripts/add_result.py -e https://elasticsearch.bordeaux.inria.fr -t concace -p scalfmm -n timeomp scalfmm_timeomp.csv
+
+# plot some figures at this precise commit
+python3 ./scripts/plot.py -f scalfmm_accuracy.csv -n accuracy
+python3 ./scripts/plot.py -f scalfmm_timeseq.csv -n timeseq
+python3 ./scripts/plot.py -f scalfmm_timeomp.csv -n timeomp
diff --git a/scripts/plot.py b/scripts/plot.py
new file mode 100644
index 000000000..d56a62c9a
--- /dev/null
+++ b/scripts/plot.py
@@ -0,0 +1,52 @@
+import click
+import pandas as pd
+import matplotlib.pyplot as plt
+
+@click.command()
+@click.option("-f", "--file", required=True, help="input csv file")
+@click.option("-n", "--name", required=True, help="benchmark name")
+def main(
+    file: str,
+    name: str,
+):
+    """Generate figure from a csv file"""
+
+    df = pd.read_csv(file)
+
+    if name == "accuracy":
+        for (ndim, kernel_type, interp_type, tree_height), group in df.groupby(['ndim', 'kernel_type', 'interp_type', 'tree_height']):
+            x = group['interp_order']
+            y = group['error']
+            plt.plot(x, y, label=f"{ndim}-{kernel_type}-{interp_type}-{tree_height}")
+            plt.yscale('log')
+
+        plt.xlabel('Order')
+        plt.ylabel('Relative norm-2 error')
+        plt.title('Error vs. Order')
+        plt.legend()
+        plt.savefig('scalfmm_accuracy.png', bbox_inches='tight')
+    elif name == "timeseq":
+        for (ndim, kernel_type, interp_type, tree_height, interp_order), group in df.groupby(['ndim', 'kernel_type', 'interp_type', 'tree_height', 'interp_order']):
+            x = group['size']
+            y = group['timefull_avg']
+            plt.plot(x, y, label=f"{ndim}-{kernel_type}-{interp_type}-{tree_height}-{interp_order}")
+
+        plt.xlabel('Size')
+        plt.ylabel('Time (s)')
+        plt.title('Time vs. Size')
+        plt.legend()
+        plt.savefig('scalfmm_timeseq.png', bbox_inches='tight')
+    elif name == "timeomp":
+        for (ndim, kernel_type, interp_type, tree_height, interp_order, size, groupsize), group in df.groupby(['ndim', 'kernel_type', 'interp_type', 'tree_height', 'interp_order', 'size', 'groupsize']):
+            x = group['nthread']
+            y = group['timefull_avg']
+            plt.plot(x, y, label=f"{ndim}-{kernel_type}-{interp_type}-{tree_height}-{interp_order}-{size}-{groupsize}")
+
+        plt.xlabel('Number of threads')
+        plt.ylabel('Time (s)')
+        plt.title('Time vs. Number of threads')
+        plt.legend()
+        plt.savefig('scalfmm_timeomp.png', bbox_inches='tight')
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file
-- 
GitLab