Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update base_kcell to base and add locked setters #599

Merged
merged 4 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 154 additions & 149 deletions src/kfactory/kcell.py

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions src/kfactory/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,7 @@ def wrapper_autocell(

@cachetools.cached(cache=cache_, lock=RLock())
@functools.wraps(f)
def wrapped_cell(
**params: Any,
) -> K:
def wrapped_cell(**params: Any) -> K:
for key, value in params.items():
if isinstance(value, DecoratorDict | DecoratorList):
params[key] = _hashable_to_original(value)
Expand Down Expand Up @@ -836,8 +834,8 @@ def wrapped_cell(
)
# post process the cell
for pp in post_process:
pp(cell.base_kcell)
cell.base_kcell.lock()
pp(cell.base)
cell.base.lock()
if cell.kcl != self:
raise ValueError(
"The KCell created must be using the same"
Expand All @@ -848,7 +846,7 @@ def wrapped_cell(
" in the standard KCLayout, use either "
"custom_kcl.kcell() or KCell(kcl=custom_kcl)."
)
return output_cell_type(base_kcell=cell.base_kcell)
return output_cell_type(base=cell.base)

with self.thread_lock:
cell_ = wrapped_cell(**params)
Expand Down Expand Up @@ -1007,9 +1005,7 @@ def wrapper_autocell(

@cachetools.cached(cache=cache_)
@functools.wraps(f)
def wrapped_cell(
**params: Any,
) -> VKCell:
def wrapped_cell(**params: Any) -> VKCell:
for key, value in params.items():
if isinstance(value, DecoratorDict | DecoratorList):
params[key] = _hashable_to_original(value)
Expand Down Expand Up @@ -1069,7 +1065,7 @@ def wrapped_cell(
port.name, port.dcplx_trans.s_trans()
)
)
cell._base_kcell.lock()
cell._base.lock()
if cell.kcl != self:
raise ValueError(
"The KCell created must be using the same"
Expand Down Expand Up @@ -1258,7 +1254,7 @@ def register_cell(self, kcell: AnyTKCell, allow_reregister: bool = False) -> Non
"""
with self.thread_lock:
if (kcell.cell_index() not in self.tkcells) or allow_reregister:
self.tkcells[kcell.cell_index()] = kcell.base_kcell
self.tkcells[kcell.cell_index()] = kcell.base
else:
raise ValueError(
"Cannot register a new cell with a name that already"
Expand All @@ -1282,7 +1278,7 @@ def get_cell(self, obj: str | int, cell_type: type[K] = KCell) -> K: # type: ig
"""
if isinstance(obj, int):
try:
return cell_type(base_kcell=self.tkcells[obj])
return cell_type(base=self.tkcells[obj])
except KeyError:
kdb_c = self.layout_cell(obj)
if kdb_c is None:
Expand All @@ -1294,7 +1290,7 @@ def get_cell(self, obj: str | int, cell_type: type[K] = KCell) -> K: # type: ig
kdb_c = self.layout_cell(obj)
if kdb_c is not None:
try:
return cell_type(base_kcell=self.tkcells[kdb_c.cell_index()])
return cell_type(base=self.tkcells[kdb_c.cell_index()])
except KeyError:
c = cell_type(name=kdb_c.name, kcl=self, kdb_cell=kdb_c)
c.get_meta_data()
Expand Down
4 changes: 4 additions & 0 deletions src/kfactory/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
config.console.print(pprint_ports(self, unit=unit))
return capture.get()

def __hash__(self) -> int:
"""Hash the ports."""
return hash(self._bases)

Check warning on line 243 in src/kfactory/ports.py

View check run for this annotation

Codecov / codecov/patch

src/kfactory/ports.py#L243

Added line #L243 was not covered by tests


class Ports(ProtoPorts[int]):
"""A collection of dbu ports.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def test_cell_yaml(layers: Layers) -> None:
yaml = YAML()
yaml.register_class(kf.KCell)
c = kf.factories.straight.straight_dbu_factory(kf.kcl)(
width=5000, length=10000, layer=layers.WG
width=5320, length=17210, layer=layers.WG
).dup()

_temp_cell_name = "kf.factories.straight.straight_dbu_factory.random_cell"
Expand All @@ -466,8 +466,8 @@ def test_cell_yaml(layers: Layers) -> None:

c.name = _temp_cell_name

c_base_kcell = c.base_kcell
cell_base_kcell = cell.base_kcell
c_base_kcell = c.base
cell_base_kcell = cell.base

def compare_kcell_fields(
c_base_kcell: kf.KCell, cell_base_kcell: kf.KCell
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dkcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_dkcell_locked() -> None:
kcl = kf.KCLayout("TEST_DKCELL_LOCKED")
c = kcl.dkcell("test_dkcell_locked")
assert c.locked is False
c.base_kcell.lock()
c.base.lock()
assert c.locked is True
with pytest.raises(kf.kcell.LockedError):
c.ports = []
Expand Down
4 changes: 2 additions & 2 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def rectangle(width: float, height: float, layer: kf.kdb.LayerInfo) -> kf.DKCell
assert rectangle_cell is rectangle_cell2
assert rectangle_cell is not rectangle_cell3

rectangle_post_process.assert_any_call(rectangle_cell.base_kcell)
rectangle_post_process.assert_any_call(rectangle_cell3.base_kcell)
rectangle_post_process.assert_any_call(rectangle_cell.base)
rectangle_post_process.assert_any_call(rectangle_cell3.base)
assert rectangle_post_process.call_count == 2


Expand Down
2 changes: 1 addition & 1 deletion tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_metainfo_set(straight: kf.KCell) -> None:
"""Test autogenerated port metadata."""
ports = straight.ports.copy()

straight.base_kcell.kdb_cell.locked = False
straight.base.kdb_cell.locked = False
straight.set_meta_data()

straight.ports = kf.Ports(kcl=straight.kcl)
Expand Down
Loading
Loading