def main(): c = mzi2x2() h0 = c.hash_geometry() gdspath1 = "{}.gds".format(c.name) gdspath2 = "{}_2.gds".format(c.name) gdspath3 = "{}_3.gds".format(c.name) pp.write_gds(c, gdspath1) c1 = pp.import_gds(gdspath1, overwrite_cache=True) dh1 = hash_cells(c1, {}, dbg=True) h1 = dh1[c1.name] pp.write_gds(c1, gdspath2) print(h0) c2 = pp.import_gds(gdspath2, overwrite_cache=True) dh2 = hash_cells(c2, {}, dbg=True) h2 = dh2[c2.name] pp.write_gds(c2, gdspath3) c3 = pp.import_gds(gdspath3, overwrite_cache=True) dh3 = hash_cells(c3, {}, dbg=True) h3 = dh3[c3.name] print(dh2) print() print() print(dh3) print() print() print(h1) print(h2) print(h3) print() print(gdspy.gdsii_hash(gdspath1)) print(gdspy.gdsii_hash(gdspath2)) print(gdspy.gdsii_hash(gdspath3))
def test_gdsii_hash(library, tmpdir): out1 = str(tmpdir.join("test1.gds")) out2 = str(tmpdir.join("test2.gds")) library.write_gds(out1) library.write_gds(out2, timestamp=datetime.datetime.today() + datetime.timedelta(1)) assert gdspy.gdsii_hash(out1) == gdspy.gdsii_hash(out2)
def compare_component_hash( component_type, component_type2factory=component_type2factory, path_library=CONFIG["gdslib"], path_test=CONFIG["gdslib_test"], ): """ raises Exception if component has changed from the library writes component if it does not exist Args: component_type: path_library: path_test: """ component_new = lock_component( component_type, component_type2factory=component_type2factory, path_library=path_test, ) component_new.name += "_new" gdspath_new = path_test / (component_type + ".gds") gdspath_library = path_library / (component_type + ".gds") if not os.path.isfile(gdspath_library): lock_component( component_type=component_type, component_type2factory=component_type2factory, path_library=path_library, ) print(f"writing new component {component_type} into {path_library}") return component_library = pp.load_component(component_name=component_type, component_path=path_library) component_library.name += "_lib" gdshash_new = gdspy.gdsii_hash(gdspath_new) gdshash_library = gdspy.gdsii_hash(gdspath_library) # gdshash_new = component_library.hash_geometry() # gdshash_library = component_new.hash_geometry() same_hash = gdshash_new == gdshash_library if not same_hash: error_hash = f"`{component_library}` hash(GDS) {gdspath_new} differs from the library {gdspath_library}, showing both cells in Klayout \n" error_settings = f"different settings: {diff(component_library.get_settings(), component_new.get_settings())}" c = pp.Component(name=component_type) c << component_new c << component_library pp.show(c) print(error_hash + error_settings) return same_hash