def make_connections(db_root, part): db = prjxray.db.Database(db_root, part) c = db.connections() wires = {} for connection in c.get_connections(): make_connection(wires, connection) nodes = {} for wire_node in wires.values(): nodes[id(wire_node)] = wire_node return nodes.values()
def make_connections(db): # Some nodes are just 1 wire, so start by enumerating all wires. wires = {} grid = db.grid() for tile in progressbar.progressbar(grid.tiles()): gridinfo = grid.gridinfo_at_tilename(tile) tile_type = db.get_tile_type(gridinfo.tile_type) for wire in tile_type.get_wires(): key = (tile, wire) wires[key] = set((key, )) c = db.connections() for connection in progressbar.progressbar(c.get_connections()): make_connection(wires, connection) nodes = {} for wire_node in wires.values(): nodes[id(wire_node)] = wire_node return nodes.values()
def import_nodes(db, grid, conn): # Some nodes are just 1 wire, so start by enumerating all wires. cur = conn.cursor() write_cur = conn.cursor() write_cur.execute("""BEGIN EXCLUSIVE TRANSACTION;""") tile_wire_map = {} wires = {} for tile in progressbar.progressbar(grid.tiles()): gridinfo = grid.gridinfo_at_tilename(tile) tile_type = db.get_tile_type(gridinfo.tile_type) cur.execute( """SELECT pkey, tile_type_pkey FROM phy_tile WHERE name = ?;""", (tile, )) phy_tile_pkey, tile_type_pkey = cur.fetchone() for wire in tile_type.get_wires(): # pkey node_pkey tile_pkey wire_in_tile_pkey cur.execute( """ SELECT pkey FROM wire_in_tile WHERE name = ? and tile_type_pkey = ?;""", (wire, tile_type_pkey)) (wire_in_tile_pkey, ) = cur.fetchone() write_cur.execute( """ INSERT INTO wire(phy_tile_pkey, wire_in_tile_pkey) VALUES (?, ?);""", (phy_tile_pkey, wire_in_tile_pkey)) assert (tile, wire) not in tile_wire_map wire_pkey = write_cur.lastrowid tile_wire_map[(tile, wire)] = wire_pkey wires[wire_pkey] = None write_cur.execute("""COMMIT TRANSACTION;""") connections = db.connections() for connection in progressbar.progressbar(connections.get_connections()): a_pkey = tile_wire_map[(connection.wire_a.tile, connection.wire_a.wire)] b_pkey = tile_wire_map[(connection.wire_b.tile, connection.wire_b.wire)] a_node = wires[a_pkey] b_node = wires[b_pkey] if a_node is None: a_node = set((a_pkey, )) if b_node is None: b_node = set((b_pkey, )) if a_node is not b_node: a_node |= b_node for wire in a_node: wires[wire] = a_node nodes = {} for wire_pkey, node in wires.items(): if node is None: node = set((wire_pkey, )) assert wire_pkey in node nodes[id(node)] = node wires_assigned = set() for node in progressbar.progressbar(nodes.values()): write_cur.execute("""INSERT INTO node(number_pips) VALUES (0);""") node_pkey = write_cur.lastrowid for wire_pkey in node: wires_assigned.add(wire_pkey) write_cur.execute( """ UPDATE wire SET node_pkey = ? WHERE pkey = ? ;""", (node_pkey, wire_pkey)) assert len(set(wires.keys()) ^ wires_assigned) == 0 del tile_wire_map del nodes del wires write_cur.execute( "CREATE INDEX wire_in_tile_index ON wire(wire_in_tile_pkey);") write_cur.execute( "CREATE INDEX wire_index ON wire(phy_tile_pkey, wire_in_tile_pkey);") write_cur.execute("CREATE INDEX wire_node_index ON wire(node_pkey);") write_cur.connection.commit()