def test_dumps_duplicate_name_raises_value_error(): plan = optplan.OptimizationPlan( nodes=[ optplan.Sum( functions=[ optplan.Constant( name="const", value=optplan.ComplexNumber(real=2)), optplan.Constant( name="const", value=optplan.ComplexNumber(real=3)), ],) ],) with pytest.raises(ValueError, match="Nonunique name found"): optplan.dumps(plan)
def run_opt(save_folder: str) -> None: """Main optimization script. This function setups the optimization and executes it. Args: save_folder: Location to save the optimization data. """ os.makedirs(save_folder) sim_space = create_sim_space("sim_fg.gds", "sim_bg.gds", box_thickness=2000, wg_thickness=220, etch_frac=0.5) obj, monitors = create_objective(sim_space) trans_list = create_transformations(obj, monitors, 50, 200, sim_space, min_feature=100) plan = optplan.OptimizationPlan(transformations=trans_list) # Save the optimization plan so we have an exact record of all the # parameters. with open(os.path.join(save_folder, "optplan.json"), "w") as fp: fp.write(optplan.dumps(plan)) # Execute the optimization and indicate that the current folder (".") is # the project folder. The project folder is the root folder for any # auxiliary files (e.g. GDS files). problem_graph.run_plan(plan, ".", save_folder=save_folder)
def test_dumps(): plan = optplan.OptimizationPlan( nodes=[ optplan.Sum( functions=[ optplan.Constant(value=optplan.ComplexNumber(real=2)), optplan.Constant(value=optplan.ComplexNumber(real=3)), ],) ],) plan_dict = json.loads(optplan.dumps(plan))
def test_custom_function_node(): @optplan.register_node_type(optplan.NodeMetaType.OPTPLAN_NODE) class CustomOp(optplan.Function): type = schema_utils.polymorphic_model_type("custom_op") int_val = types.IntType() plan = optplan.OptimizationPlan( nodes=[ optplan.Sum( functions=[ optplan.Constant(value=optplan.ComplexNumber(real=2)), CustomOp(int_val=3), ],) ],) optplan.loads(optplan.dumps(plan))
def run_opt(save_folder: str) -> None: """Main optimization script. This function setups the optimization and executes it. Args: save_folder: Location to save the optimization data. """ # os.makedirs(save_folder) os.makedirs(save_folder, exist_ok=True) sim_space = create_sim_space("sim_fg.gds", "sim_bg.gds", wg_thickness=wg_thickness, wg_length=wg_length, wg_width=wg_width, buffer_len=buffer_len, dx=dx, num_pmls=num_pmls) obj, monitors = create_objective(sim_space, wg_thickness=wg_thickness, wg_length=wg_length, wg_width=wg_width, buffer_len=buffer_len, dx=dx, num_pmls=num_pmls) trans_list = create_transformations(obj, monitors, sim_space, 200, num_stages=5, min_feature=100) plan = optplan.OptimizationPlan(transformations=trans_list) # Save the optimization plan so we have an exact record of all the # parameters. with open(os.path.join(save_folder, "optplan.json"), "w") as fp: fp.write(optplan.dumps(plan)) # Copy over the GDS files. shutil.copyfile("sim_fg.gds", os.path.join(save_folder, "sim_fg.gds")) shutil.copyfile("sim_bg.gds", os.path.join(save_folder, "sim_bg.gds")) # Execute the optimization and indicate that the current folder (".") is # the project folder. The project folder is the root folder for any # auxiliary files (e.g. GDS files). problem_graph.run_plan(plan, ".", save_folder=save_folder)
def run_opt(save_folder: str, sim_width: float, wg_width: float) -> None: """Main optimization script. This function setups the optimization and executes it. Args: save_folder: Location to save the optimization data. """ os.makedirs(save_folder) sim_space = create_sim_space("sim_fg.gds", "sim_bg.gds", sim_width=sim_width, wg_width=wg_width) obj, monitors = create_objective(sim_space, sim_width=sim_width, wg_width=wg_width) # or a grating length trans_list = create_transformations(obj, monitors, 60, 200, sim_space, min_feature=100) plan = optplan.OptimizationPlan(transformations=trans_list) # Save the optimization plan so we have an exact record of all the # parameters. with open(os.path.join(save_folder, "optplan.json"), "w") as fp: fp.write(optplan.dumps(plan)) # Copy over the GDS files. shutil.copyfile("sim_fg.gds", os.path.join(save_folder, "sim_fg.gds")) shutil.copyfile("sim_bg.gds", os.path.join(save_folder, "sim_bg.gds")) # Execute the optimization and indicate that the current folder (".") is # the project folder. The project folder is the root folder for any # auxiliary files (e.g. GDS files). problem_graph.run_plan(plan, ".", save_folder=save_folder) # Generate the GDS file. gen_gds(save_folder, sim_width, wg_width)
def test_dump_and_load(): plan = generate_wdm_2d() serialized_plan = optplan.dumps(plan) deserialized_plan = optplan.loads(serialized_plan)