def import_phy_grid(db, grid, conn, get_switch, get_switch_timing): write_cur = conn.cursor() tile_types = {} site_types = {} for tile in grid.tiles(): gridinfo = grid.gridinfo_at_tilename(tile) if gridinfo.tile_type not in tile_types: if gridinfo.tile_type in tile_types: continue import_tile_type(db, write_cur, tile_types, site_types, gridinfo.tile_type, get_switch) write_cur.connection.commit() build_tile_type_indicies(write_cur) write_cur.connection.commit() for tile_type in tile_types: add_wire_to_site_relation(db, write_cur, tile_types, site_types, tile_type, get_switch_timing) for tile in grid.tiles(): gridinfo = grid.gridinfo_at_tilename(tile) loc = grid.loc_of_tilename(tile) # tile: pkey name tile_type_pkey grid_x grid_y write_cur.execute( """ INSERT INTO phy_tile(name, tile_type_pkey, grid_x, grid_y) VALUES (?, ?, ?, ?)""", (tile, tile_types[gridinfo.tile_type], loc.grid_x, loc.grid_y)) build_other_indicies(write_cur) write_cur.connection.commit()
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()