From 0658cc20e64a0757fc60e96c49f3be85eac1675b Mon Sep 17 00:00:00 2001 From: Bin wu Date: Thu, 17 Nov 2016 17:12:48 -0800 Subject: [PATCH 1/2] move snapt_to_grid to a function in vector class --- compiler/geometry.py | 18 ++++++++---------- compiler/hierarchy_layout.py | 7 ++----- compiler/path.py | 1 - compiler/utils.py | 17 ----------------- compiler/vector.py | 19 +++++++++++++++---- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/compiler/geometry.py b/compiler/geometry.py index 1585e4a4..eee982d5 100644 --- a/compiler/geometry.py +++ b/compiler/geometry.py @@ -1,10 +1,9 @@ """ This provides a set of useful generic types for the gdsMill interface. """ - import tech import debug -from utils import snap_to_grid +from vector import vector class geometry: """ @@ -37,7 +36,7 @@ class instance(geometry): self.mod = mod self.gds = mod.gds self.rotate = rotate - self.offset = snap_to_grid(offset) + self.offset = vector(offset) self.mirror = mirror @@ -71,7 +70,7 @@ class path(geometry): self.name = "path" self.layerNumber = layerNumber self.coordinates = map(lambda x: [x[0], x[1]], coordinates) - self.coordinates = snap_to_grid(self.coordinates) + self.coordinates = vector(self.coordinates) self.path_width = path_width # FIXME figure out the width/height. This type of path is not @@ -104,7 +103,7 @@ class label(geometry): self.name = "label" self.text = text self.layerNumber = layerNumber - self.offset = snap_to_grid(offset) + self.offset = vector(offset) self.zoom = zoom self.size = 0 @@ -134,19 +133,18 @@ class rectangle(geometry): geometry.__init__(self) self.name = "rect" self.layerNumber = layerNumber - self.offset = snap_to_grid(offset) - self.size = snap_to_grid([width, height]) + self.offset = vector(offset) + self.size = vector([width, height]) self.width = self.size[0] self.height = self.size[1] def gds_write_file(self, newLayout): """Writes the rectangular shape to GDS""" - snapped_offset=snap_to_grid(self.offset) debug.info(3, "writing rectangle (" + str(self.layerNumber) + "):" - + str(self.width) + "x" + str(self.height) + " @ " + str(snapped_offset)) + + str(self.width) + "x" + str(self.height) + " @ " + str(self.offset)) newLayout.addBox(layerNumber=self.layerNumber, purposeNumber=0, - offsetInMicrons=snapped_offset, + offsetInMicrons=self.offset, width=self.width, height=self.height, center=False) diff --git a/compiler/hierarchy_layout.py b/compiler/hierarchy_layout.py index 420df8cd..bd6d4685 100644 --- a/compiler/hierarchy_layout.py +++ b/compiler/hierarchy_layout.py @@ -5,7 +5,6 @@ import debug from tech import drc, GDS from tech import layer as techlayer import os -from utils import snap_to_grid from vector import vector class layout: @@ -99,11 +98,9 @@ class layout: """Translates all 2d cartesian coordinates in a layout given the (x,y) offset""" for obj in self.objs: - obj.offset = snap_to_grid([obj.offset[0] - coordinate.x, - obj.offset[1] - coordinate.y]) + obj.offset = obj.offset - coordinate for inst in self.insts: - inst.offset = snap_to_grid([inst.offset[0] - coordinate.x, - inst.offset[1] - coordinate.y]) + inst.offset = inst.offset - coordinate # FIXME: Make name optional and pick a random one if not specified def add_inst(self, name, mod, offset=[0,0], mirror="R0",rotate=0): diff --git a/compiler/path.py b/compiler/path.py index 57409f50..5e88eb40 100644 --- a/compiler/path.py +++ b/compiler/path.py @@ -3,7 +3,6 @@ from tech import layer as techlayer import debug import design from vector import vector -from utils import snap_to_grid class path(design.design): """ diff --git a/compiler/utils.py b/compiler/utils.py index 4f00563a..0ba5a5b8 100644 --- a/compiler/utils.py +++ b/compiler/utils.py @@ -5,27 +5,10 @@ import globals OPTS = globals.OPTS -def snap_to_grid(offset): - """ - Changes the coodrinate to match the grid settings - """ - grid = tech.drc["grid"] - x = offset[0] - y = offset[1] - # this gets the nearest integer value - xgrid = int(round(round((x / grid), 2), 0)) - ygrid = int(round(round((y / grid), 2), 0)) - xoff = xgrid * grid - yoff = ygrid * grid - out_offset = [xoff, yoff] - return out_offset - - def gdsPinToOffset(gdsPin): boundary = gdsPin[2] return [0.5 * (boundary[0] + boundary[2]), 0.5 * (boundary[1] + boundary[3])] - def auto_measure_libcell(pin_list, name, units, layer): cell_gds = OPTS.openram_tech + "gds_lib/" + str(name) + ".gds" cell_vlsi = gdsMill.VlsiLayout(units=units) diff --git a/compiler/vector.py b/compiler/vector.py index b780f69a..41180e10 100644 --- a/compiler/vector.py +++ b/compiler/vector.py @@ -1,4 +1,5 @@ import debug +import tech class vector(): @@ -14,12 +15,12 @@ class vector(): """ init function support two init method""" # will take single input as a coordinate if y==None: - self.x = x[0] - self.y = x[1] + self.x = self.snap_to_grid(x[0]) + self.y = self.snap_to_grid(x[1]) #will take two inputs as the values of a coordinate else: - self.x = x - self.y = y + self.x = self.snap_to_grid(x) + self.y = self.snap_to_grid(y) def __str__(self): """ override print function output """ @@ -92,3 +93,13 @@ class vector(): y_factor=x_factor[1] x_factor=x_factor[0] return vector(self.x*x_factor,self.y*y_factor) + + def snap_to_grid(self, offset): + """ + Changes the coodrinate to match the grid settings + """ + grid = tech.drc["grid"] + # this gets the nearest integer value + off_in_grid = int(round(round((offset / grid), 2), 0)) + offset = off_in_grid * grid + return offset From 8c4b97753a8cf884700a7777fc502f05a0447538 Mon Sep 17 00:00:00 2001 From: Bin wu Date: Sun, 20 Nov 2016 11:06:53 -0800 Subject: [PATCH 2/2] not applying snap_to_grid to all vectors --- compiler/geometry.py | 14 +++++++------- compiler/vector.py | 15 ++++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/compiler/geometry.py b/compiler/geometry.py index eee982d5..9dc96401 100644 --- a/compiler/geometry.py +++ b/compiler/geometry.py @@ -36,7 +36,7 @@ class instance(geometry): self.mod = mod self.gds = mod.gds self.rotate = rotate - self.offset = vector(offset) + self.offset = vector(offset).snap_to_grid() self.mirror = mirror @@ -70,7 +70,7 @@ class path(geometry): self.name = "path" self.layerNumber = layerNumber self.coordinates = map(lambda x: [x[0], x[1]], coordinates) - self.coordinates = vector(self.coordinates) + self.coordinates = vector(self.coordinates).snap_to_grid() self.path_width = path_width # FIXME figure out the width/height. This type of path is not @@ -103,7 +103,7 @@ class label(geometry): self.name = "label" self.text = text self.layerNumber = layerNumber - self.offset = vector(offset) + self.offset = vector(offset).snap_to_grid() self.zoom = zoom self.size = 0 @@ -133,10 +133,10 @@ class rectangle(geometry): geometry.__init__(self) self.name = "rect" self.layerNumber = layerNumber - self.offset = vector(offset) - self.size = vector([width, height]) - self.width = self.size[0] - self.height = self.size[1] + self.offset = vector(offset).snap_to_grid() + self.size = vector(width, height).snap_to_grid() + self.width = self.size.x + self.height = self.size.y def gds_write_file(self, newLayout): """Writes the rectangular shape to GDS""" diff --git a/compiler/vector.py b/compiler/vector.py index b5273252..3df9af35 100644 --- a/compiler/vector.py +++ b/compiler/vector.py @@ -15,12 +15,12 @@ class vector(): """ init function support two init method""" # will take single input as a coordinate if y==None: - self.x = self.snap_to_grid(x[0]) - self.y = self.snap_to_grid(x[1]) + self.x = x[0] + self.y = x[1] #will take two inputs as the values of a coordinate else: - self.x = self.snap_to_grid(x) - self.y = self.snap_to_grid(y) + self.x = x + self.y = y def __str__(self): """ override print function output """ @@ -83,7 +83,12 @@ class vector(): """ return vector(other[0]- self.x, other[1] - self.y) - def snap_to_grid(self, offset): + def snap_to_grid(self): + self.x = self.snap_offset_to_grid(self.x) + self.y = self.snap_offset_to_grid(self.y) + return self + + def snap_offset_to_grid(self, offset): """ Changes the coodrinate to match the grid settings """