fix(meshing): extract_region no longer raises (#197) - #253
Merged
Conversation
) _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
Contributor
There was a problem hiding this comment.
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 usingself._coordsandself.parent._coordsinstead of calling the non-existentCoordinateSystem._get_kdtree(). - Added
tests/test_0771_extract_region.pyto cover serialextract_regionbehavior 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 | ||
| ) |
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.
Summary
Mesh.extract_region()raisedAttributeError: 'CoordinateSystem' object has no attribute '_get_kdtree'on every call (issue #197)._build_vertex_mapcalledself.X._get_kdtree(), butmesh.Xis aCoordinateSystem—_get_kdtreelives onMeshVariable/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_regionhad only parallel coverage (test_0770), which skips without--with-mpiand 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)
AnnulusInternalBoundary→ fixedtest_0771_extract_region.py→ 3 passedtest_0772_surface_extract.py→ 7 passed, 1 pre-existing xfail (no regression)test_0770_submesh_extract_mpi.py --with-mpi -np 2→ 6 passedCloses #197.
Underworld development team with AI support from Claude Code