Skip to content

Fix ReebGraph.boundary_matrix(astype="map") dropping parallel edges - #126

Merged
lizliz merged 3 commits into
masterfrom
125-reebgraphboundary_matrixastypemap-drops-parallel-edges
Sep 24, 2026
Merged

lizliz merged 3 commits into
masterfrom
125-reebgraphboundary_matrixastypemap-drops-parallel-edges

Conversation

@ishikaghosh2201

Copy link
Copy Markdown
Collaborator

Description

boundary_matrix built its edge list with self.edges(), which leaves out the multigraph keys. The map branch then set every key to 0, so all copies of a multi-edge were written to the same dictionary entry (u, v, 0), and only one survived. After an edge was removed, the map could also report a key that no longer exists.

This PR:

  • builds the edge list with self.edges(keys=True), so every edge keeps its real (u, v, key);
  • removes the lines in the map branch that set every key to 0.

The numpy branch only reads e[0] and e[1], so its output doesn't change.

Changes:

  • cereeberus/cereeberus/reeb/reebgraph.py: two small edits in boundary_matrix.
  • tests/test_reeb_class.py: three new tests (see below).

Motivation and Context

Fixes #___

Example with the package's torus graph, which has a double edge ('b', 'c', 0) and ('b', 'c', 1):

Call Before After
ex_rg.torus().boundary_matrix(astype="map") 3 entries for 4 edges; ('b', 'c', 1) missing 4 entries, one per edge
same, after remove_edge('b', 'c', 0) reports ('b', 'c', 0), which was deleted reports ('b', 'c', 1)

Internal code isn't affected. Nothing in the repo uses the map form: plot_boundary_matrix, test_matrices and the mapper_basics docs notebook all use the NumPy form, whose output is unchanged. Code outside the repo that reads the map will now see the real edge keys instead of 0 for every edge.

Related: the open-slice fix (#___) changes a different method; the two PRs don't conflict.

How has this been tested?

New tests in tests/test_reeb_class.py:

  • test_boundary_map_parallel_edges: on the torus example, the map has exactly one entry per edge, including both copies of the double edge, and each entry maps to that edge's two endpoints.
  • test_boundary_map_keys_after_edge_removal: after remove_edge('b', 'c', 0), the map contains ('b', 'c', 1) and not the removed key.
  • test_boundary_matrix_numpy_with_parallel_edges: the NumPy matrix has one column per edge, and each column has exactly two 1s.

The first two fail on master and pass with this change. The third passes on both, which confirms the NumPy output is unchanged.

make tests: all 87 tests pass (84 existing + 3 new).

I also compared the NumPy boundary matrix before and after the change on the package's example graphs (Reeb, mapper and merge trees) and on random Reeb graphs. Every matrix came out identical. The map changed only on graphs with parallel edges, and on each of those it went from missing entries to one entry per edge.

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 23, 2026 18:38
@ishikaghosh2201 ishikaghosh2201 linked an issue Sep 23, 2026 that may be closed by this pull request

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.

@lizliz
lizliz merged commit 99791b1 into master Sep 24, 2026
4 checks passed
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.

ReebGraph.boundary_matrix(astype="map") drops parallel edges

3 participants