Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gm.get_meep_adjoint_optimizer function #477

Open
kdotom opened this issue Aug 23, 2024 · 3 comments
Open

gm.get_meep_adjoint_optimizer function #477

kdotom opened this issue Aug 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@kdotom
Copy link
Contributor

kdotom commented Aug 23, 2024

Describe the bug
/path/to/miniconda3/envs/mp/lib/python3.11/site-packages/gplugins/gmeep/meep_adjoint_optimization.py:148: UserWarning: Settingrectangle_S5_5_LWG_CFal_d89a89d8_2500_2500.centerin um is deprecated and will change to DataBaseUnits in gdsfactory9. Please userectangle_S5_5_LWG_CFal_d89a89d8_2500_2500.dcenterinstead.

To Reproduce

import gdsfactory as gf
import gplugins as gp
import gplugins.gmeep as gm
import numpy as np
import meep as mp
from meep import MaterialGrid, Medium, Vector3, Volume
from meep.adjoint import (
    conic_filter,
    DesignRegion,
    get_conic_radius_from_eta_e,
    tanh_projection,
)

#### Demo to reproduce bug
Nx = 50
Ny = 50

c = gf.Component()
wg = c << gf.components.straight(layer=(1,0),width=0.5,length=10)

design_variables = mp.MaterialGrid(mp.Vector3(Nx, Ny), mp.Medium(index=1.444), mp.Medium(index=3.45), grid_type="U_MEAN")
design_region = \
    DesignRegion(
        design_variables,
        volume=Volume(
            center=Vector3(),
            size=Vector3(5, 5, 0),
        ),
    )

seed = 240
np.random.seed(seed)
x0 = np.random.rand(
        Nx * Ny,
    )

c.add_port("o1", port=wg.ports["o1"]) # assign ports to component
c.add_port("o2", port=wg.ports["o2"]) # assign ports to component


def J1(o1, o2):
    criterion = npa.abs(o2/o1)
    return criterion


gm.get_meep_adjoint_optimizer(
    c,
    J1,
    [design_region],
    [design_variables],
    x0,
    resolution=10,
    cell_size=(
        10,
        10,
    ),
    tpml=1.0,
    extend_ports_length=0,
    port_margin=1,
    port_source_name=f"o1",
    port_source_offset=-1.5,
    port_monitor_offset=-1.5,
    distance_source_to_monitors=1,
)

Expected behavior
Warning should not occur and design with a waveguide and design region (properly sized) should be produced.

Suggested fix
Potentially, Change block.center to block.dcenter on line 148 of path/to/site-packages/gplugins/gmeep/meep_adjoint_optimization.py
I haven't updated this as I'm not sure how changes will propagate through the gmeep library, given the new units update.

@kdotom kdotom added the bug Something isn't working label Aug 23, 2024
@joamatab
Copy link
Contributor

@simbilod

if you have some time maybe you can take a look at the meep plugin

@kdotom
Copy link
Contributor Author

kdotom commented Oct 17, 2024

@simbilod If you need backup on the updates, let me know. I could probably put something together; I just want to make sure it lines up with any scaling changes you guys have in mind for future versions.

@simbilod
Copy link
Collaborator

Hi @kdotom , I actually don't use MEEP anymore so if you have ideas on how to improve the plugin feel free to make any changes you see fit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants