Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

overwrite_duplicate not working with (use_current_library = True) #233

@userx14

Description

@userx14

When using new_cell with the option overwrite_duplicate = True and use_current_library = True
an ValueError [GDSPY] Cell named xxx already present in library occurs.

I'm not sure if it is caused by improper usage, I do multiple calls of
gdspy.current_library.new_cell(name="testDupl", overwrite_duplicate=True).

I think this is caused because inside new_cell function the first operation is to instantiate a new cell:

gdspy/gdspy/library.py

Lines 2299 to 2328 in 5234778

def new_cell(self, name, overwrite_duplicate=False, update_references=True):
"""
Create a new cell and add it to this library.
Parameters
----------
name : string
Name of the cell.
overwrite_duplicate : bool
If True, an existing cell with the same name in the library
will be overwritten.
update_references : bool
If True, `CellReference` and `CellArray` instances from an
overwritten cell are updated to the new one (used only when
`overwrite_duplicate` is True).
Returns
-------
out : `Cell`
The created cell.
Notes
-----
This is equivalent to:
>>> cell = gdspy.Cell(name)
>>> lib.add(cell, False, overwrite_duplicate, update_references)
"""
cell = Cell(name)
self.add(cell, False, overwrite_duplicate, update_references)
return cell

But inside the initializer of the new cell class the overwrite_duplicate is not passed to the current_library.add function.

gdspy/gdspy/library.py

Lines 104 to 115 in 5234778

def __init__(self, name, exclude_from_current=False):
self.name = name
self.polygons = []
self.paths = []
self.labels = []
self.references = []
self._bb_valid = False
self._bounding_box = None
if use_current_library and not exclude_from_current:
import gdspy
gdspy.current_library.add(self, include_dependencies=False)

My workaround to fix this was a modifcation the new_cell function as follows:

def new_cell(self, name, overwrite_duplicate=False, update_references=True):
    if(overwrite_duplicate and use_current_library):
        cell = Cell(name, exclude_from_current=True)
    else:
        cell = Cell(name) 
    self.add(cell, False, overwrite_duplicate, update_references) 
    return cell 

Is this a bug or wrong usage?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions