From 48b556c43aa27603f01591dcc0dfeda3eb35f384 Mon Sep 17 00:00:00 2001 From: Eren Dogan Date: Sat, 22 Jul 2023 14:07:27 -0700 Subject: [PATCH] Fix even more DRC errors in graph router --- compiler/router/graph.py | 14 +++++++------- compiler/router/graph_router.py | 3 ++- compiler/router/graph_shape.py | 22 ++++++++++++++++++++-- compiler/router/graph_utils.py | 17 +++++------------ 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/compiler/router/graph.py b/compiler/router/graph.py index 16f3954f..d0c43d6d 100644 --- a/compiler/router/graph.py +++ b/compiler/router/graph.py @@ -12,7 +12,7 @@ from openram.tech import drc from .direction import direction from .graph_node import graph_node from .graph_probe import graph_probe -from .graph_utils import * +from .graph_utils import snap class graph: @@ -80,12 +80,12 @@ class graph: offset = self.router.offset p = node.center lengths = [blockage.width(), blockage.height()] - centers = snap_to_grid(blockage.center()) + centers = blockage.center() ll, ur = blockage.rect safe = [True, True] for i in range(2): if lengths[i] >= offset * 2: - min_diff = snap_offset_to_grid(min(abs(ll[i] - p[i]), abs(ur[i] - p[i]))) + min_diff = snap(min(abs(ll[i] - p[i]), abs(ur[i] - p[i]))) if min_diff < offset: safe[i] = False elif centers[i] != p[i]: @@ -104,7 +104,7 @@ class graph: for via in self.graph_vias: ll, ur = via.rect - center = snap_to_grid(via.center()) + center = via.center() if via.on_segment(ll, point, ur) and \ (center.x != point.x or center.y != point.y): return True @@ -180,7 +180,7 @@ class graph: else: # Square-like pin points = [shape.center()] for p in points: - p = snap_to_grid(p) + p = snap(p) x_values.add(p.x) y_values.add(p.y) @@ -188,8 +188,8 @@ class graph: offset = vector(drc["grid"], drc["grid"]) for blockage in self.graph_blockages: ll, ur = blockage.rect - nll = snap_to_grid(ll - offset) - nur = snap_to_grid(ur + offset) + nll = snap(ll - offset) + nur = snap(ur + offset) # Add minimum offset to the blockage corner nodes to prevent overlap x_values.update([nll.x, nur.x]) y_values.update([nll.y, nur.y]) diff --git a/compiler/router/graph_router.py b/compiler/router/graph_router.py index 8c5a4164..d01d9f0c 100644 --- a/compiler/router/graph_router.py +++ b/compiler/router/graph_router.py @@ -13,6 +13,7 @@ from openram import OPTS from .router_tech import router_tech from .graph import graph from .graph_shape import graph_shape +from .graph_utils import snap class graph_router(router_tech): @@ -51,7 +52,7 @@ class graph_router(router_tech): self.fake_pins = [] # Set the offset here - self.offset = self.layer_widths[0] / 2 + self.offset = snap(self.layer_widths[0] / 2) def route(self, vdd_name="vdd", gnd_name="gnd"): diff --git a/compiler/router/graph_shape.py b/compiler/router/graph_shape.py index 8801a974..2405d11f 100644 --- a/compiler/router/graph_shape.py +++ b/compiler/router/graph_shape.py @@ -6,7 +6,7 @@ from openram.base.pin_layout import pin_layout from openram.base.vector import vector from openram.tech import drc -from .graph_utils import snap_to_grid +from .graph_utils import snap class graph_shape(pin_layout): @@ -21,10 +21,28 @@ class graph_shape(pin_layout): # Snap the shape to the grid here ll, ur = self.rect - self.rect = [snap_to_grid(ll), snap_to_grid(ur)] + self.rect = [snap(ll), snap(ur)] self.inflated_from = inflated_from + def center(self): + """ Override the default `center` behavior. """ + + return snap(super().center()) + + + def height(self): + """ Override the default `height` behavior. """ + + return snap(super().height()) + + + def width(self): + """ Override the default `width` behavior. """ + + return snap(super().width()) + + def get_inflated_from(self): """ Return `self` if `self.inflated_from` is None. Otherwise, return diff --git a/compiler/router/graph_utils.py b/compiler/router/graph_utils.py index a8b491a5..4fa9a301 100644 --- a/compiler/router/graph_utils.py +++ b/compiler/router/graph_utils.py @@ -10,16 +10,9 @@ from openram.base import vector from openram.tech import drc -def snap_to_grid(v): - """ Use custom `snap_to_grid` since `vector.snap_to_grid` isn't working. """ +def snap(a): + """ Use custom `snap` since `vector.snap_to_grid` isn't working. """ - return vector(snap_offset_to_grid(v.x), snap_offset_to_grid(v.y)) - - -def snap_offset_to_grid(offset): - """ - Use custom `snap_offset_to_grid` since `vector.snap_offset_to_grid` isn't - working. - """ - - return round(offset, len(str(drc["grid"]).split('.')[1])) + if isinstance(a, vector): + return vector(snap(a.x), snap(a.y)) + return round(a, len(str(drc["grid"]).split('.')[1]))