Skip to content

Merge coincident nodes for dask-backed grids - #1915

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

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

Conversation

@rajeeja

@rajeeja rajeeja commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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 with map_blocks, so it is never computed at open time. _prepare_for_dual is removed because grids are now 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 stayed the same:

Change Before [ad45eec] After [c2f052f] Ratio Benchmark (Parameter)
1.04±0.02ms 1.05±0.02ms 1.01 connectivity.Connectivity.time_edge_face('120km')
338±3μs 335±10μs 0.99 connectivity.Connectivity.time_edge_face('480km')
3.83±0.1ms 2.44±0.05ms ~0.64 connectivity.Connectivity.time_edge_node('120km')
767±20μs 788±20μs 1.03 connectivity.Connectivity.time_edge_node('480km')
47.8±3μs 45.7±3μs 0.96 connectivity.Connectivity.time_face_edge('120km')
43.0±3μs 41.5±2μs 0.97 connectivity.Connectivity.time_face_edge('480km')
797±20μs 763±40μs 0.96 connectivity.Connectivity.time_face_face('120km')
310±8μs 306±10μs 0.99 connectivity.Connectivity.time_face_face('480km')
46.4±4μs 44.2±8μs 0.95 connectivity.Connectivity.time_face_node('120km')
42.9±3μs 39.4±8μs 0.92 connectivity.Connectivity.time_face_node('480km')
483±40μs 447±30μs 0.92 connectivity.Connectivity.time_n_nodes_per_face('120km')
298±20μs 273±20μs 0.91 connectivity.Connectivity.time_n_nodes_per_face('480km')
1.10±0.04ms 958±30μs ~0.87 connectivity.Connectivity.time_node_edge('120km')
310±3μs 308±10μs 0.99 connectivity.Connectivity.time_node_edge('480km')
54.7±0.4ms 52.6±0.2ms 0.96 connectivity.Connectivity.time_node_face('120km')
3.46±0.02ms 3.41±0.04ms 0.98 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')
7.21±0.1ms 7.15±0.07ms 0.99 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
2.52±0.05ms 2.66±0.1ms 1.05 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
8.43±0.2ms 8.72±8ms 1.04 face_bounds.FaceBounds.time_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/ugrid/geoflow-small/grid.nc'))
1.48±0.05ms 1.46±0.04ms 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.72M 1.72M 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/mpas/QU/oQU480.231010.nc'))
1.7M 1.7M 1.00 face_bounds.FaceBounds.track_peakmem_face_bounds(PosixPath('/home/runner/work/uxarray/uxarray/test/meshfiles/scrip/outCSne8/outCSne8.nc'))
1.86M 1.86M 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.00±0.09μs 942±30ns 0.94 geometry_kernels.AccucrossKernels.time_accucross
2.32±0.04μs 2.37±0.07μs 1.02 geometry_kernels.AccucrossKernels.time_accucross_pair
351±30ns 336±30ns 0.96 geometry_kernels.EFTPrimitives.time_acc_sqrt_re
351±40ns 372±50ns 1.06 geometry_kernels.EFTPrimitives.time_diff_of_products
313±40ns 330±20ns 1.05 geometry_kernels.EFTPrimitives.time_two_prod
283±30ns 320±30ns ~1.13 geometry_kernels.EFTPrimitives.time_two_sum
611±10ns 601±10ns 0.98 geometry_kernels.GCAConstLatIntersection.time_accux_constlat_kernel
671±20ns 701±10ns 1.04 geometry_kernels.GCAConstLatIntersection.time_gca_const_lat_intersection
741±7ns 731±20ns 0.99 geometry_kernels.GCAConstLatIntersection.time_try_gca_const_lat_intersection
822±50ns 841±30ns 1.02 geometry_kernels.GCAGCAIntersection.time_accux_gca_kernel
932±20ns 886±30ns 0.95 geometry_kernels.GCAGCAIntersection.time_gca_gca_intersection
1.12±0.05μs 1.07±0.03μs 0.96 geometry_kernels.GCAGCAIntersection.time_try_gca_gca_intersection
48.1±3μs 51.1±0.4μs 1.06 geometry_kernels.OrientPredicates.time_on_minor_arc
49.4±0.6μs 51.7±0.9μs 1.05 geometry_kernels.OrientPredicates.time_orient3d_on_sphere
3.31±0.02ms 3.32±0.01ms 1.00 geometry_samebody.SameBodyConstLat.time_accux_dispatch
1.33±0ms 1.32±0ms 1.00 geometry_samebody.SameBodyConstLat.time_accux_kernel
2.28±0.02ms 2.29±0.02ms 1.01 geometry_samebody.SameBodyConstLat.time_fp64_dispatch
152±0.7μs 153±0.3μs 1.00 geometry_samebody.SameBodyConstLat.time_fp64_kernel
32.5±0.06ms 33.8±0.06ms 1.04 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_dispatch
6.74±0.04ms 6.80±0.04ms 1.01 geometry_samebody_gcagca.SameBodyGcaGca.time_accux_kernel
25.7±0.01ms 27.5±0.1ms 1.07 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_dispatch
864±4μs 868±2μs 1.00 geometry_samebody_gcagca.SameBodyGcaGca.time_fp64_kernel
817±9ms 825±20ms 1.01 import.Imports.timeraw_import_uxarray
1 1 1.00 lazy_grid_construction.LazyGridConstruction.track_computes_isel
99.7±0.4ms 105±0.9ms 1.05 lazy_grid_construction.OpenGridChunked.time_open_grid('480km')
2.3M 2.42M 1.05 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('480km')
1.91±0.04ms 1.82±0.02ms 0.96 mpas_ocean.AzimuthalAverage.time_azimuthal_average('120km')
780±10μs 761±4μs 0.98 mpas_ocean.AzimuthalAverage.time_azimuthal_average('480km')
2.54±0.03ms 2.72±0.06ms 1.07 mpas_ocean.CheckNorm.time_check_norm('120km')
1.58±0.01ms 1.69±0.02ms 1.07 mpas_ocean.CheckNorm.time_check_norm('480km')
1.09±0.02ms 1.07±0.02ms 0.98 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('120km')
461±10μs 471±7μs 1.02 mpas_ocean.ConnectivityConstruction.time_face_face_connectivity('480km')
697±10μs 618±9μs ~0.89 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('120km')
509±5μs 516±7μs 1.01 mpas_ocean.ConnectivityConstruction.time_n_nodes_per_face('480km')
4.27±0.02ms 4.21±0.02ms 0.99 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('120km')
3.17±0.06ms 3.10±0ms 0.98 mpas_ocean.ConstructFaceLatLon.time_cartesian_averaging('480km')
111±0.4ms 113±0.8ms 1.02 mpas_ocean.ConstructFaceLatLon.time_welzl('120km')
9.71±0.02ms 10.2±0.3ms 1.05 mpas_ocean.ConstructFaceLatLon.time_welzl('480km')
20.0±0.05ms 20.2±0.2ms 1.01 mpas_ocean.ConstructTreeStructures.time_ball_tree('120km')
1.04±0.02ms 1.04±0.01ms 1.01 mpas_ocean.ConstructTreeStructures.time_ball_tree('480km')
10.5±0.02ms 10.1±0.04ms 0.96 mpas_ocean.ConstructTreeStructures.time_kd_tree('120km')
669±40μs 639±10μs 0.96 mpas_ocean.ConstructTreeStructures.time_kd_tree('480km')
596±8ms 547±3ms 0.92 mpas_ocean.CrossSections.time_const_lat('120km', 1)
295±1ms 282±4ms 0.96 mpas_ocean.CrossSections.time_const_lat('120km', 2)
152±2ms 140±2ms 0.92 mpas_ocean.CrossSections.time_const_lat('120km', 4)
519±3ms 487±8ms 0.94 mpas_ocean.CrossSections.time_const_lat('480km', 1)
262±3ms 246±4ms 0.94 mpas_ocean.CrossSections.time_const_lat('480km', 2)
129±0.5ms 125±0.9ms 0.97 mpas_ocean.CrossSections.time_const_lat('480km', 4)
27.4±0.2ms 25.7±0.1ms 0.94 mpas_ocean.DualMesh.time_dual_mesh_construction('120km')
3.26±0.3ms 2.97±0.03ms 0.91 mpas_ocean.DualMesh.time_dual_mesh_construction('480km')
11.6±1ms 11.1±0.4ms 0.96 mpas_ocean.FaceAreas.time_face_areas('120km')
4.01±0.2ms 3.94±0.2ms 0.98 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')
674k 673k 1.00 mpas_ocean.FaceAreas.track_peakmem_face_areas('480km')
52.4±0.5ms 53.5±1ms 1.02 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'exclude')
141±3ms 139±2ms 0.99 mpas_ocean.GeoDataFrame.time_to_geodataframe('120km', 'split')
5.05±0.2ms 5.54±0.1ms 1.10 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'exclude')
26.0±0.1ms 25.7±0.2ms 0.99 mpas_ocean.GeoDataFrame.time_to_geodataframe('480km', 'split')
13.9±0.4ms 13.5±0.09ms 0.97 mpas_ocean.Gradient.time_gradient('120km')
2.32±0.01ms 2.33±0.02ms 1.01 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')
309±9μs 268±10μs ~0.87 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('120km')
117±2μs 110±0.8μs 0.94 mpas_ocean.HoleEdgeIndices.time_construct_hole_edge_indices('480km')
230±10μs 214±9μs 0.93 mpas_ocean.Integrate.time_integrate('120km')
154±0.6μs 151±5μs 0.98 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')
81.2±0.4ms 81.1±0.8ms 1.00 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'exclude')
82.2±0.7ms 81.2±0.9ms 0.99 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'include')
82.2±0.6ms 81.2±0.4ms 0.99 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('120km', 'split')
6.09±0.06ms 6.00±0.03ms 0.98 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'exclude')
5.99±0.04ms 6.03±0.08ms 1.01 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'include')
5.96±0.04ms 6.02±0.03ms 1.01 mpas_ocean.MatplotlibConversion.time_dataarray_to_polycollection('480km', 'split')
264±2ms 263±1ms 0.99 mpas_ocean.NeighborhoodBuild.time_build('120km', 1.0)
542±2ms 543±3ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('120km', 5.0)
14.3±0.06ms 14.2±0.02ms 1.00 mpas_ocean.NeighborhoodBuild.time_build('480km', 1.0)
17.6±0.2ms 17.8±0.2ms 1.01 mpas_ocean.NeighborhoodBuild.time_build('480km', 5.0)
258±2ms 261±2ms 1.01 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 1.0)
538±3ms 540±1ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('120km', 5.0)
13.8±0.01ms 13.9±0.03ms 1.00 mpas_ocean.NeighborhoodBuild.time_query_radius('480km', 1.0)
17.4±0.1ms 17.3±0.02ms 1.00 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)
40.4±0.5ms 39.7±0.3ms 0.98 mpas_ocean.NeighborhoodDask.time_mean('120km', 'grid_chunks')
17.9±0.08ms 18.2±0.04ms 1.02 mpas_ocean.NeighborhoodDask.time_mean('120km', 'numpy')
36.5±0.9ms 37.1±0.9ms 1.02 mpas_ocean.NeighborhoodDask.time_mean('120km', 'time_chunks')
10.6±0.3ms 10.2±0.2ms 0.96 mpas_ocean.NeighborhoodDask.time_mean('480km', 'grid_chunks')
643±5μs 624±20μs 0.97 mpas_ocean.NeighborhoodDask.time_mean('480km', 'numpy')
7.16±0.1ms 7.20±0.09ms 1.01 mpas_ocean.NeighborhoodDask.time_mean('480km', 'time_chunks')
5.82M 5.82M 1.00 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 677k 0.91 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'grid_chunks')
177k 177k 1.00 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'numpy')
534k 528k 0.99 mpas_ocean.NeighborhoodDask.track_peakmem_mean('480km', 'time_chunks')
2.40±0.01s 2.40±0.01s 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'mean')
2.52±0s 2.51±0s 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('120km', 'median')
68.8±0.07ms 69.4±0.3ms 1.01 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'mean')
70.8±0.1ms 71.0±0.4ms 1.00 mpas_ocean.NeighborhoodReduce.time_dataset_reduce('480km', 'median')
261±0.8ms 262±1ms 1.01 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'mean')
287±0.4ms 287±2ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('120km', 'median')
9.73±0.02ms 9.76±0.02ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'mean')
10.0±0.02ms 10.1±0.03ms 1.00 mpas_ocean.NeighborhoodReduce.time_neighborhood_reduce('480km', 'median')
2.93±0.01ms 2.94±0.01ms 1.00 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'mean')
29.9±0.1ms 29.7±0.3ms 0.99 mpas_ocean.NeighborhoodReduce.time_reduce('120km', 'median')
143±1μs 142±0.7μs 0.99 mpas_ocean.NeighborhoodReduce.time_reduce('480km', 'mean')
423±10μs 418±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')
410±10μs 403±30μs 0.98 mpas_ocean.PointInPolygon.time_face_search_lonlat('120km')
328±30μs 360±4μs 1.10 mpas_ocean.PointInPolygon.time_face_search_lonlat('480km')
357±30μs 365±20μs 1.02 mpas_ocean.PointInPolygon.time_face_search_xyz('120km')
318±30μs 288±20μs ~0.91 mpas_ocean.PointInPolygon.time_face_search_xyz('480km')
95.6±0.7ms 92.0±0.8ms 0.96 mpas_ocean.RemapDownsample.time_bilinear_remapping
15.3±0.1ms 15.2±0.3ms 0.99 mpas_ocean.RemapDownsample.time_inverse_distance_weighted_remapping
13.7±0.1ms 13.7±0.2ms 1.00 mpas_ocean.RemapDownsample.time_nearest_neighbor_remapping
929±3ms 905±10ms 0.97 mpas_ocean.RemapUpsample.time_bilinear_remapping
23.5±0.1ms 25.5±0.7ms 1.08 mpas_ocean.RemapUpsample.time_inverse_distance_weighted_remapping
10.6±0.2ms 10.5±0.09ms 0.99 mpas_ocean.RemapUpsample.time_nearest_neighbor_remapping
7.80±0.2ms 7.85±0.1ms 1.01 mpas_ocean.ZonalAverage.time_zonal_average('120km')
4.19±0.04ms 4.27±0.1ms 1.02 mpas_ocean.ZonalAverage.time_zonal_average('480km')
1.0809102310005827 1.057305739454373 0.98 nogil_scaling.GILScaling.track_gil_scaling
1.35±0.03ms 1.30±0.02ms 0.96 open_dataset.OpenDataset.time_open_dataset('dataset', 'dataset')
2.39±0.08ms 2.27±0.02ms 0.95 open_dataset.OpenDataset.time_open_dataset('dataset', 'file')
5.26±0.08ms 5.20±0.07ms 0.99 open_dataset.OpenDataset.time_open_dataset('file', 'dataset')
6.09±0.2ms 6.27±0.06ms 1.03 open_dataset.OpenDataset.time_open_dataset('file', 'file')
202±10μs 182±4μs ~0.90 open_dataset.OpenDataset.time_open_dataset('grid', 'dataset')
1.17±0.04ms 1.17±0.02ms 1.00 open_dataset.OpenDataset.time_open_dataset('grid', 'file')
1.95±0.01s 2.00±0.01s 1.02 plots.PlotContour.time_contour_projected
316±5ms 317±3ms 1.00 plots.PlotHealpix.time_default_plot(6)
2.78±0s 2.83±0.02s 1.02 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)
5.95±0.03ms 5.96±0.01ms 1.00 quad_hexagon.QuadHexagon.time_open_dataset
5.02±0.06ms 5.05±0.03ms 1.01 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.8k 71.8k 1.00 quad_hexagon.QuadHexagon.track_peakmem_open_dataset
71.5k 71.5k 1.00 quad_hexagon.QuadHexagon.track_peakmem_open_grid
9.61±0.2ms 9.36±0.3ms 0.97 subset.BoundingBox.time_bounding_box('120km')
5.48±0.2ms 5.33±0.08ms 0.97 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.78±0.07ms 3.86±10ms 1.02 subset.BoundingBoxHealpix.time_bounding_box(6)
14.4±0.2ms 14.4±0.2ms 1.00 subset.BoundingBoxHealpix.time_bounding_box(8)
2.13M 2.15M 1.01 subset.BoundingBoxHealpix.track_peakmem_bounding_box(6)
13.2M 13.2M 1.00 subset.BoundingBoxHealpix.track_peakmem_bounding_box(8)
638±3ms 632±3ms 0.99 to_raster.ToRaster.time_to_raster((10000.0, 10.0))
1.36±0.01s 1.34±0.02s 0.99 to_raster.ToRaster.time_to_raster((10000.0, 100.0))
1.58±0.01s 1.54±0.02s 0.97 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))
104±2μs 102±3μs 0.98 to_xarray.UxDataArrayToXarray.time_to_xarray(10)
311±8μs 310±6μs 1.00 to_xarray.UxDatasetToXarray.time_to_xarray((100, 10))
2.89±0.07ms 2.90±0.02ms 1.00 to_xarray.UxDatasetToXarray.time_to_xarray((1000, 100))
685±3μs 690±10μs 1.01 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((100, 10))
6.31±0.04ms 6.25±0.1ms 0.99 to_xarray.UxDatasetToXarray.time_to_xarray_healpix((1000, 100))

Benchmarks that have got worse:

Change Before [ad45eec] After [c2f052f] 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'))
+ 314M 386M 1.23 import.Imports.track_peakmem_import_uxarray
+ 2 3 1.5 lazy_grid_construction.LazyGridConstruction.track_computes_open_grid_chunked
+ 72.4±0.5ms 84.3±0.3ms 1.17 lazy_grid_construction.OpenGridChunked.time_open_grid('120km')
+ 1.99M 3.32M 1.67 lazy_grid_construction.OpenGridChunked.track_peakmem_open_grid('120km')
+ 327M 388M 1.18 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 1)
+ 327M 388M 1.19 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 2)
+ 327M 388M 1.18 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('120km', 4)
+ 315M 388M 1.23 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 1)
+ 315M 388M 1.23 mpas_ocean.CrossSectionsPeakMem.track_peakmem_const_lat('480km', 2)
+ 315M 388M 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 <[email protected]>
@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 <[email protected]>
@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.

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