Open dkeathley opened 2 years ago
Perhaps there is something wrong with your HDF5 library installation or you have multiple conflicting versions installed? If you built Meep from source, did you verify that the make check
suite passes? If you installed the Conda package, you can try running e.g. test_cavity_farfield.py
which only involves reading an HDF5 file (no writing).
Unfortunately, unlike get_farfields
which is part of the test suite (test_n2f_periodic.py
, test_cavity_farfield.py
), output_farfields
is not and so has not been properly tested (even though it is used in a tutorial example). There are C++ unit tests which involve writing and reading HDF5 files (i.e., [bragg_transmission.cpp
]()) which is why it would be important to first establish that your HDF5 libraries are working correctly before investigating whether there is a bug in output_farfields
.
Hi @oskooi, thanks for your really great work on MEEP. I think this might be an actual bug. I did try it on multiple system with MEEP installed from conda and all had the same issue. To test I added these lines to binary_grating_n2f.ipynb
sim.output_farfields(
n2f_obj,
'test',
ff_res,
center=mp.Vector3(ff_distance, 0.5 * ff_length),
size=mp.Vector3(y=ff_length),
)
It is the same arguments in the 'ff_supercell = sim.get_farfield' earlier in the notebook, but I only added a filename 'test' which sim.output_farfield requires.
Then I plotted the results in test.h5.
import h5py
with h5py.File('test.h5', 'r') as ff:
plt.plot(ff['ez.i'])`
The content of test.h5 are basically some random float number. I had the same issue in my own code as well.
Dear @oskooi, unfortunately, I have to agree with @m9631m. I cannot reproduce the results from the scheme tutorial on a M1 Mac (make checks passed fine). The saved .h5 fields have meaningless numbers (either exponentially high or low or nans)...Appreciate if you could pls investigate the scheme module output-farfields as well.
I have had a persistent issue using the Simulation.output_farfields() function. Whenever I put this at the end of my script and run it using mpirun, I see that the data saved is essentially random numerical values (a lot of very large numbers, and NaNs throughout).
I know that it is not an issue with my implementation as I have tested it using the Simulation.get_farfields() function with identical inputs (all else identical) and then used my own python code to then save the returned arrays to an h5 file using h5py.
It appears to me that the h5 file might be initialized correctly, but somehow the data is not written to the initialized file before the code exits.
I have tested this now on three machines, two running fedora and one running under windows subsystem for linux, all with identical results.
Happy to provide more details if needed.
Below is the relevant portion of code, with the commented out region at the bottom giving basically random data while the active code returns the far-fields correctly.