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

revamp test_refl_angular.py to validate results against theory rather than hard-coded values #2017

Merged
merged 1 commit into from
Apr 7, 2022

Conversation

oskooi
Copy link
Collaborator

@oskooi oskooi commented Mar 24, 2022

Currently, test_refl_angular.py involves computing the reflectance of a 1d interface for the S polarization at normal incidence and validating the results against hard-coded values. The filename is therefore a misnomer since the test does not actually involve a planewave at oblique incidence. This PR modifies this test to validate the results using the Fresnel equations for two angles of incidence (0° and 20.6°). This makes for a more rigorous and complete test.

This test will eventually be expanded to include a validation of the phase of a total internal reflected mode obtained using mode decomposition via the kz_2d feature as described by @stevengj in #1968 (comment). (The Fresnel equations for the phase are provided in slide 20 of these notes.)

Also included in this PR are small fixes/tweaks to the related Tutorial/Angular Reflectance Spectrum of a Planar Interface.

@oskooi
Copy link
Collaborator Author

oskooi commented Mar 24, 2022

Looks like there is an unrelated failure in test_mpb.py involving MPB's output_efield_z run function which involves writing an HDF5 file to disk. The cause of the failure is likely that h5py is trying to write to a file that already exists. This particular failure has been happening recently on the CI virtual machines and should be fixed in a separate PR. Simply restarting the CI fixed it in this PR.

======================================================================
ERROR: test_line_defect (__main__.TestModeSolver)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/../../../python/tests/test_mpb.py", line 815, in test_line_defect
    ms.run_tm(mpb.output_at_kpoint(k_points[len(k_points) // 2]),
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/meep/mpb/solver.py", line 970, in run_zodd
    self.run_parity(mp.ODD_Z, True, *band_functions)
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/meep/mpb/solver.py", line 942, in run_parity
    f(self, band)
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/meep/mpb/solver.py", line 1221, in output_efield_z
    ms.output_field_z()
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/meep/mpb/solver.py", line 604, in output_field_z
    self.output_field_to_file(2, self.get_filename_prefix())
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/meep/mpb/solver.py", line 623, in output_field_to_file
    self._output_vector_field(curfield_type, fname_prefix, output_k, component)
  File "/home/runner/work/meep/meep/build/meep-1.22.0/_build/sub/python/meep/mpb/solver.py", line 682, in _output_vector_field
    with h5py.File(fname, 'w') as f:
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/h5py/_hl/files.py", line 507, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/h5py/_hl/files.py", line 226, in make_fid
    fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 126, in h5py.h5f.create
BlockingIOError: [Errno 11] Unable to create file (unable to lock file, errno = 11, error message = 'Resource temporarily unavailable')

----------------------------------------------------------------------
Ran 47 tests in 260.248s

FAILED (errors=2)

@stevengj
Copy link
Collaborator

h5py.File(fname, 'w') should overwrite any existing files.

@stevengj
Copy link
Collaborator

We could run into trouble if multiple tests are run in parallel and are writing to files with the same names — we should make sure that the tests use a unique filename prefix for each test (e.g. based on the name of the test file).

@oskooi
Copy link
Collaborator Author

oskooi commented Mar 31, 2022

This is good to go.

@stevengj stevengj merged commit d379c0c into NanoComp:master Apr 7, 2022
@oskooi oskooi deleted the refl_angular_update branch April 7, 2022 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants