forked from qdrant/vector-db-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchart.py
178 lines (155 loc) · 5.2 KB
/
chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import json
import os
import matplotlib.pyplot as plt
import argparse
x_metrics = {"mean_precisions": {"human_label": "Precision"}}
y_metrics = {
"rps": {"mode": "higher-better", "human_label": "Search Queries per second"},
"mean_time": {
"mode": "lower-better",
"human_label": "Search avg. latency including RTT (seconds)",
},
"p50_time": {
"mode": "lower-better",
"human_label": "Search p50 latency including RTT (seconds)",
},
"p99_time": {
"mode": "lower-better",
"human_label": "Search p99 latency including RTT (seconds)",
},
}
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--dataset", default="glove-100-angular")
parser.add_argument("-o", "--output", default=None)
parser.add_argument(
"-x",
"--x-axis",
help="Which metric to use on the X-axis",
choices=x_metrics.keys(),
default="mean_precisions",
)
parser.add_argument(
"--x-axis-left",
default=None,
)
parser.add_argument(
"--x-axis-right",
default=None,
)
parser.add_argument(
"--x-axis-label",
default=None,
)
parser.add_argument(
"-y",
"--y-axis",
help="Which metric to use on the Y-axis",
choices=y_metrics.keys(),
default="rps",
)
parser.add_argument(
"--y-axis-label",
default=None,
)
parser.add_argument(
"--y-axis-bottom",
default=None,
)
parser.add_argument(
"--y-axis-top",
default=None,
)
parser.add_argument(
"--legend",
default="Redis",
)
parser.add_argument(
"--results", type=str, help="results folder to process", default="results"
)
parser.add_argument(
"--clients", type=int, help="consider results from this client count", default=1
)
args = parser.parse_args()
final_results_map = {}
x_axis = []
y_axis = []
fig, ax = plt.subplots()
if os.path.exists(args.results):
print(f"working on dir: {args.results}")
print("reading first the upload data")
for filename in os.listdir(args.results):
f = os.path.join(args.results, filename)
setup_name = filename.split(args.dataset)[0]
setup_name = setup_name[0 : len(setup_name) - 1]
with open(f, "r") as fd:
try:
json_res = json.load(fd)
except json.decoder.JSONDecodeError as e:
error_str = e.__str__()
print(
f"skipping {filename} given here as an error while processing the file {error_str})"
)
continue
parallel = 1
if "parallel" in json_res["params"]:
parallel = json_res["params"]["parallel"]
if args.clients != parallel:
print(
f"skipping {filename} given the client count ({parallel}) is different than the one we wish to plot ({args.clients})"
)
continue
# query
if (
args.x_axis in json_res["results"]
and args.y_axis in json_res["results"]
):
x_val = json_res["results"][args.x_axis]
y_val = json_res["results"][args.y_axis]
x_axis.append(x_val)
y_axis.append(y_val)
color = "tab:red"
ax.scatter(
x_axis, y_axis, c=color, label=args.legend, marker="^", edgecolors="none"
)
ax.legend()
ax.grid(True)
x_axis_label = args.x_axis
if args.x_axis in x_metrics:
if "human_label" in x_metrics[args.x_axis]:
x_axis_label = x_metrics[args.x_axis]["human_label"]
if args.x_axis_label is not None:
x_axis_label = args.x_axis_label
plt.xlabel(x_axis_label)
y_axis_label = args.y_axis
y_axis_mode = "higher-better"
if args.y_axis in y_metrics:
if "human_label" in y_metrics[args.y_axis]:
y_axis_label = y_metrics[args.y_axis]["human_label"]
if "mode" in y_metrics[args.y_axis]:
y_axis_mode = y_metrics[args.y_axis]["mode"]
if args.y_axis_label is not None:
y_axis_label = args.y_axis_label
plt.ylabel(y_axis_label)
title_string = (
f"{x_axis_label} vs {y_axis_label} ({y_axis_mode}).\nclients={args.clients}"
)
plt.title(title_string)
x_axis_left, x_axis_right = plt.xlim()
_, y_axis_top = plt.ylim()
y_axis_bottom = 0
if args.y_axis_bottom is not None:
y_axis_bottom = float(args.y_axis_bottom)
if args.y_axis_top is not None:
y_axis_top = float(args.y_axis_top)
plt.ylim(y_axis_bottom, y_axis_top)
if args.x_axis_left is not None:
x_axis_left = float(args.x_axis_left)
if args.x_axis_right is not None:
x_axis_right = float(args.x_axis_right)
plt.xlim(x_axis_left, x_axis_right)
output_file = f"{args.y_axis}.png"
if args.output is not None:
output_file = args.output
print(f"writing output to {output_file}")
plt.savefig(output_file)