[gdsii_arrow] further improvements to speed
This commit is contained in:
parent
c68e76a40e
commit
51cab706da
3 changed files with 235 additions and 61 deletions
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
|
||||
pytest.importorskip('pyarrow')
|
||||
|
||||
from .. import Ref, Label
|
||||
from ..library import Library
|
||||
from ..pattern import Pattern
|
||||
from ..repetition import Grid
|
||||
|
|
@ -119,7 +120,10 @@ def _make_arrow_test_library() -> Library:
|
|||
|
||||
leaf = Pattern()
|
||||
leaf.polygon((1, 0), vertices=[[0, 0], [10, 0], [10, 10], [0, 10]], annotations={'1': ['leaf-poly']})
|
||||
leaf.polygon((2, 0), vertices=[[40, 0], [50, 0], [50, 10], [40, 10]])
|
||||
leaf.polygon((1, 0), vertices=[[20, 0], [30, 0], [30, 10], [20, 10]])
|
||||
leaf.polygon((1, 0), vertices=[[80, 0], [90, 0], [90, 10], [80, 10]])
|
||||
leaf.polygon((2, 0), vertices=[[60, 0], [70, 0], [70, 10], [60, 10]], annotations={'18': ['leaf-poly-2']})
|
||||
leaf.label((10, 0), string='LEAF', offset=(3, 4), annotations={'10': ['leaf-label']})
|
||||
lib['leaf'] = leaf
|
||||
|
||||
|
|
@ -178,3 +182,80 @@ def test_gdsii_arrow_reads_small_perf_fixture(tmp_path: Path) -> None:
|
|||
assert len(lib) == manifest.cells
|
||||
assert 'TOP' in lib
|
||||
assert sum(len(refs) for refs in lib['TOP'].refs.values()) > 0
|
||||
|
||||
|
||||
def test_gdsii_arrow_boundary_batch_schema(tmp_path: Path) -> None:
|
||||
lib = _make_arrow_test_library()
|
||||
gds_file = tmp_path / 'arrow_batches.gds'
|
||||
gdsii.writefile(lib, gds_file, meters_per_unit=1e-9)
|
||||
|
||||
libarr = gdsii_arrow._read_to_arrow(gds_file)[0]
|
||||
cells = libarr['cells'].values
|
||||
cell_ids = cells.field('id').to_numpy()
|
||||
cell_names = libarr['cell_names'].as_py()
|
||||
layer_table = [
|
||||
((int(layer) >> 16) & 0xFFFF, int(layer) & 0xFFFF)
|
||||
for layer in libarr['layers'].values.to_numpy()
|
||||
]
|
||||
|
||||
leaf_index = next(ii for ii, cell_id in enumerate(cell_ids) if cell_names[cell_id] == 'leaf')
|
||||
|
||||
boundary_batches = cells.field('boundary_batches')[leaf_index].as_py()
|
||||
boundary_props = cells.field('boundary_props')[leaf_index].as_py()
|
||||
|
||||
assert len(boundary_batches) == 2
|
||||
assert len(boundary_props) == 2
|
||||
|
||||
batch_by_layer = {tuple(layer_table[entry['layer']]): entry for entry in boundary_batches}
|
||||
assert batch_by_layer[(1, 0)]['vertex_offsets'] == [0, 4]
|
||||
assert len(batch_by_layer[(1, 0)]['vertices']) == 16
|
||||
assert batch_by_layer[(2, 0)]['vertex_offsets'] == [0]
|
||||
assert len(batch_by_layer[(2, 0)]['vertices']) == 8
|
||||
|
||||
props_by_layer = {tuple(layer_table[entry['layer']]): entry for entry in boundary_props}
|
||||
assert sorted(props_by_layer) == [(1, 0), (2, 0)]
|
||||
assert props_by_layer[(1, 0)]['properties'][0]['value'] == 'leaf-poly'
|
||||
assert props_by_layer[(2, 0)]['properties'][0]['value'] == 'leaf-poly-2'
|
||||
|
||||
|
||||
def test_raw_ref_grid_label_constructors_match_public() -> None:
|
||||
raw_grid = Grid._from_raw(
|
||||
a_vector=numpy.array([20, 0]),
|
||||
a_count=3,
|
||||
b_vector=numpy.array([0, 30]),
|
||||
b_count=2,
|
||||
)
|
||||
public_grid = Grid(a_vector=(20, 0), a_count=3, b_vector=(0, 30), b_count=2)
|
||||
assert raw_grid == public_grid
|
||||
|
||||
raw_ref = Ref._from_raw(
|
||||
offset=numpy.array([100, 200]),
|
||||
rotation=numpy.pi / 2,
|
||||
mirrored=True,
|
||||
scale=1.25,
|
||||
repetition=raw_grid,
|
||||
annotations={'12': ['child-ref']},
|
||||
)
|
||||
public_ref = Ref(
|
||||
offset=(100, 200),
|
||||
rotation=numpy.pi / 2,
|
||||
mirrored=True,
|
||||
scale=1.25,
|
||||
repetition=public_grid,
|
||||
annotations={'12': ['child-ref']},
|
||||
)
|
||||
assert raw_ref == public_ref
|
||||
assert numpy.array_equal(raw_ref.as_transforms(), public_ref.as_transforms())
|
||||
|
||||
raw_label = Label._from_raw(
|
||||
'LEAF',
|
||||
offset=numpy.array([3, 4]),
|
||||
annotations={'10': ['leaf-label']},
|
||||
)
|
||||
public_label = Label(
|
||||
'LEAF',
|
||||
offset=(3, 4),
|
||||
annotations={'10': ['leaf-label']},
|
||||
)
|
||||
assert raw_label == public_label
|
||||
assert numpy.array_equal(raw_label.get_bounds_single(), public_label.get_bounds_single())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue