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

overwrite_duplicate not working with (use_current_library = True) #233

Open
userx14 opened this issue Jul 8, 2023 · 1 comment
Open

Comments

@userx14
Copy link

userx14 commented Jul 8, 2023

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?

@heitzmann
Copy link
Owner

heitzmann commented Aug 6, 2023

It's a bug. When using current_library, calling new_cell on it is not the expected use case (since just creating a cell from the constructor achieves the same goal and seems simpler). The problem is that your solution won't work if new_cell is called from another library, because self != gdspy.currentl_library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants