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

FEAT: Reduce via in bounding box #946

Merged
merged 7 commits into from
Dec 19, 2024
Merged
Changes from 3 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
105 changes: 80 additions & 25 deletions src/pyedb/dotnet/edb_core/padstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import math
import warnings

import numpy as np
import rtree

from pyedb.dotnet.clr_module import Array
Expand Down Expand Up @@ -555,7 +556,7 @@ def create_coax_port(self, padstackinstance, use_dot_separator=True, name=None):
port_name = name
if self._port_exist(port_name):
port_name = generate_unique_name(port_name, n=2)
self._logger.info("An existing port already has this same name. Renaming to {}.".format(port_name))
self._logger.info("An existing port already has this same name. Renaming to {}.".format(port_name))
self._edb.cell.terminal.PadstackInstanceTerminal.Create(
self._active_layout,
padstackinstance.GetNet(),
Expand Down Expand Up @@ -1553,30 +1554,6 @@ def get_padstack_instances_rtree_index(self, nets=None):
padstack_instances_index.insert(inst.id, inst.position)
return padstack_instances_index

def get_padstack_instances_intersecting_bounding_box(self, bounding_box, nets=None):
"""Returns the list of padstack instances ID intersecting a given bounding box and nets.

Parameters
----------
bounding_box : tuple or list.
bounding box, [x1, y1, x2, y2]
nets : str or list, optional
net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
all instances are included in the index. Default value is ``None``.

Returns
-------
List of padstack instances ID intersecting the bounding box.
"""
if not bounding_box:
raise Exception("No bounding box was provided")
index = self.get_padstack_instances_rtree_index(nets=nets)
if not len(bounding_box) == 4:
raise Exception("The bounding box length must be equal to 4")
if isinstance(bounding_box, list):
bounding_box = tuple(bounding_box)
return list(index.intersection(bounding_box))

def merge_via_along_lines(
self, net_name="GND", distance_threshold=5e-3, minimum_via_number=6, selected_angles=None
):
Expand Down Expand Up @@ -1657,3 +1634,81 @@ def merge_via_along_lines(
for inst in _instances_to_delete:
inst.delete()
return True

def get_padstack_instances_intersecting_bounding_box(self, bounding_box, nets=None):
"""Returns the list of padstack instances ID intersecting a given bounding box and nets.

Parameters
----------
bounding_box : tuple or list.
bounding box, [x1, y1, x2, y2]
nets : str or list, optional
net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
all instances are included in the index. Default value is ``None``.

Returns
-------
List of padstack instances ID intersecting the bounding box.
"""
if not bounding_box:
raise Exception("No bounding box was provided")
index = self.get_padstack_instances_rtree_index(nets=nets)
if not len(bounding_box) == 4:
raise Exception("The bounding box length must be equal to 4")
if isinstance(bounding_box, list):
bounding_box = tuple(bounding_box)
return list(index.intersection(bounding_box))

def reduce_via_in_bounding_box(self, bounding_box, x_samples, y_samples, nets=None):
"""
reduce the number of vias intersecting bounding box and nets by x and y samples.

Parameters
----------
bounding_box : tuple or list.
bounding box, [x1, y1, x2, y2]
x_samples : int
y_samples : int
nets : str or list, optional
net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
all instances are included in the index. Default value is ``None``.

Returns
-------
bool
``True`` when succeeded ``False`` when failed. <
"""

padstacks_inbox = self.get_padstack_instances_intersecting_bounding_box(bounding_box, nets)
if not padstacks_inbox:
self._logger.info("no padstack in bounding box")
return False
else:
if len(padstacks_inbox) <= (x_samples * y_samples):
self._logger.info(f"more samples {x_samples * y_samples} than existing {len(padstacks_inbox)}")
return True
else:
# extract ids and positions
vias = {item: self.instances[item].position for item in padstacks_inbox}
ids, positions = zip(*vias.items())
pt_x, pt_y = zip(*positions)

# meshgrid
_x_min, _x_max = min(pt_x), max(pt_x)
_y_min, _y_max = min(pt_y), max(pt_y)

x_grid, y_grid = np.meshgrid(
np.linspace(_x_min, _x_max, x_samples), np.linspace(_y_min, _y_max, y_samples)
)

# mapping to meshgrid
to_keep = {
ids[np.argmin(np.square(_x - pt_x) + np.square(_y - pt_y))]
for _x, _y in zip(x_grid.ravel(), y_grid.ravel())
}

for item in padstacks_inbox:
if item not in to_keep:
self.instances[item].delete()

return True
Loading