Added graph creation and functions in base class and lower level modules.

This commit is contained in:
Hunter Nichols
2019-04-24 14:23:22 -07:00
parent 4f28295e20
commit e292767166
23 changed files with 196 additions and 10 deletions
-66
View File
@@ -1,66 +0,0 @@
import os
from collections import defaultdict
import gdsMill
import tech
import math
import globals
import debug
from vector import vector
from pin_layout import pin_layout
class graph():
"""Implements a directed graph"""
def __init__(self):
self.graph = defaultdict(list)
def add_edge(self, u, v):
"""Adds edge to graph. Nodes added as well if they do not exist."""
if v not in self.graph[u]:
self.graph[u].append(v)
def add_node(self, u):
"""Add node to graph with no edges"""
if not u in self.graph:
self.graph[u] = []
def remove_edges(self, node):
"""Helper function to remove edges, useful for removing vdd/gnd"""
self.graph[node] = []
def printAllPaths(self,s, d):
# Mark all the vertices as not visited
visited = set()
# Create an array to store paths
path = []
# Call the recursive helper function to print all paths
self.printAllPathsUtil(s, d,visited, path)
def printAllPathsUtil(self, u, d, visited, path):
# Mark the current node as visited and store in path
visited.add(u)
path.append(u)
# If current vertex is same as destination, then print
# current path[]
if u == d:
debug.info(1,"{}".format(path))
else:
# If current vertex is not destination
#Recur for all the vertices adjacent to this vertex
for i in self.graph[u]:
if i not in visited:
self.printAllPathsUtil(i, d, visited, path)
# Remove current vertex from path[] and mark it as unvisited
path.pop()
visited.remove(u)
def __str__(self):
""" override print function output """
return "Nodes: {}\nEdges:{} ".format(list(self.graph), self.graph)
+10 -3
View File
@@ -24,7 +24,7 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
self.name = name
hierarchy_layout.layout.__init__(self, name)
hierarchy_spice.spice.__init__(self, name)
self.init_graph_params()
def get_layout_pins(self,inst):
""" Return a map of pin locations of the instance offset """
@@ -100,6 +100,7 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
os.remove(tempgds)
#Example graph run
# import graph_util
# graph = graph_util.graph()
# pins = ['A','Z','vdd','gnd']
# d.build_graph(graph,"Xpdriver",pins)
@@ -108,6 +109,11 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
# debug.info(1,"{}".format(graph))
# graph.printAllPaths('A', 'Z')
def init_graph_params(self):
"""Initializes parameters relevant to the graph creation"""
#Only initializes a set for checking instances which should not be added
self.graph_inst_exclude = set()
def build_graph(self, graph, inst_name, port_nets):
"""Recursively create graph from instances in module."""
@@ -115,9 +121,10 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
if len(port_nets) != len(self.pins):
debug.error("Port length mismatch:\nExt nets={}, Ports={}".format(port_nets,self.pins),1)
port_dict = {i:j for i,j in zip(self.pins, port_nets)}
debug.info(1, "Instance name={}".format(inst_name))
debug.info(3, "Instance name={}".format(inst_name))
for subinst, conns in zip(self.insts, self.conns):
debug.info(1, "Sub-Instance={}".format(subinst))
if subinst in self.graph_inst_exclude:
continue
subinst_name = inst_name+'.X'+subinst.name
subinst_ports = self.translate_nets(conns, port_dict, inst_name)
subinst.mod.build_graph(graph, subinst_name, subinst_ports)