2018-09-19 23:49:15 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
import prjxray.db
|
|
|
|
|
import prjxray.lib
|
|
|
|
|
import argparse
|
|
|
|
|
import datetime
|
|
|
|
|
import progressbar
|
|
|
|
|
import multiprocessing
|
|
|
|
|
import pyjson5 as json5
|
|
|
|
|
import json
|
|
|
|
|
import sys
|
2020-01-15 16:55:12 +01:00
|
|
|
from prjxray import util
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
|
2018-09-19 23:49:15 +02:00
|
|
|
def full_wire_name(wire_in_grid):
|
2018-09-27 17:53:39 +02:00
|
|
|
return '{}/{}'.format(wire_in_grid.tile, wire_in_grid.wire)
|
|
|
|
|
|
2018-09-19 23:49:15 +02:00
|
|
|
|
|
|
|
|
def make_connection(wires, connection):
|
2018-09-27 17:53:39 +02:00
|
|
|
wire_a = full_wire_name(connection.wire_a)
|
|
|
|
|
wire_b = full_wire_name(connection.wire_b)
|
|
|
|
|
|
|
|
|
|
if wire_a not in wires:
|
|
|
|
|
wires[wire_a] = set((wire_a, ))
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
if wire_b not in wires:
|
|
|
|
|
wires[wire_b] = set((wire_b, ))
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
wire_a_set = wires[wire_a]
|
|
|
|
|
wire_b_set = wires[wire_b]
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
if wire_a_set is wire_b_set:
|
|
|
|
|
return
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
wire_a_set |= wire_b_set
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
for wire in wire_a_set:
|
|
|
|
|
wires[wire] = wire_a_set
|
2018-09-19 23:49:15 +02:00
|
|
|
|
|
|
|
|
|
2020-01-15 17:34:33 +01:00
|
|
|
def make_connections(db_root, part):
|
|
|
|
|
db = prjxray.db.Database(db_root, part)
|
2018-09-27 17:53:39 +02:00
|
|
|
c = db.connections()
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
wires = {}
|
|
|
|
|
for connection in c.get_connections():
|
|
|
|
|
make_connection(wires, connection)
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
nodes = {}
|
2018-09-19 23:49:15 +02:00
|
|
|
|
2018-09-27 17:53:39 +02:00
|
|
|
for wire_node in wires.values():
|
|
|
|
|
nodes[id(wire_node)] = wire_node
|
|
|
|
|
|
|
|
|
|
return nodes.values()
|
2018-09-19 23:49:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_json5(fname):
|
2018-09-27 17:53:39 +02:00
|
|
|
with open(fname, 'r') as f:
|
|
|
|
|
return json5.load(f)
|
|
|
|
|
|
2018-09-19 23:49:15 +02:00
|
|
|
|
|
|
|
|
def main():
|
2018-09-27 17:53:39 +02:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
description="Tests database against raw node list.")
|
2020-01-15 17:34:33 +01:00
|
|
|
|
2020-01-15 16:55:12 +01:00
|
|
|
util.db_root_arg(parser)
|
|
|
|
|
util.part_arg(parser)
|
2018-09-27 17:53:39 +02:00
|
|
|
parser.add_argument('--raw_node_root', required=True)
|
|
|
|
|
parser.add_argument('--error_nodes', default="error_nodes.json")
|
|
|
|
|
parser.add_argument('--ignored_wires')
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
processes = min(multiprocessing.cpu_count(), 10)
|
|
|
|
|
|
|
|
|
|
print('{} Running {} processes'.format(datetime.datetime.now(), processes))
|
|
|
|
|
pool = multiprocessing.Pool(processes=processes)
|
|
|
|
|
print(
|
|
|
|
|
'{} Reading raw data index'.format(datetime.datetime.now(), processes))
|
|
|
|
|
_, nodes = prjxray.lib.read_root_csv(args.raw_node_root)
|
|
|
|
|
print('{} Reading raw_node_data'.format(datetime.datetime.now()))
|
|
|
|
|
raw_node_data = []
|
|
|
|
|
with progressbar.ProgressBar(max_value=len(nodes)) as bar:
|
|
|
|
|
for idx, node in enumerate(pool.imap_unordered(
|
|
|
|
|
read_json5,
|
|
|
|
|
nodes,
|
|
|
|
|
chunksize=20,
|
|
|
|
|
)):
|
|
|
|
|
bar.update(idx)
|
|
|
|
|
raw_node_data.append(
|
|
|
|
|
(node['node'], tuple(wire['wire'] for wire in node['wires'])))
|
|
|
|
|
bar.update(idx + 1)
|
|
|
|
|
|
|
|
|
|
print('{} Creating connections'.format(datetime.datetime.now()))
|
2020-01-15 16:55:12 +01:00
|
|
|
generated_nodes = make_connections(args.db_root, args.part)
|
2018-09-27 17:53:39 +02:00
|
|
|
|
|
|
|
|
print('{} Verifying connections'.format(datetime.datetime.now()))
|
|
|
|
|
error_nodes = []
|
|
|
|
|
prjxray.lib.verify_nodes(raw_node_data, generated_nodes, error_nodes)
|
|
|
|
|
|
|
|
|
|
if len(error_nodes) > 0:
|
|
|
|
|
if args.ignored_wires:
|
|
|
|
|
with open(args.ignored_wires, 'r') as f:
|
|
|
|
|
ignored_wires = [l.strip() for l in f.readlines()]
|
|
|
|
|
|
|
|
|
|
print(
|
|
|
|
|
'{} Found {} errors, writing errors to {}'.format(
|
|
|
|
|
datetime.datetime.now(),
|
|
|
|
|
len(error_nodes),
|
|
|
|
|
args.error_nodes,
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
with open(args.error_nodes, 'w') as f:
|
|
|
|
|
json.dump(error_nodes, f, indent=2)
|
|
|
|
|
|
|
|
|
|
if not args.ignored_wires:
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
if not prjxray.lib.check_errors(error_nodes, ignored_wires):
|
|
|
|
|
print(
|
|
|
|
|
'{} Errors were not ignored via ignored_wires {}'.format(
|
|
|
|
|
datetime.datetime.now(),
|
|
|
|
|
args.ignored_wires,
|
|
|
|
|
))
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
else:
|
|
|
|
|
print(
|
|
|
|
|
'{} All errors were via ignored_wires {}'.format(
|
|
|
|
|
datetime.datetime.now(),
|
|
|
|
|
args.ignored_wires,
|
|
|
|
|
))
|
|
|
|
|
|
2018-09-19 23:49:15 +02:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-09-27 17:53:39 +02:00
|
|
|
main()
|