Skip to content

Commit

Permalink
autograd can test angled waveguide
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflex authored and momchil-flex committed Nov 27, 2024
1 parent 0ff0e60 commit 946bcf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 16 additions & 9 deletions tests/test_components/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@

IS_3D = False

# TODO: test 2D and 3D parameterized
# angle of the measurement waveguide
ROT_ANGLE_WG = 0 * np.pi / 4

# position of output mode monitor
MODE_FIELD_SPC = 0.75
MODE_FLD_MNT_SPC = MODE_FIELD_SPC * WVL

LX = 0.5 * WVL if IS_3D else 0.0
PML_X = True if IS_3D else False


# shape of the custom medium
DA_SHAPE_X = 1 if IS_3D else 1
DA_SHAPE = (DA_SHAPE_X, 1_000, 1_000) if TEST_CUSTOM_MEDIUM_SPEED else (DA_SHAPE_X, 12, 12)
Expand Down Expand Up @@ -114,8 +118,10 @@
td.Structure(
geometry=td.Box(
size=(0.5, 0.5, LZ / 2),
center=(0, 0, LZ / 2),
),
center=(0, 0, 0),
)
.rotated(ROT_ANGLE_WG, axis=0)
.translated(x=0, y=-np.tan(ROT_ANGLE_WG) * MODE_FIELD_SPC, z=LZ / 2),
medium=td.Medium(permittivity=2.0),
)
],
Expand Down Expand Up @@ -433,12 +439,13 @@ def make_structures(params: anp.ndarray) -> dict[str, td.Structure]:
def make_monitors() -> dict[str, tuple[td.Monitor, typing.Callable[[td.SimulationData], float]]]:
"""Make a dictionary of all the possible monitors in the simulation."""

X = 0.75

mode_mnt = td.ModeMonitor(
size=(2, 2, 0),
center=(0, 0, +LZ / 2 - X * WVL),
mode_spec=td.ModeSpec(),
center=(0, 0, +LZ / 2 - MODE_FIELD_SPC),
mode_spec=td.ModeSpec(
angle_theta=ROT_ANGLE_WG,
angle_phi=3 * np.pi / 2,
),
freqs=[FREQ0],
name="mode",
)
Expand All @@ -459,7 +466,7 @@ def diff_postprocess_fn(sim_data, mnt_data):

field_vol = td.FieldMonitor(
size=(1, 1, 0),
center=(0, 0, +LZ / 2 - X * WVL),
center=(0, 0, +LZ / 2 - MODE_FIELD_SPC),
freqs=[FREQ0],
name="field_vol",
)
Expand Down
6 changes: 0 additions & 6 deletions tidy3d/web/api/autograd/autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
SIM_VJP_FILE = "output/autograd_sim_vjp.hdf5"
SIM_FIELDS_KEYS_FILE = "autograd_sim_fields_keys.hdf5"

ISSUE_URL = (
"https://github.com/flexcompute/tidy3d/issues/new?"
"assignees=tylerflex&labels=adjoint&projects=&template=autograd_bug.md"
)
URL_LINK = f"[blue underline][link={ISSUE_URL}]'{ISSUE_URL}'[/link][/blue underline]"

MAX_NUM_TRACED_STRUCTURES = 500

# default value for whether to do local gradient calculation (True) or server side (False)
Expand Down

0 comments on commit 946bcf1

Please sign in to comment.