Skip to content

Fix ValueError from ULP-adjacent tied filtration values in computeReeb - #112

Open
ishikaghosh2201 wants to merge 1 commit into
masterfrom
fix-tied-vertices-valueerror
Open

ishikaghosh2201 wants to merge 1 commit into
masterfrom
fix-tied-vertices-valueerror

Conversation

@ishikaghosh2201

Copy link
Copy Markdown
Collaborator

Description

Fixes a crash in computeReeb that occurs when two distinct filtration
values are exactly 1 float64 ULP apart. computeReeb's half-edge
sentinel height, (now_min + now_max) / 2, has no representable float
strictly between two ULP-adjacent values, so the computed midpoint
rounds to exactly now_max -- making the sentinel numerically
indistinguishable from a real Reeb node about to be created at that
height. This spuriously triggers add_edge's equal-height "collapse"
branch (intended only for genuine ties), deleting the real vertex
before a later step tries to connect to it, causing:

ValueError: The vertex X must be in the Reeb graph to add an edge between them.

Fix:
snap chains of filtration values that are numerically
indistinguishable at float64 precision (rtol=1e-9, atol=1e-12)
into one canonical value, before grouping vertices into sweep levels,
using the same "does the midpoint round back to one of the endpoints"
test that exposes the bug. The snapped values are then used
consistently for both level grouping and simplex classification
(upper / horizontal / lower). The original LowerStar object (K)
is never mutated.

Motivation and Context

This is a more general version of a previously-closed issue
(computeReeb error, closed 2026-03-20), which fixed the case of
exact tied heights. That fix does not cover the case where two
values are merely float64-indistinguishable rather than literally
equal -- which happens naturally on symmetric meshes (e.g. an
icosphere), where vertices with the same true height are computed
along different subdivision paths and land 1 ULP apart due to
floating-point rounding, not due to any real geometric difference.

Fixes #111

How has this been tested?

  • Unit tests: python -m unittest discover -s tests -p 'test_*.py'
    -- all tests passing.
  • New regression coverage added in tests/test_computereeb.py:
    • TestMergeCloseValues: direct unit tests on the new
      _merge_close_values helper -- confirms ULP-adjacent values are
      merged, genuinely distinct values are left untouched, and a
      3-value chain all snaps to one representative.
    • TestComputeReebTiedHeights: a minimal, hand-traceable 5-vertex
      case with two ULP-adjacent heights no longer raises ValueError
      and produces a valid tree (edges == nodes - 1); a genuine
      exact-tie case (the originally-fixed bug) still works, guarding
      against regression; the docstring example (no near-ties) produces
      identical node/edge counts to pre-fix behavior.
    • TestComputeReebTiedHeightsRealMesh (skipped if trimesh isn't
      installed): reproduces the original real-world crash on an
      icosphere (subdivisions=2) and confirms it now succeeds with
      81 nodes / 80 edges, a valid tree.
  • Manually verified bit-identical output (R.f, node set, edge set)
    between the patched and unpatched computeReeb on non-degenerate
    cases (docstring example, subdivisions=1 icosphere) -- confirming
    this fix is a no-op everywhere the bug doesn't apply.
  • Manually verified against real gap-distribution data: on the
    subdivisions=2 icosphere, only 2 of 42 unique vertex heights sit
    within the merge tolerance of each other; the next-smallest gap in
    the dataset is ~9 orders of magnitude larger, so there's no
    ambiguous middle ground being swept in by this tolerance choice.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have incremented the version number in the pyproject.toml file if a new version needs to be pushed to pypi. Note that if the number isn't incremented, the package will not be pushed to pypi, which is useful if this PR is only for updating documentation.
  • My code follows the code style of this project and I have run make format to clean up the code with black.
  • My change requires a change to the documentation. I have updated the documentation as necessary and compiled locally to ensure it is clean.
  • I have added tests to cover my changes, and all new and existing tests passed (run make tests).

@ishikaghosh2201
ishikaghosh2201 requested review from lizliz and a lite review from Copilot September 18, 2026 15:52

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

computeReeb raises ValueError on near duplicate filtration values, even after the original tied-heights fix

2 participants