def from_gds(gdspath: Union[str, Path], **kwargs) -> Component: """Returns Component with ports and metadata (YAML) info (if any). Args: gdspath: path of GDS file cellname: cell of the name to import (None) imports top cell flatten: if True returns flattened (no hierarchy) snap_to_grid_nm: snap to different nm grid (does not snap if False) """ gdspath = Path(gdspath) metadata_filepath = gdspath.with_suffix(".yml") if not gdspath.exists(): raise FileNotFoundError(f"No such file '{gdspath}'") component = import_gds(gdspath) metadata = OmegaConf.load(metadata_filepath) for port_name, port in metadata.ports.items(): component.add_port( name=port_name, midpoint=port.midpoint, width=port.width, orientation=port.orientation, layer=port.layer, port_type=port.port_type, ) component.info = metadata.info return component
def remove_empty_cells(gds: Union[str, Path], recursive: bool = True, recurse_depth: int = 0): """Returns the list cells to cells.""" if isinstance(gds, (str, Path)): gds = import_gds(gds) cells = gds.get_dependencies(recursive=True) cells_to_remove = [] for c in cells: if is_empty(c): cells_to_remove += [c] for c in cells_to_remove: print(c.name) remove_cell(gds, c.name) if recursive: while (len(cells_to_remove)) > 0: print(recurse_depth) sys.stdout.flush() cells_to_remove = remove_empty_cells(gds, recursive=True, recurse_depth=recurse_depth + 1) return cells_to_remove
def gdsdiff( component1: Union[Path, Component, str], component2: Union[Path, Component, str], name: str = "TOP", xor: bool = True, ) -> Component: """Compare two Components. Args: component1: Component or path to gds file component2: Component or path to gds file name: name of the top cell xor: makes boolean operation Returns: Component with both cells (xor, common and diffs) """ if isinstance(component1, pathlib.Path): component1 = str(component1) if isinstance(component2, pathlib.Path): component2 = str(component2) if isinstance(component1, str): component1 = import_gds(component1, flatten=True) if isinstance(component2, str): component2 = import_gds(component2, flatten=True) top = Component(name=f"{name}_diffs") if component1.name.startswith("Unnamed"): component1.name = f"{name}_old" if component2.name.startswith("Unnamed"): component2.name = f"{name}_new" ref1 = top << component1 ref2 = top << component2 ref1.xmin = 0 ref1.ymin = 0 ref2.xmin = 0 ref2.ymin = 0 if xor: diff = xor_polygons(ref1, ref2, hash_geometry=False) diff.name = f"{name}_xor" top.add_ref(diff) return top
def test_components_ports( gdspath: Path, num_regression: NumericRegressionFixture ) -> None: c = import_gds(gdspath) add_ports_from_markers_center(c) auto_rename_ports(c) if num_regression: num_regression.check(c.get_ports_array())
def test_import_gds_snap_to_grid() -> None: gdspath = gf.CONFIG["gdsdir"] / "mmi1x2.gds" c = import_gds(gdspath, snap_to_grid_nm=5) assert len(c.get_polygons()) == 8, len(c.get_polygons()) for x, y in c.get_polygons()[0]: assert gf.snap.is_on_grid(x, 5) assert gf.snap.is_on_grid(y, 5)
def from_gdspaths(cells: Iterable[ComponentOrPath]) -> Component: """Combine all GDS files or gf.components into a gf.component. Args: cells: List of gdspaths or Components """ c = Component() for cell in cells: if not isinstance(cell, Component): cell = import_gds(cell) c << cell return c
import gdsfactory as gf from gdsfactory.import_gds import add_ports_from_markers_center, import_gds from gdsfactory.port import auto_rename_ports gdspaths = [gf.CONFIG["gdsdir"] / name for name in ["mmi1x2.gds", "mzi2x2.gds"]] @pytest.mark.parametrize("gdspath", gdspaths) def test_components_ports( gdspath: Path, num_regression: NumericRegressionFixture ) -> None: c = import_gds(gdspath) add_ports_from_markers_center(c) auto_rename_ports(c) if num_regression: num_regression.check(c.get_ports_array()) if __name__ == "__main__": c = import_gds(gdspaths[0]) add_ports_from_markers_center(c) auto_rename_ports(c) print(c.ports.keys()) print(c.name) c = import_gds(gdspaths[1]) add_ports_from_markers_center(c) auto_rename_ports(c) print(c.ports.keys()) print(c.name)
def remove_empty_cells_from_gds_file(gdspath): component = import_gds(gdspath) remove_empty_cells(component) component.write_gds(gdspath[:-4] + "_cleaned.gds")
def test_import_gds_hierarchy() -> None: c0 = gf.components.mzi() gdspath = c0.write_gds() c = import_gds(gdspath) assert len(c.get_dependencies()) == 3, len(c.get_dependencies())