Esempio n. 1
0
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)
Esempio n. 2
0
def test_kerr(tmpdir):
    folder = os.path.join(tmpdir, 'kerr_test_results')
    _copyfiles(CUR_DIR, folder, ["sim_fg_kerr.gds", "sim_bg_kerr.gds"])

    sim_space = kerr.create_sim_space("sim_fg_kerr.gds", "sim_bg_kerr.gds")
    obj, monitors = kerr.create_objective(sim_space)
    trans_list = kerr.create_transformations(
        obj, monitors, sim_space, cont_iters=20, min_feature=100)
    plan = optplan.OptimizationPlan(transformations=trans_list)
    problem_graph.run_plan(plan, folder)
Esempio n. 3
0
def test_wdm2(tmpdir):
    folder = str(tmpdir.mkdir("wdm2"))
    _copyfiles(CUR_DIR, folder, ["sim_fg.gds", "sim_bg.gds"])

    sim_space = wdm2.create_sim_space("sim_fg.gds", "sim_bg.gds")
    obj, monitors = wdm2.create_objective(sim_space)
    trans_list = wdm2.create_transformations(obj,
                                             monitors,
                                             sim_space,
                                             cont_iters=1,
                                             min_feature=100)
    plan = optplan.OptimizationPlan(transformations=trans_list)
    problem_graph.run_plan(plan, folder)
Esempio n. 4
0
def test_phc(tmpdir):
    folder = os.path.join(tmpdir, 'phc_gvd_test')
    fg = "sim_fg_rect.gds"
    bg = "sim_bg_rect.gds"
    _copyfiles(CUR_DIR, folder, [fg, bg])

    sim_space = phc_rect.create_sim_space(fg, bg)
    obj, monitors = phc_rect.create_objective(sim_space)
    trans_list = phc_rect.create_transformations(obj,
                                                 monitors,
                                                 sim_space,
                                                 cont_iters=42,
                                                 min_feature=60,
                                                 num_stages=6)
    plan = optplan.OptimizationPlan(transformations=trans_list)
    problem_graph.run_plan(plan, folder)
Esempio n. 5
0
def resume_opt(save_folder: str) -> None:
    """Resumes a stopped optimization.

    This restarts an optimization that was stopped prematurely. Note that
    resuming an optimization will not lead the exact same results as if the
    optimization were finished the first time around.

    Args:
        save_folder: Location where log files are saved. It is assumed that
            the optimization plan is also saved there.
    """
    # Load the optimization plan.
    with open(os.path.join(save_folder, "optplan.json")) as fp:
        plan = optplan.loads(fp.read())

    # Run the plan with the `resume` flag to restart.
    problem_graph.run_plan(plan, ".", save_folder=save_folder, resume=True)
Esempio n. 6
0
def test_phase(tmpdir):
    folder = os.path.join(tmpdir, 'GVD_test_wg')
    _copyfiles(CUR_DIR, folder, ["sim_fg_wg.gds", "sim_bg_wg.gds"])

    sim_space = phase.create_sim_space("sim_fg_wg.gds", "sim_bg_wg.gds")
    obj, power_obj, monitors = phase.create_objective(sim_space)
    trans_list = phase.create_transformations(obj,
                                              monitors,
                                              sim_space,
                                              cont_iters=80,
                                              min_feature=40,
                                              num_stages=4)
    # power_obj=power_obj, power_iters=6, power_stages=2)
    plan = optplan.OptimizationPlan(transformations=trans_list)
    # with open("plan_dump.json", "w") as plan_dump_file:
    #     plan_dump_file.write(optplan.dumps(plan))
    problem_graph.run_plan(plan, folder)
Esempio n. 7
0
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)
Esempio n. 8
0
def test_grating(tmpdir):
    folder = str(tmpdir.mkdir("grating"))
    _copyfiles(CUR_DIR, folder, ["sim_fg.gds", "sim_bg.gds"])

    sim_space = grating.create_sim_space(os.path.join(folder, "sim_fg.gds"),
                                         os.path.join(folder, "sim_bg.gds"),
                                         box_thickness=2000,
                                         wg_thickness=220,
                                         etch_frac=0.5)
    obj, monitors = grating.create_objective(sim_space)
    trans_list = grating.create_transformations(obj,
                                                monitors,
                                                1,
                                                2,
                                                sim_space,
                                                min_feature=100)
    plan = optplan.OptimizationPlan(transformations=trans_list)

    problem_graph.run_plan(plan, folder)
Esempio n. 9
0
def main() -> None:
    """Runs the optimization."""
    # Create the simulation space using the GDS files.
    sim_space = create_sim_space("sim_fg.gds", "sim_bg.gds")

    # Setup the objectives and all values that should be recorded (monitors).
    obj, monitors = create_objective(sim_space)

    # Create the list of operations that should be performed during
    # optimization. In this case, we use a series of continuous parametrizations
    # that approximate a discrete structure.
    trans_list = create_transformations(
        obj, monitors, sim_space, cont_iters=100, min_feature=100)

    # 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). By default, all log files produced
    # during the optimization are also saved here. This can be changed by
    # passing in a third optional argument.
    plan = optplan.OptimizationPlan(transformations=trans_list)
    problem_graph.run_plan(plan, ".")
Esempio n. 10
0
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)