From 63ece976dd59d79419da32eb371635b31d929e38 Mon Sep 17 00:00:00 2001 From: Alex Tait Date: Wed, 13 Mar 2019 11:06:03 -0600 Subject: [PATCH] now using phidl's new hash_geometry function. --- lytest/kdb_xor.py | 15 ++++++++------- tests/phidl/test_phidl/test_1_phidldevices.py | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lytest/kdb_xor.py b/lytest/kdb_xor.py index aaef20d..deb7098 100644 --- a/lytest/kdb_xor.py +++ b/lytest/kdb_xor.py @@ -75,16 +75,17 @@ def run_xor(file1, file2, tolerance=1, verbose=False): raise GeometryDifference("Differences found between layouts {} and {}".format(*fn_abgd)) -def xor_polygons_phidl(A, B, geom_hash=True): +def xor_polygons_phidl(A, B, hash_geom=True): """ Given two devices A and B, performs a layer-by-layer XOR diff between A and B, and returns polygons representing the differences between A and B. """ - import phidl - import phidl.geometry as pg + from phidl import Device import gdspy - # first do + # first do a geometry hash to vastly speed up if they are equal + if hash_geom and (A.hash_geometry() == B.hash_geometry()): + return Device() - D = phidl.Device() + D = Device() A_polys = A.get_polygons(by_spec = True) B_polys = B.get_polygons(by_spec = True) A_layers = A_polys.keys() @@ -106,14 +107,14 @@ def xor_polygons_phidl(A, B, geom_hash=True): return D -def run_xor_phidl(file1, file2, tolerance=1, verbose=False): +def run_xor_phidl(file1, file2, tolerance=1, verbose=False, hash_geom=True): import phidl.geometry as pg from lytest.phidl_oas import import_oas TOPS = [] for fn in [file1, file2]: TOPS.append(import_oas(fn)) TOP1, TOP2 = TOPS - XOR = xor_polygons_phidl(TOP1, TOP2) + XOR = xor_polygons_phidl(TOP1, TOP2, hash_geom=True) if len(XOR.elements) > 0: raise GeometryDifference("Differences found between layouts {} and {}".format(file1, file2)) diff --git a/tests/phidl/test_phidl/test_1_phidldevices.py b/tests/phidl/test_phidl/test_1_phidldevices.py index 0b7df81..22b1764 100644 --- a/tests/phidl/test_phidl/test_1_phidldevices.py +++ b/tests/phidl/test_phidl/test_1_phidldevices.py @@ -33,11 +33,11 @@ def test_phidlXOR(): TOP1 = phidlib.box() TOP2 = pg.import_gds(ref_file) TOP_different = phidlib.box(width=100) - for geom_hash in [True, False]: - XOR = xor_polygons_phidl(TOP1, TOP2, geom_hash=geom_hash) + for hash_geom in [True, False]: + XOR = xor_polygons_phidl(TOP1, TOP2, hash_geom=hash_geom) if len(XOR.elements) > 0: raise GeometryDifference("Differences found between phidl Devices.") - XOR_different = xor_polygons_phidl(TOP_different, TOP2, geom_hash=geom_hash) + XOR_different = xor_polygons_phidl(TOP_different, TOP2, hash_geom=hash_geom) assert len(XOR_different.elements) > 0