Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Laplacian calculation in spectral partitioning #2568

Open
wants to merge 5 commits into
base: branch-25.04
Choose a base branch
from

Conversation

wphicks
Copy link
Contributor

@wphicks wphicks commented Feb 3, 2025

These changes enable the use of the new Lanczos solver for spectral partitioning. This solver gives the correct eigenvalues in some cases where the old solver did not, but a previous attempt to introduce this led to a downstream breakage because the Laplacian was not being calculated correctly in the spectral partitioning logic.

In this PR, we introduce a new compute_graph_laplacian function to correctly generate a new CSR matrix representing the graph Laplacian of the input CSR-formatted adjacency matrix. This resolves #2419. This function is used in the spectral partition function to obtain the correct partitioning using the new Lanczos solver. This eliminates all internal uses of computeSmallestEigenvectors, the old Lanczos implementation, which should allow it to be removed after a deprecation cycle for downstream consumers. This will in turn allow us to resolve #313.

Note that the originally-reported breakage from the previous attempt to switch to the new Lanczos solver was used to create the test confirming correct functionality of the current PR.

This PR is marked as a bugfix because it unblocks usage of the corrected Lanczos implementation. It is based on and requires PR #2541, and it will be marked as draft until that PR is merged.

@wphicks wphicks added bug Something isn't working non-breaking Non-breaking change labels Feb 3, 2025
Copy link

copy-pr-bot bot commented Feb 3, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@wphicks
Copy link
Contributor Author

wphicks commented Feb 3, 2025

The additional "vetting" is required due to missing signatures on commits in #2541. Once it's merged, I'll fix up this PR to include only the additional changes on top of the final version of #2541.

@wphicks
Copy link
Contributor Author

wphicks commented Feb 4, 2025

Also partially answers #379, though we may want additional testing beyond what is provided here.

In the previous implementation of spectral partitioning, the eigenvalue computation was actually performed on the original adjacency matrix, not the graph Laplacian thereof. This change provides a utility for computing the graph Laplacian, which is then fed into the new implementation of the Lanczos solver. An additional test is provided to ensure that the end-to-end spectral partitioning quality is as expected.
@wphicks wphicks force-pushed the bug/laplacian_in_spec_part branch from 99698bd to de85257 Compare February 13, 2025 17:18
Copy link

copy-pr-bot bot commented Feb 13, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@wphicks wphicks marked this pull request as ready for review February 13, 2025 17:19
@wphicks wphicks requested a review from a team as a code owner February 13, 2025 17:19
Comment on lines +61 to +62
const_cast<index_type_t*>(A.row_offsets_),
const_cast<index_type_t*>(A.col_indices_),
Copy link
Member

Choose a reason for hiding this comment

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

Must we do this instead of removing const-reference from the function signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a very good question, and I don't immediately remember why I did it this way. Let me try to figure that out and either fix it or add an explanatory comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Realized that I lifted this from the same logic here. Looks like there were some const-correctness issues in the PR that introduced the new solver. I'll see if I can fix them now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are performing similar casts throughout the codebase around csr_matrix objects. To fix it here and elsewhere, we'll need quite a few changes to csr_matrix to support a const version of the view method. How would we feel about doing that in a follow-up, since it will be a fairly large change in its own right?

@wphicks wphicks requested a review from a team as a code owner February 13, 2025 21:55
@github-actions github-actions bot added the CMake label Feb 13, 2025
namespace spectral {
namespace matrix {
namespace sparse {
namespace linalg {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I just realized this was detail code. Can we please pull this into the detail/ directory and expose a wrapper function around it? That's how we hide the impl details (since this is header only) to make it blatantly clear to users where the public APIs are (it's been more challenging to do this than it should be for header-only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CMake cpp non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Laplacian Sparse primitive for spectral algorithms [BUG] Accuracy of lanczos solver.
3 participants