Skip to content

h5i: is_h5i, and arrays of structures that lost elements on write and read - #115

Merged
tomneiser merged 1 commit into
masterfrom
fix/h5i
Nov 16, 2026
Merged

tomneiser merged 1 commit into
masterfrom
fix/h5i

Conversation

@tomneiser

Copy link
Copy Markdown
Member

Three problems of the ITER tensorized HDF5 format (imas2h5i, h5i2imas, is_h5i), which show up as soon as a file is written and read back.

1. is_h5i is false for every file

It looked for &AOS_SHAPE among the names at the root of the file, which are the IDS groups (equilibrium, pf_active, ...), and its return true was inside the do block, so it only left the closure. file2imas therefore sent tensorized files to hdf2imas, which returned a dd with every array of structures empty, without an error.

It now looks inside the IDS groups for dataset names that contain &.

2. Arrays of structures lost elements, or the file could not be read

imas2h5i padded each field only up to the last structure that holds it, while h5i2imas sized each array of structures from the first of its fields that it reads, and indexed numbers and strings up to the &AOS_SHAPE length.

  • A field that the last structures do not have and that comes first in the file truncated the whole array: the ITER pf_active sample came back with 12 of its 14 coils, the D3D samples with 1 of 2 ions.
  • A number or string that the last structures do not have gave a BoundsError (omas_sample.json, ARCv3a_starting_dd.json).
  • With three levels, the shape of the inner arrays was that of the last instance visited, not the largest, and the instances that did not fit were skipped silently.

Now:

  • imas2h5i pads every field to the full shape of the arrays of structures that hold it, and the shape of an array of structures is the largest among its instances.
  • h5i2imas first sizes every array of structures from its &AOS_SHAPE, parents before children, and then fills the fields. Nested arrays of different lengths keep their own lengths (before, the first field read decided).
  • h5i2imas skips a field where the stored array is shorter than &AOS_SHAPE, so files written before this change can be read: on nine sample files written with the current master, every array of structures now has the length it had in the source.

Effect

imas2h5i then h5i2imas on 12 sample files (omas_sample.json and FUSE's samples):

master this PR
is_h5i true 0 of 12 12 of 12
read back without error 10 of 12 12 of 12
files with an array of structures of the wrong length 3 of 10 0 of 12

What still differs after a round trip is what the format does not hold: empty arrays are dropped, ids_properties.homogeneous_time is added, and a number or string that only some structures of an array have comes back as 0 or "" in the others.

Question for reviewers

The third change of the reader (skipping a field whose stored array is too short instead of throwing) is only there for files written by earlier versions. There is a commented-out check with the same purpose just below it; if you would rather have an error or a warning for such files, I can change it.

Tests

New testset h5i in test/runtests_io.jl (15 tests): arrays of structures of different lengths, fields that only some structures hold, three levels with a shorter last instance, file2imas, and a second write and read that returns the same dd. On master it fails at is_h5i and stops with the BoundsError.

🤖 Generated with Claude Code

- is_h5i looked for `&AOS_SHAPE` among the IDS groups at the root of the
  file, and returned from the `do` block only: it was false for every file,
  so file2imas read tensorized files with hdf2imas.
- imas2h5i pads every field to the full shape of the arrays of structures
  that hold it (it stopped at the last structure holding the field), and
  takes the largest instance as the shape of an array of structures (it
  took the last one visited).
- h5i2imas sizes every array of structures from its `&AOS_SHAPE` before
  filling the fields (the first field read decided the length), and skips
  a field whose stored array is shorter, as written by earlier versions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 44.76%. Comparing base (db52845) to head (08ebd68).

Files with missing lines Patch % Lines
src/io.jl 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #115      +/-   ##
==========================================
+ Coverage   44.02%   44.76%   +0.74%     
==========================================
  Files          16       16              
  Lines       31556    31588      +32     
==========================================
+ Hits        13891    14140     +249     
+ Misses      17665    17448     -217     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tomneiser
tomneiser merged commit d2082c4 into master Nov 16, 2026
10 checks passed
@tomneiser
tomneiser deleted the fix/h5i branch November 16, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant