File: plot_congestion_by_wiretype.py

package info (click to toggle)
nextpnr 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 45,032 kB
  • sloc: cpp: 218,128; python: 24,276; ansic: 10,907; pascal: 1,328; sh: 849; makefile: 563; vhdl: 44; objc: 42; tcl: 41
file content (56 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download
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
import csv
import sys

import matplotlib.pyplot as plt

data = {}
max_bars = {}

file = 1
try:
    while True:
        print("{}/heatmap_congestion_by_wiretype_{}.csv".format(sys.argv[1], file))
        with open("{}/heatmap_congestion_by_wiretype_{}.csv".format(sys.argv[1], file)) as f:
            reader = csv.reader(f, delimiter=',')
            for row in [x for x in reader][1:]:
                key = row[0]
                values = [float(x) for x in row[1:] if x != '']
                # Ignore wires without overuse
                values[0] = 0
                values[1] = 0
                if key not in data:
                    data[key] = []
                    max_bars[key] = 0
                data[key].append(values)
                max_bars[key] = max(max_bars[key], len(values))
            file += 1
except FileNotFoundError:
    pass
finally:
    file -= 1

to_remove = []
for key in data.keys():
    if sum([sum(values) for values in data[key]]) == 0:
        # Prune entries that never have any overuse to attempt to reduce visual clutter
        to_remove.append(key)
    else:
        # Pad entries as needed
        for values in data[key]:
            while len(values) < max_bars[key]:
                values.append(0)
for key in to_remove:
    del data[key]

COLS = 2
for i in range(file):
    plt.suptitle("heatmap for iteration {}".format(i))
    fig, axs = plt.subplots((len(data.keys())+(COLS-1))//COLS, COLS)
    for j, key in enumerate(data.keys()):
        if sum(data[key][i]) > 0:
            axs[j//COLS, j%COLS].bar([x for x in range(len(data[key][i]))], data[key][i])
            axs[j//COLS, j%COLS].set_title(key)
        else:
            axs[j//COLS, j%COLS].set_axis_off()
    plt.savefig("{}/heatmap_congestion_by_wiretype_{:03}.png".format(sys.argv[1], i), dpi=300)
    plt.close()