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
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
54 changes: 54 additions & 0 deletions src/pyedb/dotnet/edb_core/padstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,3 +1755,57 @@ def merge_via_along_lines(
for inst in _instances_to_delete:
inst.delete()
return True

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 False
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
Binary file added tests/example_models/TEDB/vias_300.aedb/edb.def
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/legacy/system/test_edb_padstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""Tests related to Edb padstacks
"""
import os
from pathlib import Path

import pytest

Expand Down Expand Up @@ -459,6 +460,19 @@ def test_via_fence(self):
assert "via_central" in edbapp.padstacks.definitions
edbapp.close()

def test_reduce_via_in_bounding_box(self):
source_path = Path(__file__).parent.parent.parent / "example_models" / "TEDB" / "vias_300.aedb"
edbapp = Edb(edbpath=source_path)
assert len(edbapp.padstacks.instances) == 301
# empty bounding box
assert edbapp.padstacks.reduce_via_in_bounding_box([-16e-3, -7e-3, -13e-3, -6e-3], 10, 10) is False
# over sampling
assert edbapp.padstacks.reduce_via_in_bounding_box([-20e-3, -10e-3, 20e-3, 10e-3], 20, 20) is False

assert edbapp.padstacks.reduce_via_in_bounding_box([-20e-3, -10e-3, 20e-3, 10e-3], 10, 10) is True
assert len(edbapp.padstacks.instances) == 96
edbapp.close_edb()

def test_via_merge(self, edb_examples):
edbapp = edb_examples.get_si_verse()
polygon = [[[118e-3, 60e-3], [125e-3, 60e-3], [124e-3, 56e-3], [118e-3, 56e-3]]]
Expand Down
1 change: 1 addition & 0 deletions tests/legacy/unit/test_padstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


from mock import MagicMock, PropertyMock, patch
import pytest

Expand Down
Loading