def write_doe_from_yaml(yaml): """Loads DOE settings from yaml and writes GDS into build_directory Args: filepath: YAML string or filepath describing DOEs Returns: gdspaths: list For each DOE save: - GDS - json metadata - ports CSV - markdown report, with DOE settings """ yaml = io.StringIO(yaml) if isinstance(yaml, str) and "\n" in yaml else yaml does = load_does(yaml) gdspaths = [] for doe_name, doe in does.items(): # print(doe_name) # print(doe.get("settings")) # print(doe.get("do_permutations")) # print(doe) # print(list(doe.keys())) # print(type(doe.get('settings'))) # assert type(doe.get('settings')) d = write_doe( component_type=doe.get("component"), doe_name=doe_name, do_permutations=doe.get("do_permutations", True), list_settings=doe.get("settings"), description=doe.get("description"), analysis=doe.get("analysis"), test=doe.get("test"), functions=doe.get("functions"), ) gdspaths.append(d) return gdspaths
def build_does(filepath, component_factory=component_factory): """ this function is depreacted Writes DOE settings from config.yml file and writes GDS into build_directory If you want to use cache use pp.generate_does instead Write For each DOE: - GDS - json metadata - ports CSV - markdown report, with DOE settings """ does = load_does(filepath) doe_names = does.keys() doe_params = zip(doe_names, itertools.repeat(filepath), itertools.repeat(component_factory)) p = multiprocessing.Pool(multiprocessing.cpu_count()) p.starmap(_build_doe, doe_params)
def build_does(config=CONFIG, component_type2factory=component_type2factory): """ Writes DOE settings from config.yml file and writes GDS into build_directory If you want to use cache use pp.generate_does instead Write For each DOE: - GDS - json metadata - ports CSV - markdown report, with DOE settings """ if config.get("does") is None: raise ValueError(f"no does defined in {CONFIG}") does = load_does(config) doe_names = does.keys() doe_params = zip(doe_names, itertools.repeat(config), itertools.repeat(component_type2factory)) p = multiprocessing.Pool(multiprocessing.cpu_count()) p.starmap(_build_doe, doe_params)
def write_doe_from_yaml(config=CONFIG): """ Loads DOE settings from yaml file and writes GDS into build_directory Args: filepath: YAML file describing DOE add_io_function: default add_io_optical For each DOE save: - GDS - json metadata - ports CSV - markdown report, with DOE settings """ does = load_does(config) gds_paths = [] for doe_name, doe in does.items(): # print(doe_name) # print(doe.get("settings")) # print(doe.get("do_permutations")) # print(doe) # print(list(doe.keys())) # print(type(doe.get('settings'))) # assert type(doe.get('settings')) d = write_doe( component_type=doe.get("component"), doe_name=doe_name, do_permutations=doe.get("do_permutations", True), list_settings=doe.get("settings"), description=doe.get("description"), analysis=doe.get("analysis"), test=doe.get("test"), functions=doe.get("functions"), ) gds_paths.append(d) return gds_paths
def component_grid_from_yaml(filepath, precision=1e-9): """ Returns a Component composed of DOEs/components given in a yaml file allows for each DOE to have its own x and y spacing (more flexible than method1) """ input_does = OmegaConf.load(str(filepath)) mask_settings = input_does["mask"] does = load_does(filepath) placed_doe = None placed_does = {} if mask_settings.get("name"): component_grid = pp.Component(mask_settings["name"]) else: component_grid = pp.Component() default_cache_enabled = ( mask_settings["cache_enabled"] if "cache_enabled" in mask_settings else False ) for doe_name, doe in does.items(): list_settings = doe["settings"] component_type = doe["component"] # description = doe["description"] if "description" in doe else '' # test = doe["test"] if "test" in doe else {} # analysis = doe["analysis"] if "analysis" in doe else {} # Get DOE policy concerning the cache cache_enabled = ( doe["cache_enabled"] if "cache_enabled" in doe else default_cache_enabled ) components = None # If cache enabled, attempt to load from cache if cache_enabled: try: components = load_doe_from_cache(doe_name) except Exception as e: _print(e) components = None # If no component is loaded, build them if components is None: print("{} - Generating components...".format(doe_name)) components = build_components(component_type, list_settings) # After building the components, if cache enabled, save them if cache_enabled: save_doe(doe_name, components, precision=precision) else: _print("{} - Loaded components from cache".format(doe_name)) # _print(doe_name, [c.name for c in components]) # Find placer information default_settings = {"align_x": "W", "align_y": "S", "margin": 10} if "placer" in doe: placer_type = doe["placer"].pop("type") _placer = PLACER_NAME2FUNC[placer_type] # All other attributes are assumed to be settings for the placer settings = default_settings.copy() settings.update(doe["placer"]) # x0, y0 can either be float or string x0 = settings.pop("x0") y0 = settings.pop("y0") # Check whether we are doing relative or absolute placement if (x0 in ["E", "W"] or y0 in ["N", "S"]) and not placed_doe: raise ValueError( "At least one DOE must be placed to use\ relative placement" ) # For relative placement (to previous DOE) if "margin_x" not in settings: settings["margin_x"] = settings["margin"] if "margin_y" not in settings: settings["margin_y"] = settings["margin"] margin_x = settings["margin_x"] margin_y = settings["margin_y"] align_x = settings["align_x"] align_y = settings["align_y"] ## Making sure that the alignment is sensible depending on how we stack # If we specify a DOE to place next to, use it if "next_to" in settings: placed_doe = placed_does[settings.pop("next_to")] # Otherwise, use previously placed DOE as starting point if x0 == "E": x0 = placed_doe.size_info.east if align_x == "W": x0 += margin_x if x0 == "W": x0 = placed_doe.size_info.west if align_x == "E": x0 -= margin_x if y0 == "N": y0 = placed_doe.size_info.north if align_y == "S": y0 += margin_y if y0 == "S": y0 = placed_doe.size_info.south if align_y == "N": y0 -= margin_y # Add x0, y0 in settings as float settings["x0"] = x0 settings["y0"] = y0 placed_components = _placer(components, **settings) else: # If no placer is specified, we assume this is a grid placer cols, rows = doe["shape"] x0, y0 = doe["origin"] dx, dy = doe["spacing"] placed_components = placer_grid_cell_refs( components, cols, rows, dx, dy, x0=x0, y0=y0 ) # Place components within a cell having the DOE name placed_doe = pp.Component() placed_doe.add(placed_components) placed_doe.name = doe_name placed_does[doe_name] = placed_doe # # Write the json and md metadata / report # write_doe_metadata( # doe_name=doe_name, # cells = placed_components, # list_settings=list_settings, # flag_write_component=False, # description=description, # test=test, # analysis=analysis # ) component_grid.add_ref(placed_doe) return component_grid