示例#1
0
def test_extract():
    c = [gdspy.Cell('tree_' + unique(), True) for _ in range(8)]
    gdspy.current_library = gdspy.GdsLibrary()
    lib = gdspy.GdsLibrary()
    lib.add(c)
    c[0].add(gdspy.CellReference(c[1]))
    c[0].add(gdspy.CellReference(c[3]))
    c[1].add(gdspy.CellReference(c[2]))
    c[1].add(gdspy.CellArray(c[2], 2, 1, (0, 0)))
    c[1].add(gdspy.CellArray(c[3], 2, 1, (0, 0)))
    c[4].add(gdspy.CellReference(c[3]))
    c[6].add(gdspy.CellArray(c[5], 2, 1, (0, 0)))
    assert len(gdspy.current_library.cell_dict) == 0

    lib.extract(c[7])
    assert gdspy.current_library.cell_dict == {c[7].name: c[7]}

    lib.extract(c[1])
    assert gdspy.current_library.cell_dict == {
        c[7].name: c[7],
        c[1].name: c[1],
        c[2].name: c[2],
        c[3].name: c[3]
    }

    lib.extract(c[0])
    assert gdspy.current_library.cell_dict == {
        c[7].name: c[7],
        c[0].name: c[0],
        c[1].name: c[1],
        c[2].name: c[2],
        c[3].name: c[3]
    }
示例#2
0
def test_robustpath_togds(tmpdir):
    cell = gdspy.Cell('robustpath')
    rp = gdspy.RobustPath((0, 0), 0.1, layer=[1])
    rp.segment((1, 1))
    rp.segment((2, 3), 0)
    cell.add(rp)
    rp = gdspy.RobustPath((2, 0), [0.1, 0.2],
                          0.2,
                          ends=['round', (0.2, 0.1)],
                          layer=4,
                          datatype=[1, 1],
                          gdsii_path=True)
    rp.segment((3, 1))
    cell.add(rp)
    rp = gdspy.RobustPath((0, 0),
                          0.1,
                          layer=5,
                          tolerance=1e-5,
                          max_points=0,
                          max_evals=1e6,
                          gdsii_path=True)
    rp.segment((10, 0))
    rp.turn(20, 'll')
    rp.turn(20, 'rr')
    rp.turn(20, 'll')
    cell.add(rp)
    fname = str(tmpdir.join('test.gds'))
    with pytest.warns(UserWarning):
        gdspy.write_gds(fname, unit=1, precision=1e-7)
    lib = gdspy.GdsLibrary(infile=fname, rename={'robustpath': 'file'})
    assertsame(lib.cell_dict['file'], cell, tolerance=1e-3)
    gdspy.current_library = gdspy.GdsLibrary()
示例#3
0
    def render(self):
        """
        Draws WMI logos
        :return:
        """
        mcqst_negative_cell=gdspy.GdsLibrary()
        mcqst_negative = mcqst_negative_cell.read_gds(infile=self.path_mask+"\logo_mcqst.gds").cells['MCQST']
        mcqst_negative.remove_polygons(lambda pts, layer, datatype: layer != self.layers_configuration['inverted'])

        mcqst_positive_cell = gdspy.GdsLibrary()
        mcqst_positive = mcqst_positive_cell.read_gds(infile=self.path_mask + "\logo_mcqst.gds").cells['MCQST']
        mcqst_positive.remove_polygons(lambda pts, layer, datatype: layer != self.layers_configuration['total'])
        for elements_layer in [mcqst_negative.polygons,mcqst_positive.polygons]:
            for element in elements_layer:
                element.translate(self.position_logo_one[0],self.position_logo_one[1])
        ############### add wmi logos
        wmi_negative_cell = gdspy.GdsLibrary()
        wmi_negative = wmi_negative_cell.read_gds(infile=self.path_mask + "\logo_wmi.gds").cells['WMI']
        wmi_negative.remove_polygons(lambda pts, layer, datatype: layer != self.layers_configuration['inverted'])

        wmi_positive_cell = gdspy.GdsLibrary()
        wmi_positive = wmi_positive_cell.read_gds(infile=self.path_mask + "\logo_wmi.gds").cells['WMI']
        wmi_positive.remove_polygons(lambda pts, layer, datatype: layer != self.layers_configuration['total'])
        for elements_layer in [wmi_negative.polygons,wmi_positive.polygons]:
            for element in elements_layer:
                element.translate(self.position_logo_two[0],self.position_logo_two[1])
        ############## add restricted area
        restricted_object=None
        for object in [mcqst_positive,wmi_positive,mcqst_negative,wmi_negative]:
            restricted_object=gdspy.boolean(object.get_polygons(),restricted_object,'or')

        return {'positive': gdspy.boolean(mcqst_positive.get_polygons(),wmi_positive.get_polygons(),'or',layer=self.layers_configuration['total']),
                'inverted': gdspy.boolean(mcqst_negative.get_polygons(),wmi_negative.get_polygons(),'or',layer=self.layers_configuration['inverted']),
                'restrict': restricted_object}
示例#4
0
    def render(self):

        if self.cross_type=='Navigation':
            filename = "\/navigation_cross.gds"
            cell_name = 'Navigation_cross'

        elif self.cross_type=='Cut':
            filename = "\cut_cross.gds"
            cell_name = 'Cut_cross'

        cross_positive = gdspy.GdsLibrary().read_gds(infile=self.path_mask +
                                                            filename).cells[cell_name].remove_polygons(lambda pts,layer,
                                                           datatype: layer != self.layers_configuration['total'])

        cross_negative = gdspy.GdsLibrary().read_gds(infile=self.path_mask +
                                                            filename).cells[cell_name].remove_polygons(lambda pts,layer,
                                                           datatype: layer != self.layers_configuration['inverted'])


        for elements_layer in [cross_negative.polygons,cross_positive.polygons]:
            for element in elements_layer:
                element.translate(self.cross_position[0],self.cross_position[1])

        restricted_object=gdspy.boolean(cross_negative.get_polygons(),cross_positive.get_polygons(),'or')

        return {'positive': cross_positive,
                'inverted': cross_negative,
                'restrict': restricted_object}
示例#5
0
def test_write_gds(library, tmpdir):
    gdspy.current_library = library
    fname1 = str(tmpdir.join('test1.gds'))
    gdspy.write_gds(fname1, name='lib', unit=2e-6, precision=1e-8)
    lib1 = gdspy.GdsLibrary(infile=fname1,
                            units='convert',
                            rename={'cell1': '1'},
                            layers={2: 4},
                            datatypes={4: 2},
                            texttypes={6: 7})
    assert lib1.name == 'lib'
    assert len(lib1.cell_dict) == 4
    assert set(lib1.cell_dict.keys()) == {'1', 'cell2', 'cell3', 'cell04'}
    c = lib1.cell_dict['1']
    assert len(c.polygons) == len(c.labels) == 1
    assert c.polygons[0].area() == 12.0
    assert c.polygons[0].layers == [4]
    assert c.polygons[0].datatypes == [2]
    assert c.labels[0].text == 'label'
    assert c.labels[0].position[0] == 2 and c.labels[0].position[1] == -2
    assert c.labels[0].anchor == 4
    assert c.labels[0].rotation == 45
    assert c.labels[0].magnification == 1.5
    assert c.labels[0].x_reflection == True
    assert c.labels[0].layer == 5
    assert c.labels[0].texttype == 7

    c = lib1.cell_dict['cell2']
    assert len(c.polygons) == 2
    assert isinstance(c.polygons[0], gdspy.Polygon) and isinstance(
        c.polygons[1], gdspy.Polygon)

    c = lib1.cell_dict['cell3']
    assert len(c.references) == 1
    assert c.references[0].ref_cell == lib1.cell_dict['1']
    assert c.references[0].origin[0] == 0 and c.references[0].origin[1] == 2
    assert c.references[0].rotation == -90
    assert c.references[0].magnification == 2
    assert c.references[0].x_reflection == True

    c = lib1.cell_dict['cell04']
    assert len(c.references) == 1
    assert c.references[0].ref_cell == lib1.cell_dict['cell2']
    assert c.references[0].origin[0] == -2 and c.references[0].origin[1] == -4
    assert c.references[0].rotation == 180
    assert c.references[0].magnification == 0.5
    assert c.references[0].x_reflection == True
    assert c.references[0].spacing[0] == 2 and c.references[0].spacing[1] == 8
    assert c.references[0].columns == 2
    assert c.references[0].rows == 3

    fname2 = str(tmpdir.join('test2.gds'))
    with open(fname2, 'wb') as fout:
        gdspy.write_gds(fout, name='lib2', unit=2e-3, precision=1e-5)
    with open(fname2, 'rb') as fin:
        lib2 = gdspy.GdsLibrary()
        lib2.read_gds(fin)
    assert lib2.name == 'lib2'
    assert len(lib2.cell_dict) == 4
示例#6
0
def test_togds(tmpdir):
    ps = gdspy.PolygonSet([[(10 + i * 1e-3, i ** 2 * 1e-6) for i in range(8191)]])
    cell = gdspy.Cell("LARGE").add(ps)
    fname = str(tmpdir.join("large.gds"))
    lib = gdspy.GdsLibrary(unit=1, precision=1e-7).add(cell)
    with pytest.warns(UserWarning):
        lib.write_gds(fname)
    lib = gdspy.GdsLibrary(infile=fname)
    assertsame(lib.cells["LARGE"], cell)
示例#7
0
def test_flexpath_togds(tmpdir):
    cell = gdspy.Cell("flexpath")
    fp = gdspy.FlexPath([(0, 0), (0.5, 0.5), (1, 1)],
                        0.1,
                        layer=[1],
                        gdsii_path=True)
    cell.add(fp)
    fp = gdspy.FlexPath([(3, 0), (3.5, 0.5), (4, 1)], 0.1, layer=[21])
    cell.add(fp)
    fp = gdspy.FlexPath(
        [(1, 0), (2, 1)],
        0.1,
        [-0.1, 0.1],
        max_points=6,
        ends=["round", "extended"],
        layer=[2, 3],
        gdsii_path=True,
    )
    cell.add(fp)
    fp = gdspy.FlexPath(
        [(2, 0), (3, 1)],
        [0.1, 0.2],
        0.2,
        ends=(0.2, 0.1),
        layer=4,
        datatype=[10, 10],
        gdsii_path=True,
    )
    cell.add(fp)

    fp = gdspy.FlexPath(
        [(0, 0), (0.5, 0), (1, 0), (1, 1), (0, 1), (-1, -2), (-2, 0)],
        0.05,
        [0, -0.1, 0, 0.1],
        corners=["natural", "circular bend", "circular bend", "circular bend"],
        tolerance=1e-5,
        ends=["flush", "extended", (0.1, 0.2), "flush"],
        layer=[10, 11, 11, 12],
        bend_radius=[0, 0.3, 0.3, 0.2],
        gdsii_path=True,
    ).translate(-5, 0)
    cell.add(fp)
    fp = gdspy.FlexPath([(i, 2 + i**2) for i in numpy.linspace(0, 1, 8192)],
                        0.01,
                        gdsii_path=True)
    cell.add(fp)
    fname = str(tmpdir.join("test.gds"))
    with pytest.warns(UserWarning):
        gdspy.write_gds(fname, unit=1, precision=1e-7)
    lib = gdspy.GdsLibrary(infile=fname, rename={"flexpath": "file"})
    assertsame(lib.cell_dict["file"], cell, tolerance=1e-3)
    gdspy.current_library = gdspy.GdsLibrary()
示例#8
0
def test_add():
    lib = gdspy.GdsLibrary()
    c1 = gdspy.Cell("gl_add_1")
    c2 = gdspy.Cell("gl_add_2")
    c3 = gdspy.Cell("gl_add_3")
    r1 = gdspy.CellReference(c1)
    with pytest.warns(UserWarning):
        r2 = gdspy.CellReference("gl_add_2")
    c3.add([r1, r2])
    lib.add(c1)
    lib.add((c2, c3))
    assert lib.cells == {"gl_add_1": c1, "gl_add_2": c2, "gl_add_3": c3}
    lib = gdspy.GdsLibrary()
    lib.add(c3)
    assert lib.cells == {"gl_add_1": c1, "gl_add_3": c3}
示例#9
0
 def __init__(self, position_logo_one: Tuple[float, float], position_logo_two: Tuple[float, float],layers_configuration: LayerConfiguration):
     """
     Element for creating a WMI logos on a chip
     :param position_logo_one:
     :param position_logo_two:
     :param layer_configuration:
     """
     super().__init__('wmi_logos','wmi_logos')
     self.position_logo_one = position_logo_one
     self.position_logo_two = position_logo_two
     path=os.getcwd()
     self.path_mask = path[:path.rindex('QCreator')]+'QCreator\QCreator\elements\masks'
     self.logo_mcqst = gdspy.GdsLibrary(infile = self.path_mask+"\logo_mcqst.gds")
     self.logo_wmi = gdspy.GdsLibrary(infile = self.path_mask+"\logo_wmi.gds")
     self.layers_configuration = layers_configuration
示例#10
0
def test_offset():
    gdspy.current_library = gdspy.GdsLibrary()
    r = gdspy.Rectangle((0, 0), (1, 2))
    result = gdspy.Rectangle((-1, -1), (2, 3))
    assert equals(gdspy.offset(r, 1), result)
    c = gdspy.Cell("OFFSET").add(r)
    ca = gdspy.CellArray(c, 2, 1, (1, 0))
    result = gdspy.Rectangle((0.2, 0.2), (1.8, 1.8))
    assert equals(gdspy.offset([ca], -0.2, join_first=True), result)
    v = [gdspy.Rectangle((-1, -1), (1, 1)), [(0, 0), (1, 0), (1, 1), (0, 1)]]
    x = 1 + 0.1 * numpy.tan(numpy.pi / 8)
    result = gdspy.Polygon(
        [
            (-1.1, -x),
            (-1.1, x),
            (-x, 1.1),
            (x, 1.1),
            (1.1, x),
            (1.1, -x),
            (x, -1.1),
            (-x, -1.1),
        ],
        layer=8,
    )
    assert equals(gdspy.offset(v, 0.1, join="bevel", layer=12), result)
示例#11
0
    def __init__(self, name, configurations):
        self.layer_configuration = elements.LayerConfiguration(
            **configurations)
        self.chip_geometry = elements.ChipGeometry(**configurations)
        self.name = str(name)

        self.lib = gdspy.GdsLibrary(unit=1e-06, precision=1e-09)

        self.total_cell = self.lib.new_cell(self.name,
                                            overwrite_duplicate=True,
                                            update_references=True)
        self.restricted_cell = self.lib.new_cell(self.name + ' restricted',
                                                 overwrite_duplicate=True,
                                                 update_references=True)
        # Geometry must be placed in cells.

        # for several additional features
        self.qubits_cells = []
        self.qubit_cap_cells = []
        self.caps_list = []

        self.objects = []

        # self.pads = []
        self.qubits = []
        self.lines = []
        self.bridges = []
        self.couplers = []
        self.resonators = []
        self.purcells = []

        self.pads = elements.Pads(self.objects)
        self.connections = []
示例#12
0
def write_cells_recursively(
    cell: gdspy.Cell,
    unit: float = 1e-6,
    precision: float = 1e-9,
    timestamp: Optional[datetime.datetime] = _timestamp2019,
    dirpath: pathlib.Path = Optional[pathlib.Path],
):
    """Write gdspy cells recursively

    Args:
        cell: gdspy cell
        unit: unit size for objects in library. 1um by default.
        precision: for object dimensions in the library (m). 1nm by default.
        timestamp: Defaults to 2019-10-25. If None uses current time.
        dirpath: directory for the GDS file
    """
    dirpath = dirpath or pathlib.Path.cwd()

    for cell in cell.get_dependencies():
        gdspath = f"{pathlib.Path(dirpath)/cell.name}.gds"
        lib = gdspy.GdsLibrary(unit=unit, precision=precision)
        lib.write_gds(gdspath, cells=[cell], timestamp=timestamp)
        logger.info(f"Write GDS to {gdspath}")

        if cell.get_dependencies():
            write_cells_recursively(
                cell=cell,
                unit=unit,
                precision=precision,
                timestamp=timestamp,
                dirpath=dirpath,
            )
示例#13
0
def test_gather():
    def same_points(x, y):
        for px, py in zip(x, y):
            for ptx, pty in zip(px, py):
                for cx, cy in zip(ptx, pty):
                    if cx != cy: return False
        return True

    gdspy.current_library = gdspy.GdsLibrary()
    pts = [(0, 0), (1, 1), (1, 0)]
    ps1 = gdspy.Round((10, 10), 1, inner_radius=0.2)
    ps2 = gdspy.Path(0.1, (-1, -1), 2, 1).segment(2, '-x')
    c = gdspy.Cell('C1').add(gdspy.Rectangle((-4, 3), (-5, 4)))
    cr = gdspy.CellReference(c, (10, -10))
    ca = gdspy.CellArray(c, 2, 1, (2, 0))
    assert gdspy._gather_polys(None) == []
    assert same_points(gdspy._gather_polys([pts]), [pts])
    assert same_points(gdspy._gather_polys(ps1), ps1.polygons)
    assert same_points(gdspy._gather_polys(ps2), ps2.polygons)
    assert same_points(gdspy._gather_polys(cr), cr.get_polygons())
    assert same_points(gdspy._gather_polys(ca), ca.get_polygons())
    result = [pts]
    result.extend(ps2.polygons)
    result.extend(cr.get_polygons())
    assert same_points(gdspy._gather_polys([pts, ps2, cr]), result)
示例#14
0
def test_copy():
    gdspy.current_library = gdspy.GdsLibrary()
    p = gdspy.Rectangle((0, 0), (1, 1))
    q = gdspy.copy(p, 1, -1)
    assert set(p.polygons[0][:, 0]) == {0, 1}
    assert set(p.polygons[0][:, 1]) == {0, 1}
    assert set(q.polygons[0][:, 0]) == {1, 2}
    assert set(q.polygons[0][:, 1]) == {-1, 0}
    p = gdspy.PolygonSet([[(0, 0), (1, 0), (0, 1)], [(2, 2), (3, 2), (2, 3)]])
    q = gdspy.copy(p, 1, -1)
    assert set(p.polygons[0][:, 0]) == {0, 1}
    assert set(p.polygons[0][:, 1]) == {0, 1}
    assert set(q.polygons[0][:, 0]) == {1, 2}
    assert set(q.polygons[0][:, 1]) == {-1, 0}
    assert set(p.polygons[1][:, 0]) == {2, 3}
    assert set(p.polygons[1][:, 1]) == {2, 3}
    assert set(q.polygons[1][:, 0]) == {3, 4}
    assert set(q.polygons[1][:, 1]) == {1, 2}
    l = gdspy.Label('text', (0, 1))
    m = gdspy.copy(l, -1, 1)
    assert l.position[0] == 0 and l.position[1] == 1
    assert m.position[0] == -1 and m.position[1] == 2
    c = gdspy.CellReference('empty', (0, 1), ignore_missing=True)
    d = gdspy.copy(c, -1, 1)
    assert c.origin == (0, 1)
    assert d.origin == (-1, 2)
    c = gdspy.CellArray('empty', 2, 3, (1, 0), (0, 1), ignore_missing=True)
    d = gdspy.copy(c, -1, 1)
    assert c.origin == (0, 1)
    assert d.origin == (-1, 2)
示例#15
0
def test_inside():
    gdspy.current_library = gdspy.GdsLibrary()
    polygons = [
        gdspy.Round((0, 0), 10, inner_radius=5, number_of_points=180),
        gdspy.Rectangle((20, -10), (40, 10)).polygons[0],
        gdspy.CellReference(
            gdspy.Cell("X").add(gdspy.Rectangle((-10, 0), (10, 20)))),
    ]
    assert gdspy.inside([(0, 0)], polygons[0]) == (False, )
    assert gdspy.inside([(0, 0)], polygons[2]) == (True, )
    assert gdspy.inside([(0, 0)], polygons) == (True, )
    assert gdspy.inside([(0, 0), (0, 30), (30, 0), (0, -1)], polygons) == (
        True,
        False,
        True,
        False,
    )
    assert gdspy.inside(
        [[(0, 0), (0, 30), (30, 0), (0, -1)], [(0, -1),
                                               (0, 30)], [(0, 0), (30, 0)]],
        polygons,
        "any",
    ) == (True, False, True)
    assert gdspy.inside(
        [[(0, 0), (0, 30), (30, 0), (0, -1)], [(0, -1),
                                               (0, 30)], [(0, 0), (30, 0)]],
        polygons,
        "all",
    ) == (False, False, True)
示例#16
0
文件: cell.py 项目: gnawhleinad/gdspy
def test_ignore_duplicate():
    lib = gdspy.GdsLibrary()
    c1 = gdspy.Cell("c_ignore_duplicate")
    lib.add(c1)
    lib.add(c1, overwrite_duplicate=False)
    lib.add(gdspy.Cell(c1.name), overwrite_duplicate=True)
    assert lib.cells[c1.name] is not c1
示例#17
0
文件: cell.py 项目: thorphil/gdspy
def test_add_label():
    gdspy.current_library = gdspy.GdsLibrary()
    lbl = gdspy.Label("label", (0, 0))
    c = gdspy.Cell("c_add_label")
    assert c.add(lbl) is c
    assert c.add([lbl, lbl]) is c
    assert c.labels == [lbl, lbl, lbl]
示例#18
0
文件: cell.py 项目: thorphil/gdspy
def test_add_element():
    gdspy.current_library = gdspy.GdsLibrary()
    p = gdspy.Polygon(((0, 0), (1, 0), (0, 1)))
    c = gdspy.Cell("c_add_element")
    assert c.add(p) is c
    assert c.add([p, p]) is c
    assert c.polygons == [p, p, p]
示例#19
0
def parse_gdsii():
  gdsii = gdspy.GdsLibrary()
  gdsii.read_gds(
      cmisc.
      path_here('./shiftreg_e7f285dccca5788b157d72e7fde31a92ed765c64ec86d56164426b7c1cde1625.gds2'),
  )
  return gdsii
示例#20
0
文件: cell.py 项目: thorphil/gdspy
def test_duplicate():
    gdspy.current_library = gdspy.GdsLibrary()
    name = "c_duplicate"
    gdspy.Cell(name)
    with pytest.raises(ValueError) as e:
        gdspy.Cell(name)
    assert name in str(e.value)
示例#21
0
def test_add_update2():
    lib = gdspy.GdsLibrary()
    main = gdspy.Cell("MAIN")
    c1 = gdspy.Cell("C1")
    c2 = gdspy.Cell("C2")
    c3 = gdspy.Cell("C1")
    r1 = gdspy.CellReference(c1)
    main.add(r1)
    with pytest.warns(UserWarning):
        r2 = gdspy.CellArray("C1", 1, 1, (1, 1))
    main.add(r2)
    r3 = gdspy.CellReference(c2)
    main.add(r3)
    r4 = gdspy.CellReference(c3)
    c2.add(r4)
    with pytest.warns(UserWarning):
        r5 = gdspy.CellReference("C3")
    c1.add(r5)
    with pytest.warns(UserWarning):
        r6 = gdspy.CellReference("C2")
    main.add(r6)
    lib.add([main, c1, c2], include_dependencies=False)
    lib.add(
        c3,
        include_dependencies=False,
        overwrite_duplicate=True,
        update_references=False,
    )
    assert r1.ref_cell is c1
    assert r2.ref_cell == "C1"
    assert r3.ref_cell is c2
    assert r4.ref_cell is c3
    assert r5.ref_cell == "C3"
    assert r6.ref_cell == "C2"
示例#22
0
def makeFile(filename, parts):
    lib = gdspy.GdsLibrary()
    cell = lib.new_cell('cell')
    cell.add(parts)
    cell.add(gdspy.Label('origin', [0, 0]))
    lib.write_gds(filename)
    gdspy.LayoutViewer()
示例#23
0
def test_replace():
    lib = gdspy.GdsLibrary()
    main = gdspy.Cell("MAIN")
    c1 = gdspy.Cell("C1")
    c2 = gdspy.Cell("C2")
    c3 = gdspy.Cell("C1")
    r1 = gdspy.CellReference(c1)
    main.add(r1)
    with pytest.warns(UserWarning):
        r2 = gdspy.CellArray("C1", 1, 1, (1, 1))
    main.add(r2)
    r3 = gdspy.CellReference(c2)
    main.add(r3)
    r4 = gdspy.CellReference(c3)
    c2.add(r4)
    with pytest.warns(UserWarning):
        r5 = gdspy.CellReference("C3")
    c1.add(r5)
    with pytest.warns(UserWarning):
        r6 = gdspy.CellReference("C2")
    main.add(r6)
    lib.add([main, c1, c2], include_dependencies=False)
    assert lib.replace_references(c2, c3) == 2
    assert r3.ref_cell is c3
    assert r6.ref_cell is c3
    assert lib.replace_references("C3", "C1") == 1
    assert r5.ref_cell is c1
    assert lib.replace_references("C1", c2) == 6
    assert r1.ref_cell is c2
    assert r2.ref_cell is c2
    assert r3.ref_cell is c2
    assert r4.ref_cell is c2
    assert r5.ref_cell is c2
    assert r6.ref_cell is c2
示例#24
0
def test_remove():
    lib = gdspy.GdsLibrary()
    main = gdspy.Cell("MAIN")
    c1 = gdspy.Cell("C1")
    c2 = gdspy.Cell("C2")
    c3 = gdspy.Cell("C1")
    r1 = gdspy.CellReference(c1)
    main.add(r1)
    with pytest.warns(UserWarning):
        r2 = gdspy.CellArray("C1", 1, 1, (1, 1))
    main.add(r2)
    r3 = gdspy.CellReference(c2)
    main.add(r3)
    r4 = gdspy.CellReference(c3)
    c2.add(r4)
    with pytest.warns(UserWarning):
        r5 = gdspy.CellReference("C3")
    c1.add(r5)
    with pytest.warns(UserWarning):
        r6 = gdspy.CellReference("C2")
    main.add(r6)
    lib.add([main, c1, c2], include_dependencies=False)
    assert lib.remove("C3") == 1
    assert len(c1.references) == 0
    assert len(c2.references) == 1
    assert c2.references[0] is r4
    assert lib.remove(c1) == 3
    assert "C1" not in lib.cells
    assert len(main.references) == 2
    assert main.references[0] is r3
    assert main.references[1] is r6
    assert len(c2.references) == 0
示例#25
0
    def _import_gds(self):
        gdsii_lib = gdspy.GdsLibrary()
        gdsii_lib.read_gds(self.filename)
        top_level_cells = gdsii_lib.top_level()
        cellname = self.cellname
        if cellname is not None:
            if cellname not in gdsii_lib.cell_dict:
                raise ValueError(
                    'The requested cell (named %s) is not present in file %s' %
                    (cellname, self.filename))
            topcell = gdsii_lib.cell_dict[cellname]
        elif cellname is None and len(top_level_cells) == 1:
            topcell = top_level_cells[0]
        elif cellname is None and len(top_level_cells) > 1:
            areas = []
            for cell in top_level_cells:
                areas.append(cell.area())
            ind = areas.index(max(areas))
            topcell = top_level_cells[ind]

        D = Device('import_gds')
        polygons = topcell.get_polygons(by_spec=True)

        for layer_in_gds, polys in polygons.items():
            D.add_polygon(polys, layer=layer_in_gds)
        return D
示例#26
0
文件: cell.py 项目: gnawhleinad/gdspy
def test_duplicate():
    lib = gdspy.GdsLibrary()
    name = "c_duplicate"
    c = gdspy.Cell(name)
    lib.add(c)
    with pytest.raises(ValueError) as e:
        lib.add(gdspy.Cell(name), overwrite_duplicate=False)
    assert name in str(e.value)
示例#27
0
def test_add():
    lib = gdspy.GdsLibrary()
    c1 = gdspy.Cell("gl_add_1", exclude_from_current=True)
    c2 = gdspy.Cell("gl_add_2", exclude_from_current=True)
    c3 = gdspy.Cell("gl_add_3", exclude_from_current=True)
    lib.add(c1)
    lib.add((c2, c3))
    assert lib.cell_dict == {"gl_add_1": c1, "gl_add_2": c2, "gl_add_3": c3}
示例#28
0
def test_add():
    lib = gdspy.GdsLibrary()
    c1 = gdspy.Cell('gl_add_1', exclude_from_current=True)
    c2 = gdspy.Cell('gl_add_2', exclude_from_current=True)
    c3 = gdspy.Cell('gl_add_3', exclude_from_current=True)
    lib.add(c1)
    lib.add((c2, c3))
    assert lib.cell_dict == {'gl_add_1': c1, 'gl_add_2': c2, 'gl_add_3': c3}
示例#29
0
def _example():
    file_path = './layout/Combinenation_SiO2.gds'
    origin = (100, 100)
    loadedcell = new_import.import_gds(file_path, origin, 'GC_a230_0_0')
    lib = gdspy.GdsLibrary(name='GC', precision=1e-10)
    device = lib.new_cell('loadedCell')
    device.add(loadedcell)
    gdspy.LayoutViewer(lib)
示例#30
0
 def bbox(self):
     glib = gdspy.GdsLibrary(name=self.name)
     cell = deepcopy(self)
     cell = self.construct_gdspy_tree(glib)
     bbox = cell.get_bounding_box()
     if bbox is None:
         bbox = ((0, 0), (0, 0))
     return np.array(bbox)