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

Sparse SVD #1566

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Sparse SVD #1566

wants to merge 6 commits into from

Conversation

dallan-keylogic
Copy link
Contributor

Summary/Motivation:

Presently, the SVDToolbox isn't widely utilized, in part because of the limited options for calculating the SVD. Scipy's dense SVD is time-consuming on problems larger than 1000x1000, while its sparse SVD does not work well to find the singular values of the smallest magnitude.

Therefore, I've implemented a custom version of the SVD that uses simultaneous inverse iteration. Due to limited options for sparse matrix factorization available in Scipy, we must explicitly form a normal matrix A.T @ A or A @ A.T in order to invert it, which reduces numerical precision of the results from ~1e-16 to ~1e-8. Therefore a second refinement step is used, in order to project A into its near-null space computed through the inverse iteration and then computes a dense SVD of that matrix, reduces an n by n matrix calculation to an n by n_vec matrix computation, which can be computed rapidly.

In order to try out the new method, check out this branch, optionally merge it into your working branch, then set the svd callback:

import pyomo.environ as pyo
from idaes.core.util.linalg import svd_explicit_normal
from idaes.core.util.model_diagnostics import SVDToolbox

...

m_scaled = pyo.TransformationFactory("core.scale_model").create_using(m, rename=False)
svd_tbx = SVDToolbox(m_scaled)
svd_tbx.config.svd_callback = svd_explicit_normal
svd_tbx.display_underdetermined_variables_and_constraints()
# If you want to view the singular values in addition to the variables and constraints
svd_tbx.s

I'd appreciate testers for this method before we merge it.

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants