-
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 add tests #54
WI add tests #54
Conversation
Old tests don't work for me, I think in plot_spectra.py we are still using wrong imports ( (Works when that is fixed) |
Running the tests (after fixing the mentioned import) I get this warning
Please fix that :) (just follow the instructions from the warning I think) |
I think you are missing a test for |
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 comments, we are on the right way 💪 but need to check a bit more thoroughly to make sure we notice when things break
"FDTD_use_pulsesource", | ||
"FDTD_use_pointsource", |
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.
aren't these mutually exclusive? If so, shouldn't rather be something like FDTD_source_type = "pulse" or "point" ?
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.
No, the pulse is about continuous wave or not. point is about pointsource or linesource, both which can be continuous or have a pulse. But I can change the naming/structure for clarity
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.
Hmmm, well depends on the logic behind. "use_pointsource" to me sounds as if it is true I use a point source, otherwise I use none.
If it is like that fine, otherwise it should probably be sourcetype with FDTD_source_type="point" or "line"
Analogously for pulse
nidn/tests/fdtd_test.py
Outdated
from ..utils.compute_spectrum import compute_spectrum | ||
|
||
|
||
def test_fdtd_simulation(): |
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 write brief docstrings for each test describing what is tested, see e.g. here
Line 59 in 98112c7
"""Tests a single uniform layer at two frequencies. TRCWA vs. GRCWA""" |
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 quite the difference between this test and the init_fdtd_grid_test?
Maybe just make it one test called fdtd_test?
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 think fdtd_test can then have several subtests
test_init
uniform layer
4 uni
patterned
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 comments, we are on the right way 💪 but need to check a bit more thoroughly to make sure we notice when things break
…th updating validate config and added some more logging. Also fixed unnoticed errors in transmission detector placement
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 / changes, also tests are currently failing: see here https://github.com/esa/NIDN/runs/5371947251?check_suite_focus=true
signal_array, signal_array, "mean square", cfg | ||
) | ||
# TODO: Add test for fdtd, when the method is complete | ||
assert transmission_coefficient_ms - 0.25 == 0 |
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.
for completeness also check reflection_coefficient.
Would it make sense to check here also if they are all >= 0 and <= 1.0? ( We ought to have some way to deal with this in the code as well btw 🤔 But maybe can happen when you look into the FFT? (Does that have an issue btw? Then could add a todo there for checking that spectrum values are between 0 and 1 and throwing at least a warning if they aren't.)
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.
Do you think this should be done in the test, or in the compute_spectrum_fdtd function? (The check that all values are betweenn 0 and 1)
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 would still assert it here that they are all between 0 and 1. Doesn't hurt and serves as a sanity check if the check inside the codebase is accidentally circumvented
nidn/tests/fdtd_test.py
Outdated
transmission_spectrum, reflection_spectrum = compute_spectrum(eps_grid, cfg) | ||
validated_transmission_spectrum = [ | ||
tensor(0.0), | ||
tensor(0.5564), |
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.
that is not a lot of digits. Why not more precise values?
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 the output from running the compute_spectrum in my notebook, which I just copied. Can probably set higher precision for the output?
"FDTD_use_pulsesource", | ||
"FDTD_use_pointsource", |
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.
Hmmm, well depends on the logic behind. "use_pointsource" to me sounds as if it is true I use a point source, otherwise I use none.
If it is like that fine, otherwise it should probably be sourcetype with FDTD_source_type="point" or "line"
Analogously for pulse
…dded more precision to tests and added validation of coefficents
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 minor changes, feel free to merge once fixed (assuming unit tests are still passing and all ;) )
nidn/fdtd_integration/calculate_transmission_reflection_coefficients.py
Outdated
Show resolved
Hide resolved
nidn/fdtd_integration/calculate_transmission_reflection_coefficients.py
Outdated
Show resolved
Hide resolved
nidn/fdtd_integration/calculate_transmission_reflection_coefficients.py
Outdated
Show resolved
Hide resolved
nidn/fdtd_integration/calculate_transmission_reflection_coefficients.py
Outdated
Show resolved
Hide resolved
@@ -76,7 +76,7 @@ def compute_spectrum_fdtd(permittivity, cfg: DotMap): | |||
logger.debug("Reflection spectrum") | |||
logger.debug(reflection_spectrum) | |||
|
|||
return transmission_spectrum, reflection_spectrum | |||
return torch.tensor(transmission_spectrum), torch.tensor(reflection_spectrum) |
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.
if it was not a torch tensor before then you already have lost the gradients somewhere along the way :) You can leave it for now, just pointing out
else: | ||
grid[source_x, :, 0] = fdtd.LineSource(period=period, name="linesource") | ||
|
||
raise ValueError(f'FDTD_source_type must be either "line" or "point"') |
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.
potentially as above with assert may be easier
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.
but this is also fine
signal_array, signal_array, "mean square", cfg | ||
) | ||
# TODO: Add test for fdtd, when the method is complete | ||
assert transmission_coefficient_ms - 0.25 == 0 |
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 would still assert it here that they are all between 0 and 1. Doesn't hurt and serves as a sanity check if the check inside the codebase is accidentally circumvented
Description
Summary of changes
Resolved Issues
How Has This Been Tested?