-
Notifications
You must be signed in to change notification settings - Fork 6
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
WI ensuring runnable code #50
WI ensuring runnable code #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See specific comments :)
…ion for compute spectrum, with a parameter solver in cfg that decides whether to use rcwa or fdtd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments, note you have merge conflict atm ;)
nidn/fdtd_integration/calculate_transmission_reflection_coefficients.py
Outdated
Show resolved
Hide resolved
nidn/fdtd_integration/init_fdtd.py
Outdated
grid = _add_object( | ||
grid, | ||
int( | ||
cfg.FDTD_pml_thickness * scaling | ||
+ cfg.FDTD_free_space_distance * scaling | ||
+ i * scaling * cfg.FDTD_per_layer_thickness | ||
scaling | ||
* ( | ||
cfg.FDTD_pml_thickness | ||
+ cfg.FDTD_free_space_distance | ||
+ i * cfg.FDTD_per_layer_thickness | ||
) | ||
), | ||
int( | ||
cfg.FDTD_pml_thickness * scaling | ||
+ cfg.FDTD_free_space_distance * scaling | ||
+ (i + 1) * scaling * cfg.FDTD_per_layer_thickness | ||
scaling | ||
* ( | ||
cfg.FDTD_pml_thickness | ||
+ cfg.FDTD_free_space_distance | ||
+ (i + 1) * cfg.FDTD_per_layer_thickness | ||
) | ||
), | ||
permittivity[i], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super hard to read and understand, please untangle a bit and explain the positions
# We want to place the detector at (...). Therefore it has to be (...)
transmission_detector_x = scaling
* (
cfg.FDTD_pml_thickness
+ cfg.FDTD_free_space_distance
+ i * cfg.FDTD_per_layer_thickness
)
(...)
grid = _add_object(grid,transmission_detector_x ,reflection_detector_x )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally same for
grid, t_detector, r_detector = _add_detectors(
grid,
int(
scaling
* (
cfg.FDTD_reflection_detector_x
+ cfg.N_layers * cfg.FDTD_per_layer_thickness
)
),
int(cfg.FDTD_reflection_detector_x * scaling),
)
above
nidn/utils/compute_spectrum.py
Outdated
Array, Array: Reflection spectrumand transmission spectrum | ||
""" | ||
if cfg.solver == "FDTD": | ||
return compute_spectrum_fdtd(eps_grid[0, 0, :, 0].real, cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be right. Materials can have complex permittivity? Also, the permittivity depends on frequency so you cannot throw away the last dimension. Further, can there be patterns on the grid in FDTD? If not then you always need to set Nx = 1, Ny = 1 for FDTD and this should be asserted here instead of just throwing away the other dimensions.
Ideally, do the following here:
- Pass full eps_grid
- Use appropriate eps for appropriate wl (not throwing away last dim)
- Check that eps_grid first two dimension have len 1 and raise an exception (unless it supports patterned layers?). For ( you can just use
assert eps_grid.shape[0] == 1
andassert eps_grid.shape[1] == run_cfg.Ny
) .
As a general note: Never write code that fails silently. If you give it a patterned layer with the wrong frequencies this code will still run and you won't notice. This is a recipe for horrible bugs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(e.g. see also how the other compute spectrum handles this
NIDN/nidn/trcwa/compute_spectrum.py
Line 25 in 98112c7
logger.debug("Testing input for NaNs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small addendum,I think you can have patterned objects? https://github.com/flaport/fdtd#adding-an-object-to-the-grid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think I can, but maybe leave this out for now as I think it will take some time to implement in a smooth way?
… into WI_ensuring_runnable_code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some small comments, very minor changes
@@ -325,28 +326,28 @@ def update_H(self): | |||
det.detect_H() | |||
|
|||
def reset(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, seeing as you haven't run black on the entire thing yet (it seems) maybe run in CLI once black .
to format all the new code automatically :)
@@ -28,13 +26,16 @@ def compute_spectrum_fdtd(permittivity, cfg: DotMap): | |||
|
|||
# For each wavelength, calculate transmission and reflection coefficents | |||
|
|||
for w in tqdm(physical_wavelengths): | |||
for i in tqdm(range(len(physical_wavelengths))): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this progressbar will always show. I don't think we want that when training a neural net. You can make it optional by having a variable like this
disable_progress_bar = logger._core.min_level >= 20
for i in tqdm(range(len(physical_wavelengths)),disable=disable_progress_bar ):
(...)
then it will only show on DEBUG or TRACE (it's a bit of a hack but loguru doesn't seem to easily over the loglevel :S
nidn/fdtd_integration/init_fdtd.py
Outdated
grid[0:pml_thickness, :, :] = fdtd.PML( | ||
name="pml_xlow" | ||
) # Add PML boundary to the left side of the grid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grid[0:pml_thickness, :, :] = fdtd.PML( | |
name="pml_xlow" | |
) # Add PML boundary to the left side of the grid | |
# Add PML boundary to the left side of the grid | |
grid[0:pml_thickness, :, :] = fdtd.PML(name="pml_xlow") |
If you move the comment above the line it won't do the weird line breaks I think. (Also below)
nidn/utils/global_constants.py
Outdated
UNIT_MAGNITUDE = 10 ** (-6) | ||
|
||
MU_0: float = 4e-7 * PI | ||
""" vacuum permeability """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put the comment in the line above not below :)
…bsolute to relative to the grid, added some logging and some formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two very minimal changes, feel to merge afterwards
nidn/fdtd_integration/init_fdtd.py
Outdated
@@ -1,5 +1,6 @@ | |||
from dotmap import DotMap | |||
import fdtd | |||
from scipy.fft import set_backend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you use this import?
nidn/utils/global_constants.py
Outdated
M_E = 9.1093837015 * 10 ** (-31) | ||
# Free space permittivity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Free space permittivity | |
# Vacuum permittivity |
This is vacuum I think, right? (free space could also be interpreted as air maybe?)
Description
Summary of changes
Resolved Issues