Skip to content

Merge coincident nodes for dask-backed grids - #1915

Open
rajeeja wants to merge 15 commits into
mainfrom
rajeeja/fix-1905-lazy-coincident-merge
Open

rajeeja wants to merge 15 commits into
mainfrom
rajeeja/fix-1905-lazy-coincident-merge

Conversation

@rajeeja

@rajeeja rajeeja commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1905

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 too: node coordinates are loaded in one compute and searched from lon/lat without building the full XYZ array, and connectivity is remapped blockwise so it stays lazy. Subsets of an already merged grid skip the search, and _prepare_for_dual is removed because grids are canonical at construction.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • [N/A] User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)
  • [N/A] If touched any notebook files, cleared the output of all cells before committing
  • [N/A] If added new notebook files, put into appropriate directories and referenced in appropriate files

AI Disclosure

AI Usage:

  • I have tested and take responsibility for all AI-generated content in my PR.

Lazy grids skipped the construction-time merge, so chunks= changed the
topology. Remap and collapse connectivity blockwise so it stays lazy.

Fixes #1905
@Sevans711
Sevans711 requested review from cmdupuis3 and removed request for ChrisBarker-NOAA November 20, 2026 18:41
@Sevans711 Sevans711 added run-benchmark Run ASV benchmark workflow bug Something isn't working scalability Related to scalability & performance efforts labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

ASV Benchmarking

Benchmark Comparison Results

Benchmarks that have improved:

Change Before [b7a43bb] After [b4d3b3c] Ratio Benchmark (Parameter)
- 21.1±0.06ms 19.0±0.05ms 0.9 mpas_ocean.DualMesh.time_dual_mesh_construction('120km')

Benchmarks that have stayed the same:

Change Before [b7a43bb] After [b4d3b3c] Ratio Benchmark (Parameter)
678±10μs 708±5μs 1.04 connectivity.Connectivity.time_edge_face('120km')
234±20μs 234±10μs 1.00 connectivity.Connectivity.time_edge_face('480km')
3.34±0.04ms 1.77±0.02ms ~0.53 connectivity.Connectivity.time_edge_node('120km')
577±10μs 545±20μs 0.95 connectivity.Connectivity.time_edge_node('480km')
38.2±4μs 34.1±2μs ~0.89 connectivity.Connectivity.time_face_edge('120km')
36.0±7μs 29.6±3μs ~0.82 connectivity.Connectivity.time_face_edge('480km')
397±6μs 416±9μs 1.05 connectivity.Connectivity.time_face_face('120km')
224±10μs 225±10μs 1.01 connectivity.Connectivity.time_face_face('480km')
44.4±3μs 38.4±7μs ~0.87 connectivity.Connectivity.time_face_node('120km')
32.6±2μs 29.1±4μs ~0.89 connectivity.Connectivity.time_face_node('480km')
400±90μs 295±10μs ~0.74 connectivity.Connectivity.time_n_nodes_per_face('120km')
200±6μs 206±30μs 1.03 connectivity.Connectivity.time_n_nodes_per_face('480km')
665±10μs 680±6μs 1.02 connectivity.Connectivity.time_node_edge('120km')
225±5μs 227±10μs 1.01 connectivity.Connectivity.time_node_edge('480km')
44.7±1ms 46.0±3ms 1.03 connectivity.Connectivity.time_node_face('120km')
2.67±0.02ms 2.68±0.02ms 1.00 connectivity.Connectivity.time_node_face('480km')
1.42M 1.42M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_face('120km')
105k 105k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_face('480km')
6.48M 6.48M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_node('120km')
419k 419k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_edge_node('480km')
2.05k 2.05k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_edge('120km')
2.05k 2.05k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_edge('480km')
1.6M 1.6M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_face('120km')
101k 101k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_face('480km')
2.18k 2.18k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_node('120km')
2.18k 2.18k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_face_node('480km')
240k 240k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_n_nodes_per_face('120km')
26k 26k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_n_nodes_per_face('480km')
1.9M 1.9M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_edge('120km')
127k 127k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_edge('480km')
11.9M 11.9M 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_face('120km')
747k 747k 1.00 connectivity.ConnectivityTracemalloc.track_peakmem_node_face('480km')
4.28±0.06ms 4.34±0.06ms 1.01 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
1.30±0.02ms 1.29±0.05ms 1.00 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
5.22±0.03ms 5.28±0.1ms 1.01 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
715±20μs 711±10μs 0.99 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
57.3k 57.3k 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
12.3k 12.3k 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
123k 123k 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
128 128 1.00 face_bounds.FaceBounds.track_nbytes_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
1.27M 1.27M 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
50.1k 50.1k 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
516k 516k 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
712 712 1.00 face_bounds.FaceBounds.track_nbytes_grid_with_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
1.78M 1.78M 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
1.76M 1.76M 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
1.92M 1.92M 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
35.3k 35.3k 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
1.04±0.04μs 1.05±0.03μs 1.00 geometry_kernels.AccucrossKernels.time_accucross
2.40±0.03μs 2.43±0.08μs 1.01 geometry_kernels.AccucrossKernels.time_accucross_pair
261±10ns 241±10ns 0.92 geometry_kernels.EFTPrimitives.time_acc_sqrt_re
245±10ns 236±5ns 0.96 geometry_kernels.EFTPrimitives.time_diff_of_products
210±4ns 206±10ns 0.98 geometry_kernels.EFTPrimitives.time_two_prod
210±4ns 210±10ns 1.00 geometry_kernels.EFTPrimitives.time_two_sum
641±30ns 659±30ns 1.03 geometry_kernels.GCAConstLatIntersection.time_accux_constlat_kernel
811±30ns 824±30ns 1.02 geometry_kernels.GCAConstLatIntersection.time_gca_const_lat_intersection
925±50ns 990±50ns 1.07 geometry_kernels.GCAConstLatIntersection.time_try_gca_const_lat_intersection
585±50ns 563±30ns 0.96 geometry_kernels.GCAGCAIntersection.time_accux_gca_kernel
806±90ns 807±20ns 1.00 geometry_kernels.GCAGCAIntersection.time_gca_gca_intersection
838±100ns 795±20ns 0.95 geometry_kernels.GCAGCAIntersection.time_try_gca_gca_intersection
19.3±0.2μs 20.8±0.2μs 1.08 geometry_kernels.OrientPredicates.time_on_minor_arc
21.4±10μs 20.4±0.3μs 0.95 geometry_kernels.OrientPredicates.time_orient3d_on_sphere
2.51±0.01ms 2.52±0ms 1.00 geometry_samebody.SameBodyConstLat.time_accux_dispatch
1.02±0ms 1.02±0ms 1.00 geometry_samebody.SameBodyConstLat.time_accux_kernel
2.15±0.4ms 1.74±0.01ms ~0.81 geometry_samebody.SameBodyConstLat.time_fp64_dispatch
121±1μs 121±0.2μs 1.00 geometry_samebody.SameBodyConstLat.time_fp64_kernel
35.9±0.4ms 38.6±3ms 1.08 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_dispatch
3.85±0.04ms 4.17±0.3ms 1.08 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_kernel
32.4±0.4ms 32.8±0.3ms 1.01 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_dispatch
487±7μs 475±7μs 0.97 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_kernel
585±9ms 571±7ms 0.98 import.Imports.timeraw_import_uxarray
1 1 1.00 lazy_grid_construction.LazyGridConstruction.track_computes_isel
75.3±3ms 74.5±0.7ms 0.99 lazy_grid_construction.OpenGridChunked.time_open_grid('480km')
1.86±0.02ms 1.89±0.08ms 1.02 mpas_ocean.AzimuthalAverage.time_azimuthal_average('120km')
747±10μs 728±20μs 0.98 mpas_ocean.AzimuthalAverage.time_azimuthal_average('480km')
2.79±0.05ms 2.75±0.05ms 0.99 mpas_ocean.CheckNorm.time_check_norm('120km')
1.70±0.01ms 1.73±0.01ms 1.02 mpas_ocean.CheckNorm.time_check_norm('480km')
1.13±0.02ms 1.10±0.02ms 0.97 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('120km')
485±10μs 491±10μs 1.01 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('480km')
714±20μs 701±9μs 0.98 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('120km')
530±4μs 519±9μs 0.98 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('480km')
2.36±0.01ms 2.41±0.07ms 1.02 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('120km')
1.72±0.01ms 1.77±0.01ms 1.03 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('480km')
67.3±0.3ms 70.0±1ms 1.04 mpas_ocean.ConstructFaceLatLon.time_welzl('120km')
5.84±0.02ms 5.90±0.07ms 1.01 mpas_ocean.ConstructFaceLatLon.time_welzl('480km')
15.5±0.08ms 15.6±0.06ms 1.00 mpas_ocean.ConstructTreeStructures.time_ball_tree('120km')
754±4μs 752±10μs 1.00 mpas_ocean.ConstructTreeStructures.time_ball_tree('480km')
8.11±0.05ms 7.81±0.03ms 0.96 mpas_ocean.ConstructTreeStructures.time_kd_tree('120km')
436±7μs 430±7μs 0.99 mpas_ocean.ConstructTreeStructures.time_kd_tree('480km')
461±3ms 422±4ms 0.92 mpas_ocean.CrossSections.time_const_lat('120km', 1)
238±2ms 218±1ms 0.92 mpas_ocean.CrossSections.time_const_lat('120km', 2)
119±0.4ms 109±0.2ms 0.91 mpas_ocean.CrossSections.time_const_lat('120km', 4)
398±2ms 376±2ms 0.94 mpas_ocean.CrossSections.time_const_lat('480km', 1)
200±2ms 186±2ms 0.93 mpas_ocean.CrossSections.time_const_lat('480km', 2)
102±1ms 96.0±2ms 0.94 mpas_ocean.CrossSections.time_const_lat('480km', 4)
2.51±0.02ms 2.29±0.02ms 0.91 mpas_ocean.DualMesh.time_dual_mesh_construction('480km')
10.5±0.2ms 10.6±0.2ms 1.00 mpas_ocean.FaceAreas.time_face_areas('120km')
3.52±0.1ms 3.51±0.1ms 1.00 mpas_ocean.FaceAreas.time_face_areas('480km')
229k 229k 1.00 mpas_ocean.FaceAreas.track_nbytes_face_areas('120km')
14.3k 14.3k 1.00 mpas_ocean.FaceAreas.track_nbytes_face_areas('480km')
2.12M 2.12M 1.00 mpas_ocean.FaceAreas.track_peakmem_face_areas('120km')
679k 679k 1.00 mpas_ocean.FaceAreas.track_peakmem_face_areas('480km')
47.7±0.6ms 48.1±0.7ms 1.01 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'exclude')
132±0.5ms 129±1ms 0.98 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'split')
4.65±0.2ms 4.71±0.2ms 1.01 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'exclude')
24.4±0.3ms 24.7±0.3ms 1.01 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'split')
10.6±0.02ms 10.5±0.03ms 0.99 mpas_ocean.Gradient.time_gradient('120km')
1.74±0.02ms 1.73±0.01ms 0.99 mpas_ocean.Gradient.time_gradient('480km')
457k 457k 1.00 mpas_ocean.Gradient.track_nbytes_gradient('120km')
28.7k 28.7k 1.00 mpas_ocean.Gradient.track_nbytes_gradient('480km')
3.44M 3.44M 1.00 mpas_ocean.Gradient.track_peakmem_gradient('120km')
226k 226k 1.00 mpas_ocean.Gradient.track_peakmem_gradient('480km')
220±10μs 195±9μs ~0.88 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('120km')
75.2±1μs 74.4±1μs 0.99 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('480km')
137±6μs 136±5μs 1.00 mpas_ocean.Integrate.time_integrate('120km')
111±1μs 120±7μs 1.07 mpas_ocean.Integrate.time_integrate('480km')
18.4M 18.4M 1.00 mpas_ocean.Integrate.track_nbytes_integrate('120km')
1.2M 1.2M 1.00 mpas_ocean.Integrate.track_nbytes_integrate('480km')
82.5±1ms 86.3±1ms 1.05 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'exclude')
79.8±2ms 85.0±1ms 1.07 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'include')
84.5±3ms 82.2±1ms 0.97 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'split')
5.66±0.08ms 5.86±0.1ms 1.04 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'exclude')
5.66±0.09ms 6.19±0.6ms 1.09 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'include')
5.68±0.07ms 5.86±0.1ms 1.03 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'split')
159±1ms 158±4ms 0.99 mpas_ocean.NeighborhoodBuild.time_build('120km', 1.0)
334±2ms 335±2ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('120km', 5.0)
8.53±0.03ms 8.47±0.02ms 0.99 mpas_ocean.NeighborhoodBuild.time_build('480km', 1.0)
10.6±0.06ms 10.6±0.01ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('480km', 5.0)
156±0.8ms 156±0.5ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 1.0)
330±1ms 329±2ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 5.0)
8.33±0.01ms 8.34±0.02ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('480km', 1.0)
10.4±0.01ms 10.5±0.04ms 1.01 mpas_ocean.NeighborhoodBuild.time_query_radius('480km', 5.0)
612.76 612.76 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('120km', 15.0)
74.17 74.17 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('120km', 5.0)
37.29 37.29 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('480km', 15.0)
6.57 6.57 1.00 mpas_ocean.NeighborhoodBuild.track_mean_neighbors('480km', 5.0)
141M 141M 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('120km', 15.0)
17.4M 17.4M 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('120km', 5.0)
563k 563k 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('480km', 15.0)
123k 123k 1.00 mpas_ocean.NeighborhoodBuild.track_nbytes_neighbors('480km', 5.0)
145M 145M 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('120km', 15.0)
21.5M 21.5M 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('120km', 5.0)
824k 824k 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('480km', 15.0)
384k 384k 1.00 mpas_ocean.NeighborhoodBuild.track_peakmem_build('480km', 5.0)
39.4±0.3ms 39.7±1ms 1.01 mpas_ocean.NeighborhoodDask.time_mean('120km', 'grid_chunks')
17.5±0.3ms 17.2±0.01ms 0.98 mpas_ocean.NeighborhoodDask.time_mean('120km', 'numpy')
36.3±0.9ms 35.5±0.4ms 0.98 mpas_ocean.NeighborhoodDask.time_mean('120km', 'time_chunks')
9.77±0.03ms 9.97±0.09ms 1.02 mpas_ocean.NeighborhoodDask.time_mean('480km', 'grid_chunks')
592±4μs 603±7μs 1.02 mpas_ocean.NeighborhoodDask.time_mean('480km', 'numpy')
6.88±0.1ms 6.91±0.08ms 1.00 mpas_ocean.NeighborhoodDask.time_mean('480km', 'time_chunks')
5.74M 5.82M 1.01 mpas_ocean.NeighborhoodDask.track_peakmem_mean('120km', 'grid_chunks')
2.75M 2.75M 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('120km', 'numpy')
5.68M 5.68M 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('120km', 'time_chunks')
744k 754k 1.01 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'grid_chunks')
177k 177k 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'numpy')
528k 529k 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'time_chunks')
3.19±0.02s 3.16±0.01s 0.99 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'mean')
3.36±0.01s 3.31±0.02s 0.98 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'median')
92.6±1ms 91.2±1ms 0.99 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'mean')
94.5±0.4ms 94.3±0.9ms 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'median')
348±1ms 343±0.9ms 0.99 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'mean')
383±1ms 381±0.9ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'median')
13.1±0.2ms 13.1±0.03ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'mean')
13.4±0.03ms 13.2±0.02ms 0.99 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'median')
3.95±0.1ms 3.82±0.08ms 0.97 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'mean')
38.8±0.08ms 38.9±0.07ms 1.00 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'median')
191±3μs 196±6μs 1.03 mpas_ocean.NeighborhoodReduce.time_reduce('480km', 'mean')
549±10μs 545±6μs 0.99 mpas_ocean.NeighborhoodReduce.time_reduce('480km', 'median')
234k 234k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('120km', 'mean')
235k 235k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('120km', 'median')
19.5k 19.5k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('480km', 'mean')
19.6k 19.6k 1.00 mpas_ocean.NeighborhoodReduce.track_peakmem_reduce('480km', 'median')
226±30μs 212±10μs 0.94 mpas_ocean.PointInPolygon.time_face_search_lonlat('120km')
165±3μs 147±6μs ~0.89 mpas_ocean.PointInPolygon.time_face_search_lonlat('480km')
174±20μs 181±10μs 1.04 mpas_ocean.PointInPolygon.time_face_search_xyz('120km')
134±10μs 151±10μs ~1.13 mpas_ocean.PointInPolygon.time_face_search_xyz('480km')
76.3±0.3ms 74.3±0.8ms 0.97 mpas_ocean.RemapDownsample.time_bilinear_remapping
13.1±0.2ms 12.9±0.1ms 0.98 mpas_ocean.RemapDownsample.time_inverse_distance_weighted_remapping
11.6±0.1ms 11.7±0.09ms 1.01 mpas_ocean.RemapDownsample.time_nearest_neighbor_remapping
700±4ms 704±2ms 1.01 mpas_ocean.RemapUpsample.time_bilinear_remapping
17.6±0.06ms 19.1±0.09ms 1.09 mpas_ocean.RemapUpsample.time_inverse_distance_weighted_remapping
7.76±0.08ms 7.71±0.06ms 0.99 mpas_ocean.RemapUpsample.time_nearest_neighbor_remapping
5.77±0.1ms 5.74±0.1ms 0.99 mpas_ocean.ZonalAverage.time_zonal_average('120km')
3.29±0.03ms 3.28±0.04ms 1.00 mpas_ocean.ZonalAverage.time_zonal_average('480km')
1.0172490874344067 1.01595956788151 1.00 nogil_scaling.GILScaling.track_gil_scaling
905±5μs 924±8μs 1.02 open_dataset.OpenDataset.time_open_dataset('dataset', 'dataset')
1.75±0.01ms 1.73±0.01ms 0.99 open_dataset.OpenDataset.time_open_dataset('dataset', 'file')
3.51±0.02ms 3.58±0.08ms 1.02 open_dataset.OpenDataset.time_open_dataset('file', 'dataset')
4.35±0.1ms 4.32±0.05ms 0.99 open_dataset.OpenDataset.time_open_dataset('file', 'file')
139±4μs 142±3μs 1.02 open_dataset.OpenDataset.time_open_dataset('grid', 'dataset')
897±20μs 900±20μs 1.00 open_dataset.OpenDataset.time_open_dataset('grid', 'file')
1.06±0.01s 1.04±0.01s 0.98 plots.PlotContour.time_contour_projected
225±4ms 222±3ms 0.98 plots.PlotHealpix.time_default_plot(6)
2.13±0.01s 2.11±0.01s 0.99 plots.PlotHealpix.time_default_plot(8)
28M 27.9M 1.00 plots.PlotHealpix.track_peakmem_default_plot(6)
443M 443M 1.00 plots.PlotHealpix.track_peakmem_default_plot(8)
4.21±0.03ms 4.29±0.02ms 1.02 quad_hexagon.QuadHexagon.time_open_dataset
3.70±0.02ms 3.58±0.01ms 0.97 quad_hexagon.QuadHexagon.time_open_grid
408 408 1.00 quad_hexagon.QuadHexagon.track_nbytes_open_dataset
392 392 1.00 quad_hexagon.QuadHexagon.track_nbytes_open_grid
71.7k 71.8k 1.00 quad_hexagon.QuadHexagon.track_peakmem_open_dataset
71.5k 71.5k 1.00 quad_hexagon.QuadHexagon.track_peakmem_open_grid
5.39±0.3ms 5.38±0.1ms 1.00 subset.BoundingBox.time_bounding_box('120km')
2.83±0.1ms 2.94±0.2ms 1.04 subset.BoundingBox.time_bounding_box('480km')
2.38M 2.38M 1.00 subset.BoundingBox.track_peakmem_bounding_box('120km')
203k 203k 1.00 subset.BoundingBox.track_peakmem_bounding_box('480km')
3.14±0.09ms 3.16±8ms 1.01 subset.BoundingBoxHealpix.time_bounding_box(6)
17.1±0.3ms 16.8±0.6ms 0.98 subset.BoundingBoxHealpix.time_bounding_box(8)
2.08M 2.1M 1.01 subset.BoundingBoxHealpix.track_peakmem_bounding_box(6)
13.2M 13.2M 1.00 subset.BoundingBoxHealpix.track_peakmem_bounding_box(8)
502±7ms 531±30ms 1.06 to_raster.ToRaster.time_to_raster((10000.0, 10.0))
1.09±0.03s 1.08±0.03s 0.99 to_raster.ToRaster.time_to_raster((10000.0, 100.0))
1.25±0.01s 1.24±0.01s 0.99 to_raster.ToRaster.time_to_raster((100000.0, 100.0))
270M 270M 1.00 to_raster.ToRaster.track_peakmem((10000.0, 10.0))
680M 680M 1.00 to_raster.ToRaster.track_peakmem((10000.0, 100.0))
765M 765M 1.00 to_raster.ToRaster.track_peakmem((100000.0, 100.0))
94.4±2μs 95.4±2μs 1.01 to_xarray.UxDataArrayToXarray.time_to_xarray(10)
257±9μs 261±2μs 1.02 to_xarray.UxDatasetToXarray.time_to_xarray((100, 10))
2.29±0.01ms 2.39±0.03ms 1.04 to_xarray.UxDatasetToXarray.time_to_xarray((1000, 100))
570±8μs 568±10μs 1.00 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((100, 10))
5.14±0.09ms 5.19±0.08ms 1.01 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((1000, 100))

Benchmarks that have got worse:

Change Before [b7a43bb] After [b4d3b3c] Ratio Benchmark (Parameter)
+ 314M 386M 1.23 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
+ 314M 386M 1.23 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
+ 314M 386M 1.23 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
+ 314M 386M 1.23 face_bounds.FaceBoundsColdStartRss.track_peakmem_open_and_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/quad-hexagon/grid.nc'))
+ 315M 388M 1.23 import.Imports.track_peakmem_import_uxarray
+ 2 3 1.5 lazy_grid_construction.LazyGridConstruction.track_computes_open_grid_chunked
+ 48.8±2ms 58.6±0.7ms 1.2 lazy_grid_construction.OpenGridChunked.time_open_grid('120km')
+ 2.01M 3.21M 1.6 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('120km')
+ 2.11M 2.42M 1.15 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('480km')
+ 328M 386M 1.18 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 1)
+ 328M 386M 1.18 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 2)
+ 327M 386M 1.18 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 4)
+ 314M 386M 1.23 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 1)
+ 314M 386M 1.23 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 2)
+ 314M 386M 1.23 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 4)
+ 328M 386M 1.18 mpas_ocean.GradientColdStartRss.track_peakmem_gradient('120km')
+ 314M 386M 1.23 mpas_ocean.GradientColdStartRss.track_peakmem_gradient('480km')
+ 328M 386M 1.18 mpas_ocean.ZonalAveragePeakMem.track_peakmem_zonal_average('120km')
+ 314M 386M 1.23 mpas_ocean.ZonalAveragePeakMem.track_peakmem_zonal_average('480km')

@Sevans711 Sevans711 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.

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.

Comment thread uxarray/grid/connectivity.py Resolved
Comment thread uxarray/grid/connectivity.py Resolved
Comment thread uxarray/grid/connectivity.py Resolved
Comment thread uxarray/grid/connectivity.py Resolved
Comment thread uxarray/grid/connectivity.py Resolved

@cmdupuis3 cmdupuis3 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.

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')

cmdupuis3 and others added 2 commits November 23, 2026 14:34
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 <noreply@anthropic.com>
@cmdupuis3

Copy link
Copy Markdown
Collaborator

My last commit should mostly fix the lazy grid construction.

@rajeeja

rajeeja commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

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.
@rajeeja

rajeeja commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

I tested lazy (chunks=) opens on larger local meshes. On the 12.8M node ESMF mesh, which has 11,878 duplicate nodes, main gives a different face_node_connectivity and n_edge for lazy and eager, and this branch matches eager exactly. 0124587 removes two redundant float64 copies in the coincident-node search with no change in results:

Mesh before 0124587 after main
esmf_mesh, 12.8M nodes (traced peak) 2.09 GB 0.93 GB not merged
esmf_mesh (RSS) 2741 MB 1790 MB 267 MB
oRRS18to6v3, 7.4M nodes (RSS) 1560 MB 1015 MB 266 MB
WC14to60E2r5, 0.8M nodes (RSS) 410 MB 351 MB 273 MB
ne256np4 SCRIP, 3.5M nodes (RSS) 2197 MB 2071 MB 2071 MB
oQU120 benchmark (traced peak) 9.91 MB 4.64 MB 4.05 MB

@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.

@erogluorhan

Copy link
Copy Markdown
Member

I'll defer its review to @cmdupuis3 and @Sevans711

rajeeja and others added 2 commits November 24, 2026 12:59
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 <noreply@anthropic.com>
@cmdupuis3

Copy link
Copy Markdown
Collaborator

@rajeeja I got the peakmem down a bit more, can you rerun your tests?

@rajeeja

rajeeja commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@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.

Mesh 0124587 d13c82a main
esmf_mesh, 12.8M nodes (traced peak) 919 MB 574 MB not merged
esmf_mesh (RSS) 1790 MB 1314 MB 267 MB
oRRS18to6v3, 7.4M nodes (RSS) 1008 MB 726 MB 266 MB
WC14to60E2r5, 0.8M nodes (RSS) 347 MB 315 MB 273 MB
ne256np4 SCRIP, 3.5M nodes (RSS) 2067 MB 2125 to 2150 MB 2071 MB
oQU120 (traced peak) 4.59 MB 3.17 MB 4.05 MB

@cmdupuis3 cmdupuis3 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.

I'm guessing this is about as good as peakmem is going to get for now. Approving.

@Sevans711 Sevans711 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.

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:

  1. 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_at function 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!
  2. 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 _subgrid function, 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.

@rajeeja

rajeeja commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

The validation.py changes are all for peakmem: the search now builds only x and |sin(lat)| for every node and full XYZ rows just for prescreen candidates and poles, which took the esmf_mesh traced peak from 919 to 574 MB, and xyz_at has two branches because grids with only node_x/y/z still pass XYZ (connectivity.py:745). The slice.py change doesn't improve on main, since main never merged chunked grids, but it keeps this PR from adding a coordinate load and search to every subset of a merged grid, which track_computes_isel shows by staying at 1 instead of 2. I reworded the overstated _subgrid comment in d77ca5c, updated the overview and merged main.

@rajeeja
rajeeja requested a review from Sevans711 November 25, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working run-benchmark Run ASV benchmark workflow scalability Related to scalability & performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eager and lazy grids with any duplicates now give different results, because #1692 deduplicated eager grids only

4 participants