[data_to_ports] warn that repetitions are not not expanded

This commit is contained in:
Jan Petykiewicz 2026-04-01 19:01:47 -07:00
commit ac87179da2
2 changed files with 27 additions and 0 deletions

View file

@ -1,10 +1,13 @@
import numpy import numpy
import pytest
from numpy.testing import assert_allclose from numpy.testing import assert_allclose
from ..utils.ports2data import ports_to_data, data_to_ports from ..utils.ports2data import ports_to_data, data_to_ports
from ..pattern import Pattern from ..pattern import Pattern
from ..ports import Port from ..ports import Port
from ..library import Library from ..library import Library
from ..error import PortError
from ..repetition import Grid
def test_ports2data_roundtrip() -> None: def test_ports2data_roundtrip() -> None:
@ -74,3 +77,24 @@ def test_data_to_ports_hierarchical_scaled_ref() -> None:
assert_allclose(parent.ports["A"].offset, [100, 110], atol=1e-10) assert_allclose(parent.ports["A"].offset, [100, 110], atol=1e-10)
assert parent.ports["A"].rotation is not None assert parent.ports["A"].rotation is not None
assert_allclose(parent.ports["A"].rotation, numpy.pi / 2, atol=1e-10) assert_allclose(parent.ports["A"].rotation, numpy.pi / 2, atol=1e-10)
def test_data_to_ports_hierarchical_repeated_ref_warns_and_keeps_best_effort(
caplog: pytest.LogCaptureFixture,
) -> None:
lib = Library()
child = Pattern()
layer = (10, 0)
child.label(layer=layer, string="A:type1 0", offset=(5, 0))
lib["child"] = child
parent = Pattern()
parent.ref("child", repetition=Grid(a_vector=(100, 0), a_count=3))
caplog.set_level("WARNING")
data_to_ports([layer], lib, parent, max_depth=1)
assert "A" in parent.ports
assert_allclose(parent.ports["A"].offset, [5, 0], atol=1e-10)
assert any("importing only the base instance ports" in record.message for record in caplog.records)

View file

@ -133,6 +133,9 @@ def data_to_ports(
if not aa.ports: if not aa.ports:
break break
if ref.repetition is not None:
logger.warning(f'Pattern {name if name else pattern} has repeated ref to {target!r}; '
'data_to_ports() is importing only the base instance ports')
aa.apply_ref_transform(ref) aa.apply_ref_transform(ref)
pattern.check_ports(other_names=aa.ports.keys()) pattern.check_ports(other_names=aa.ports.keys())
pattern.ports.update(aa.ports) pattern.ports.update(aa.ports)