Record the grid_volume in structure.h5 and test dump/load consistency - #3289
Open
oskooi wants to merge 2 commits into
Open
Record the grid_volume in structure.h5 and test dump/load consistency#3289oskooi wants to merge 2 commits into
grid_volume in structure.h5 and test dump/load consistency#3289oskooi wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #3282.
Context
dump_structureandload_structureuse the samegrid_volumeat any resolution — but only by construction, and nothing was enforcing it.Neither Python wrapper builds a
gv. Both call through toself.structure(python/simulation.py:2345,:2361), and there is exactly onegvconstruction path —_init_structure→_create_grid_volume(:2053,:1681) — driven by (cell_size,resolution,dimensions,geometry_center,k_point). The(int)(size*a + 0.5)rounding involone/vol3d/volcyl(src/vec.cpp:904-941) is deterministic, so identical inputs give a bit-identicalgvon both sides. The delayed-load path also runs in the right order, afterload_chunk_layout.The gap was that
structure::dumpwrote no geometric metadata, sostructure::loadcould only validate byte counts. Confirmed empirically that dumping a(5, 4)cell and loading it into a(4, 5)cell at the same resolution succeeded silently with transposed data — the per-chunkntot(251×201 vs 201×251) is identical, so none of the existing checks fired.Changes
src/vec.cpp:933—volcyltestedisinteger(rsize)instead ofisinteger(rsize * a). Verified before/after:r=2.5, res=2now gives 5 pixels with no warning (previously warned), andr=3, res=2.5gives 8 pixels with the warning (previously silent).src/structure_dump.cpp—structure::dumpnow writes agv_metadatadataset (dim,a, pixel counts, origin; full double precision), andstructure::loadcompares it against the livegvbefore reading anything, aborting with a message that names the offending field. Files without the dataset load exactly as before.python/tests/test_dump_load.py—test_dump_load_grid_volume_matchesasserts fullgvsignature equality across a round trip for 1D/2D/3D/cylindrical at resolutions[10, 13, 17.5, 21.3, 33](all landing on non-integer pixel counts); plus resolution-mismatch, transposed cell, and legacy-file tests.python/tests/test_simulation.py—test_volcyl_pixel_rounding_warning, capturing stderr at the file-descriptor level. The warning tested is from C++ (master_printf_stderr→fprintf(stderr, ...)insrc/mympi.cpp), not from Python.python/simulation.py+ the corresponding block indoc/docs/Python_User_Interface.md—load_structuredocstring now states the matching requirements.Verification
test_dump_load.py: 17 passed single-process and undermpirun -np 2(which exercises the shardedsingle_parallel_file=Falsepath).test_simulation.py: 32 passed. C++tests/dump_loadexits 0.Two Notes:
@unittest.skipIf(mp.count_processors() > 1, ...)is used rather than thetest_dump_load.py's existingmp.with_mpi()guard, becausemeep::abortthrowsRuntimeErrorwhenevercount_processors() == 1even in an MPI build (src/mympic.cpp:248). With the existing guard the new tests would never have run here. The pre-existing test's guard is not changed.fileds::dump/fields::load(src/fields_dump.cpp) have the identical gap — same byte-count-only checks, nogvrecord. That is not addressed in this PR.