Skip to content

fix(meshing): extract_region no longer raises (#197) - #253

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/extract-region-kdtree-197
Jun 18, 2026
Merged

fix(meshing): extract_region no longer raises (#197)#253
lmoresi merged 1 commit into
developmentfrom
bugfix/extract-region-kdtree-197

Conversation

@lmoresi

@lmoresi lmoresi commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Mesh.extract_region() raised AttributeError: 'CoordinateSystem' object has no attribute '_get_kdtree' on every call (issue #197). _build_vertex_map called self.X._get_kdtree(), but mesh.X is a CoordinateSystem_get_kdtree lives on MeshVariable/swarm variables, not on it.

Fix

Build the vertex-coincidence KDTree directly on the coordinate arrays, mirroring the proven inline path already used by extract_surface (which carried a comment explicitly flagging this same #197 breakage). Submesh vertices are an exact subset of the parent's, so the 1e-10 coincidence match is bit-exact.

Why it shipped

extract_region had only parallel coverage (test_0770), which skips without --with-mpi and was red-but-not-gating (the branch has no required status checks). This PR adds serial regression tests (test_0771_extract_region.py).

Verification (local, amr-dev env)

  • serial repro on AnnulusInternalBoundary → fixed
  • test_0771_extract_region.py3 passed
  • test_0772_surface_extract.py7 passed, 1 pre-existing xfail (no regression)
  • test_0770_submesh_extract_mpi.py --with-mpi -np 26 passed

Closes #197.

Underworld development team with AI support from Claude Code

)

_build_vertex_map called self.X._get_kdtree(), but mesh.X is a
CoordinateSystem which has no _get_kdtree (that method lives on
MeshVariable / swarm variables) — so every extract_region() raised
AttributeError. Build the vertex-coincidence KDTree directly on the
coordinate arrays instead, mirroring the proven inline path already used
by extract_surface().

extract_region had only parallel coverage (test_0770, which skips without
--with-mpi and was red-but-not-gating). Adds serial regression tests
(test_0771). Verified: serial repro fixed, test_0771 passes (3),
test_0772 surface tests unaffected (7 passed/1 pre-existing xfail),
parallel test_0770 passes (6, np=2).

Closes #197.

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings June 18, 2026 10:53
@lmoresi
lmoresi merged commit 071c563 into development Jun 18, 2026
2 checks passed
@lmoresi
lmoresi deleted the bugfix/extract-region-kdtree-197 branch June 18, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes Mesh.extract_region() raising AttributeError by updating _build_vertex_map() to build a vertex-coincidence KDTree directly from mesh coordinate arrays (matching the already-working extract_surface approach), and adds a serial regression test to prevent recurrence.

Changes:

  • Reworked Mesh._build_vertex_map() to build/query a KDTree using self._coords and self.parent._coords instead of calling the non-existent CoordinateSystem._get_kdtree().
  • Added tests/test_0771_extract_region.py to cover serial extract_region behavior and validate vertex-map consistency and basic geometric bounds.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/underworld3/discretisation/discretisation_mesh.py Fixes _build_vertex_map() to avoid calling _get_kdtree() on CoordinateSystem by building the KDTree from coordinate arrays.
tests/test_0771_extract_region.py Adds serial regression coverage for extract_region, including a vertex-map consistency assertion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to +44
assert np.allclose(
sub_coords[sub_rows], parent_coords[parent_rows], atol=1.0e-10
)
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.

2 participants