Repository navigation
[Scripting] Generalize PlotfileDataset and the cache budget for analysis tools - #289
Merged
Merged
Conversation
This was referenced Oct 29, 2026
BenWibking
force-pushed
the
analysis-1-core
branch
from
October 29, 2026 01:28
2f2e929 to
f96f0b5
Compare
- Move the cache-budget default and AMREXPLORER_CACHE_SIZE_MB parsing from src/qt to core/CacheConfig.hpp, so code without Qt can share them. - Let PlotfileDataset take a DerivedFieldPolicy, so an unattended analysis can fail at open on a definition that does not resolve, and expose a derived field's program for callers that bound reads ahead. - Give FabValues span accessors in its stored precision, for callers copying many values without dispatching per value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BenWibking
force-pushed
the
analysis-1-core
branch
from
November 2, 2026 16:23
f96f0b5 to
045eb46
Compare
WeiqunZhang
pushed a commit
that referenced
this pull request
Nov 4, 2026
A Qt-free `src/analysis` library with an exact planner and reader for a plotfile's **leaf cells**, the cells no finer level covers. This is the core algorithm the Python package builds on. - **Plans.** `planLeafChunks` partitions the leaf cells of a region into one item per grid, in a fixed order: levels coarsest first, grids in native FAB order. - Covered coarse cells never appear, and every leaf cell appears exactly once. - Regions select cells by center, `lower <= center < upper`, so adjacent regions split the cells between them. - Planning reads metadata only. - **Precision.** Field values keep the widest precision any level stores unless the plan asks for float32 or float64. Derived fields are evaluated per block and follow the plan's dtype. - **Cache budget.** Each item's worst-case cache use is checked against the budget at planning, and again when reading. The error names the item. - **Chunks.** `readLeafChunk` copies an item's values out of the cache: a chunk holds no cache pins and outlives the dataset. Geometry arrays (indices, centers, widths, volumes) are computed on first use. - **Errors.** Unknown fields, unsupported geometry or centering, invalid regions and items planned on another dataset are `AnalysisError`. ## Review notes `src/analysis/LeafChunks.cpp` is the file to read closely. The covered-cell computation, region-to-index-box conversion and the pinned-bytes estimate are where the guarantees come from. ## Tests `tests/integration/test_leaf_chunks.cpp` runs on a two-level 2-D fixture whose fine grid straddles a coarse grid boundary. It checks: - exact partition, stored values, and the leaf cells tiling the domain - the half-open region rule, and an empty plan outside the domain - unknown, duplicate and non-finite requests are refused, as is non-Cartesian geometry - float32 narrowing and derived fields - reading items repeatedly and in any order - no pins after a read, and chunks outliving the dataset - the planning-time and read-time budget checks - cancellation, and items bound to their dataset The headless ctest suite passes (64 tests). ## Stack Part of a stack replacing #276. Review and merge in order; each PR shows only its own layer. 1. #289 Prepare PlotfileDataset and the cache budget for analysis 2. #285 Exact leaf-cell plans and chunks (C++) ← this PR 3. #286 The amrexplorer Python package (bindings) 4. #287 Parallel reductions and batch helpers 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
WeiqunZhang
pushed a commit
that referenced
this pull request
Nov 17, 2026
The `amrexplorer` Python package: nanobind bindings over the leaf-cell planner and reader from the previous PR, plus a small pure-Python wrapper and build plumbing. Most of this PR is mechanical glue. The Python tests are the clearest statement of the API. - **`open_plotfile(path, derived=..., cache_bytes=...)`** returns a `Dataset` usable as a context manager. Derived-field definitions use `Strict`, so a bad one fails at open. - **Plans and chunks.** `plan_leaf_chunks` returns a sequence of items, and `read_leaf_chunk` returns a chunk. - A chunk is a mapping of read-only NumPy arrays that keep their memory alive, so they outlive the chunk and the dataset. - Geometry (`x`, `dx`, `i`, `cell_volume`, ...) is computed lazily. - `leaf_cells()` plans and reads in one loop. - **`CancelToken`** stops a read in progress. Analysis, cache-budget, read, closed-dataset and cancellation errors map to Python exceptions. - **Build.** - `-DAMREXPLORER_ENABLE_PYTHON=ON` builds the module into `<build>/python`. - `pip install .` builds the module alone through scikit-build-core (`pyproject.toml`). - ctest runs the pytest suite as `python_analysis` when pytest is installed. - **Docs.** `docs/python-analysis.md` (installing and leaf cells) and `docs/building.md`. ## Review notes - `python/src/module.cpp` (~540 lines) is type conversion: dicts and boxes, NumPy views kept alive by capsules, GIL release around reads, and closed-dataset checks. - `python/amrexplorer/_dataset.py` is property accessors and the Mapping/Sequence protocols over the native objects. - Both are worth skimming, not reading line by line. ## Tests - `tests/python/test_leaf_chunks.py` (25 tests) checks every contract against an independent NumPy reconstruction of 1-D, 2-D and 3-D fixture plotfiles. It includes a region over a 2^64-cell domain, a regression test for an overflow found on real data. - `tests/python/plotfile_writer.py` writes AMReX-layout plotfiles (per-level precision, stored ghost cells, version-1 and version-2 FAB headers) for these and later tests. - The headless ctest suite passes (65 tests, `python_analysis` among them). ## Stack Part of a stack replacing #276. Review and merge in order; each PR shows only its own layer. 1. #289 Prepare PlotfileDataset and the cache budget for analysis 2. #285 Exact leaf-cell plans and chunks (C++) 3. #286 The amrexplorer Python package (bindings) ← this PR 4. #287 Parallel reductions and batch helpers 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Small changes to existing code that the analysis library (next PR) needs. No new feature yet.
core. The cache-budget default andAMREXPLORER_CACHE_SIZE_MBparsing move fromsrc/qt/CacheConfig.hpptoinclude/amrexplorer/core/CacheConfig.hpp, so code without Qt can share them.src/qt/CacheConfig.hppnow uses the core version.PlotfileDatasettakes aDerivedFieldPolicy:Skip.Strict, so a definition that doesn't resolve fails at open instead of silently dropping the field.derivedFieldProgram(field). Exposes a derived field's compiled program, so a caller can bound in advance which blocks a read will pin.FabValuesspans.FabValues::singleValues()anddoubleValues()expose the payload in its stored precision, for callers copying many values without dispatching on precision per value.Tests
tests/integration/test_derived_field_policy.cpp:Skipinstalls what resolves and reports the rest.Strictfails the open, naming the broken definition.derivedFieldProgramreturns null for a stored field and the right inputs for a derived one, and a derived block evaluates its program.test_single_precision_plotfile.cppchecks both span accessors for float and double FABs.Stack
Part of a stack replacing #276. Review and merge in order; each PR shows only its own layer.
🤖 Generated with Claude Code