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

add Structure.background_medium and deprecate background_permittivity #2069

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `CustomMedium` design regions require far less data when performing inverse design by reducing adjoint field monitor size for dims with one pixel.
- Calling `.values` on `DataArray` no longer raises a `DeprecationWarning` during automatic differentiation.
- Minimum number of PML layers set to 6.
- `Structure.background_permittivity : float` for specifying background medium for shape differentiation deprecated in favor of `Structure.background_medium : Medium` for more generality.

### Fixed
- Regression in local field projection leading to incorrect results for `far_field_approx=True`.
Expand Down
72 changes: 36 additions & 36 deletions tests/sims/simulation_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"length": 1.0
},
"name": "traced_dieletric_cylinder",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -73,7 +73,7 @@
]
},
"name": "traced_dieletric_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -117,7 +117,7 @@
]
},
"name": "traced custom polyslab",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -152,7 +152,7 @@
]
},
"name": "dieletric_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -184,7 +184,7 @@
]
},
"name": "lossy_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -212,7 +212,7 @@
]
},
"name": "sellmeier_sphere",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -252,7 +252,7 @@
]
},
"name": "lorentz_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -290,7 +290,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -322,7 +322,7 @@
}
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -359,7 +359,7 @@
]
},
"name": "drude_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -396,7 +396,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -472,7 +472,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -522,7 +522,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -592,7 +592,7 @@
]
},
"name": "pec_group",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -622,7 +622,7 @@
"length": 2.0
},
"name": "anisotopic_cylinder",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -700,7 +700,7 @@
]
},
"name": "pole_slab",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -743,7 +743,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -778,7 +778,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -817,7 +817,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -857,7 +857,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -896,7 +896,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -935,7 +935,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -973,7 +973,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1014,7 +1014,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1071,7 +1071,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1135,7 +1135,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1192,7 +1192,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1249,7 +1249,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1299,7 +1299,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1336,7 +1336,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1414,7 +1414,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1452,7 +1452,7 @@
}
},
"name": "dieletric_mesh",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1494,7 +1494,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1545,7 +1545,7 @@
}
},
"name": "clip_operation",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -1607,7 +1607,7 @@
]
},
"name": "transformed_box",
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down Expand Up @@ -2842,7 +2842,7 @@
]
},
"name": null,
"background_permittivity": null,
"background_medium": null,
"type": "Structure",
"medium": {
"attrs": {},
Expand Down
51 changes: 50 additions & 1 deletion tests/test_components/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def make_structures(params: anp.ndarray) -> dict[str, td.Structure]:
size_element = td.Structure(
geometry=td.Box(center=(0, 0, 0), size=(1, size_y, 1)),
medium=med,
background_permittivity=5.0,
background_medium=td.Medium(permittivity=5.0),
)

# custom medium with variable permittivity data
Expand Down Expand Up @@ -1710,6 +1710,55 @@ def objective(params):
g = ag.grad(objective)(params0)


def test_background_medium(log_capture):
geo = td.Box(size=(1, 1, 1), center=(0, 0, 0))
med = td.Medium(permittivity=2.0)

background_permittivity = 5.0
background_medium = td.Medium(permittivity=background_permittivity)

# nothing
s = td.Structure(
geometry=geo,
medium=med,
)

# both supplied, consistent
td.Structure(
geometry=geo,
medium=med,
background_permittivity=background_permittivity,
background_medium=background_medium,
)

# both supplied, inconsistent
with pytest.raises(ValueError):
td.Structure(
geometry=geo,
medium=med,
background_permittivity=background_permittivity + 1,
background_medium=background_medium,
)

# background medium (preferred)
s = td.Structure(
geometry=geo,
medium=med,
background_medium=background_medium,
)

# background permittivity (deprecated)
with AssertLogLevel(log_capture, "WARNING", contains_str="deprecated"):
s_warn = td.Structure(
geometry=geo,
medium=med,
background_permittivity=background_permittivity,
)

assert s_warn.background_medium is not None
assert s_warn.background_medium.permittivity == background_permittivity


class TestTidyArrayBox:
def test_is_tidy_box(self):
da = DataArray(tracer_arr, dims=map(str, range(tracer_arr.ndim)))
Expand Down
Loading
Loading