Repository navigation
Conversation
Lazy grids skipped the construction-time merge, so chunks= changed the topology. Remap and collapse connectivity blockwise so it stays lazy. Fixes #1905
ASV BenchmarkingBenchmark Comparison ResultsBenchmarks that have stayed the same:
Benchmarks that have got worse:
|
Sevans711
left a comment
There was a problem hiding this comment.
Looks pretty good overall, thank you for creating this fix. The test coverage is good and includes the original MCVEs reported in #1905, and I confirmed locally that all newly added tests currently fail on main.
My main concern is the performance losses shown in the ASV benchmark suite, especially the 5x larger peakmem for lazy open grid. Is there any way to avoid these losses while still fixing the underlying bug? If not, would you be able to run a quick check using a large grid (perhaps one of the large grids discussed in #1775?) to ensure this fix doesn't break your use-case for uxarray with large grids?
Aside from that, just left a few inline minor comments.
There was a problem hiding this comment.
There are some concerning regressions in the benchmarks...
| Change | Before [2c11f78] | After [2bda976] | Ratio | Benchmark (Parameter) |
|---|---|---|---|---|
| + | 1 | 3 | 3 | lazy_grid_construction.LazyGridConstruction.track_computes_isel |
| + | 2 | 4 | 2 | lazy_grid_construction.LazyGridConstruction.track_computes_open_grid_chunked |
| + | 2.01M | 10.1M | 5.05 | lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('120km') |
Load node_lon and node_lat in one compute instead of two, and skip the coincident-node search when slicing a grid that was already merged: a face subset keeps only nodes its canonical faces reference, so it has no duplicates. Restores track_computes_isel to 1 and brings track_computes_open_grid_chunked to 3 (the extra one is the coordinate read the #1905 fix requires). Update the benchmark docstrings to match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
My last commit should mostly fix the lazy grid construction. |
|
Thanks @Sevans711 for the careful review and @cmdupuis3 for cutting the extra computes in isel and open_grid. Sam's inline comments are addressed in 16e1d8e. The peakmem increase on lazy open comes from the coincident-node search on the node coordinates; I'm looking at trimming that and will report back with a large-grid check. |
The search copied the (n_node, 3) xyz array twice even in the common case, once for the finite-point filter and once for the pole filter, and kept the loaded lon/lat alive through it; now it searches the original array when every point is finite and none is a pole, and frees lon/lat first. Results are unchanged, and on the 12.8M-node esmf_mesh the lazy open's traced peak drops from 2.09 GB to 0.93 GB (RSS 2.74 GB to 1.79 GB), with oQU120 back to 4.6 MB against 4.05 MB on main.
|
I tested lazy (
@Sevans711 @cmdupuis3 @erogluorhan could you retest on your grids and review again? We'd like this in the upcoming release since main gives the wrong topology on real meshes. |
|
I'll defer its review to @cmdupuis3 and @Sevans711 |
The coincident-node search only needs x for every node (the prescreen) and |z| (the pole test); full XYZ rows are needed just for the prescreen's candidates and the pole nodes. _coincident_node_canonical_indices now also accepts lonlat_rad=(lon, lat) and builds XYZ only for those, so the (n, 3) array and its copies are never materialized. The merge and _find_duplicate_node_map use this form. Traced peak of the merge on a chunked open drops from ~69 to ~45 bytes per node (101 to 46 when the mesh has pole nodes, where the old code copied the whole XYZ array); 849 MB to 542 MB at 12.8M nodes. Duplicate maps and merged connectivity are identical to before across the test meshes and randomized cases (exact copies, near-tolerance jitter, +360 aliases, chains, poles, unreferenced non-finite nodes). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@rajeeja I got the peakmem down a bit more, can you rerun your tests? |
|
@cmdupuis3 I reran on d13c82a, which builds full XYZ only for the prescreen candidates and pole nodes instead of the whole (n, 3) array. Lazy and eager still match on esmf_mesh and oRRS18to6, and the esmf_mesh traced peak drops from 919 to 574 MB. The only regression is ne256 RSS, up 60 to 80 MB across three runs with an identical traced peak.
|
cmdupuis3
left a comment
There was a problem hiding this comment.
I'm guessing this is about as good as peakmem is going to get for now. Approving.
Sevans711
left a comment
There was a problem hiding this comment.
All my previous inline comments have been addressed. Also, the newer changes all "look reasonable" and the pytest suite would hopefully catch any major issues. But, at the same time, it is a bit difficult to review some of the changes. Could you add a bit of clarification in the thread here and maybe update the PR overview message as well? (cc: @cmdupuis3 who added some of these changes.) In particular:
- What is the purpose and effect of the changes to validation.py? Are those just reducing peakmem usage? I can't tell if all the changes here are necessary or if a variety of stylistic refactors are happening at the same time (e.g., defining the
xyz_atfunction inside another function in two places based on branching logic). If it's possible to get the same improvements without as much stylistic refactoring that would be very helpful from the perspective of reviewing the code. If the refactors are essential, that's okay too, but please clarify here so I can give a proper review! - What is the benefit of the changes in slice.py? Do any of the ASV benchmarks show this? I would think something as huge as avoiding
"when chunked, a load of every node coordinate"as is claimed in the new_subgridfunction, could have a huge effect in some cases, but I'm not seeing any ASV benchmarks with a huge improvement here. (The answer this point might just be to add a corresponding ASV benchmark.)
Regarding my original comment about the 5x increased peakmem usage, though there's still a small increase, it looks like that has been mostly resolved, and the discussion thread seems to be converging on "this is as good as we're going to get it". So, I am happy to avoid blocking on that point.
Closes #1905
Please merge after #1870. That PR adds a strict xfail for this bug, and this fix turns it into an XPASS failure. Once #1870 lands I'll rebase and drop the marker here, so the fix and its test go in together.
Overview
Chunked grids skipped the coincident-node merge from #1692, so
chunks=changed the topology (n_edge,==,validate()). The merge now runs for lazy grids as well: the 1-D node coordinates are loaded for the search, and the connectivity is remapped blockwise withmap_blocks, so it is never computed at open time._prepare_for_dualis removed because grids are now canonical at construction.PR Checklist
General
Testing & Benchmarking
Documentation and Examples
docs/api.rst; internal (private) function names start with an underscore (_)AI Disclosure
AI Usage: