Skip to content

Collect filled coverage paths without repeated AoS index searches - #23

Merged
olivhoenen merged 1 commit into
iterorganization:developfrom
chupakobra6:codex/linear-filled-paths
Sep 29, 2026
Merged

olivhoenen merged 1 commit into
iterorganization:developfrom
chupakobra6:codex/linear-filled-paths

Conversation

@chupakobra6

Copy link
Copy Markdown
Contributor

Fixes #10.

Filled-path collection reconstructs each leaf's node._path, repeatedly scanning parent Arrays of Structures for their indices. Collection is quadratic in AoS length despite caching per (IDS name, occurrence).

Add a private depth-first iterator that carries the path prefix and enumerates each AoS once. It preserves concrete, zero-based indices, filled-leaf filtering, and the existing per-occurrence cache. A result is cached only after traversal completes, so an exception cannot leave partial coverage that suppresses a later attempt. Lazy-loaded IDSs retain the existing rejection instead of silently reporting only loaded fields.

Add 16 regression cases covering exact path equivalence, nested and sparse AoS, empty/materialized nodes, distinct IDSs and occurrences, repeated assertions, reordered/resized arrays, lazy netCDF reads, interrupted traversal, and an end-to-end netCDF validation. The scaling test counts AoS accesses at 100, 1,000 and 10,000 elements; a separate test forbids _path during filled-path collection. Add standalone ASV time and peak-memory benchmarks with a fresh collector per measurement.

On a synthetic core_profiles IDS with two ions per profile and five filled leaves per profile, Python 3.12.13 / IMAS-Python 2.3.0 on macOS arm64:

Profiles Filled paths Before After AoS accesses before → after
100 500 2.747 ms 0.810 ms 26,251 → 401
1,000 5,000 161.599 ms 8.146 ms 2,512,501 → 4,001
10,000 50,000 15.973 s 82.669 ms 250,125,001 → 40,001

Times are medians of three collections, excluding fixture creation, in separate processes for the baseline and fix. Sets match exactly. At 50,000 paths, traced peak Python allocations were 5.460 MiB before and 5.459 MiB after; separate uninstrumented process peak RSS was 223.1 / 224.6 MiB, including the interpreter and IDS.

Validation:

  • Full suite: 185 passed, 2 existing skips on macOS Python 3.12 and on Linux arm64 Python 3.10–3.14.
  • Minimum IMAS-Python 2.2.0: 185 passed, 2 existing skips on Python 3.10.
  • Black, Flake8, MyPy, Isort, wheel/sdist build, Sphinx with warnings treated as errors, and ASV checks/smoke run pass.
  • Additional equivalence check: 468 generated IDS cases, 89,368 paths across DD 3.40.1 and 4.0.0. The upstream generator excludes amns_data in the former and thomson_scattering in the latter.
  • Additional real HDF5 validation through IMAS Core: two occurrences, four rule assertions, and rejection of unloaded/partially loaded lazy IDSs without caching partial coverage.

This change targets filled-path collection. It does not reduce database read time or change touched-node path collection in create_nodes_dict(). The internal dataset was unavailable; the synthetic benchmark reproduces its quadratic index-search behavior.

@olivhoenen olivhoenen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chupakobra6, thanks for this addition, which is very welcome!
(if affects only the perf when using the -nc option though, so I'm keeping #10 open for the time being)

@olivhoenen
olivhoenen merged commit c73d45b into iterorganization:develop Sep 29, 2026
8 checks passed
@olivhoenen olivhoenen mentioned this pull request Nov 26, 2026
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.

Performance issue for large datasets

2 participants