Skip to content

Sparse SVD #1566

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 392 additions & 0 deletions idaes/core/util/linalg.py

Large diffs are not rendered by default.

31 changes: 28 additions & 3 deletions idaes/core/util/model_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
ParameterSweepBase,
is_psweepspec,
)
from idaes.core.util.linalg import svd_rayleigh_ritz

import idaes.logger as idaeslog

_log = idaeslog.getLogger(__name__)
Expand Down Expand Up @@ -200,6 +202,29 @@
return u, s, vT.transpose()


def svd_rayleigh_ritz_callback(jacobian, number_singular_values, **kwargs):
"""
Callback for performing SVD analysis using idaes.core.util.linalg.svd_rayleigh_ritz

Args:
jacobian: Jacobian to be analysed
number_singular_values: number of singular values to compute
**kwargs: Dictionary of keyword arguments to pass to svd_rayleigh_ritz

Returns:
u, s and v numpy arrays

"""
# This method also returns the null space, which is not used by
# the model diagnostics at present
m, n = jacobian.shape
if m != n:
u, s, v, _ = svd_rayleigh_ritz(jacobian, number_singular_values, **kwargs)

Check warning on line 222 in idaes/core/util/model_diagnostics.py

View workflow job for this annotation

GitHub Actions / Pylint

W0632 (unbalanced-tuple-unpacking)

Possible unbalanced tuple unpacking with sequence defined at line 390 of idaes.core.util.linalg: left side has 4 labels, right side has 3 values

Check warning on line 222 in idaes/core/util/model_diagnostics.py

View check run for this annotation

Codecov / codecov/patch

idaes/core/util/model_diagnostics.py#L222

Added line #L222 was not covered by tests
else:
u, s, v = svd_rayleigh_ritz(jacobian, number_singular_values, **kwargs)
return u, s, v


CONFIG = ConfigDict()
CONFIG.declare(
"variable_bounds_absolute_tolerance",
Expand Down Expand Up @@ -363,10 +388,10 @@
SVDCONFIG.declare(
"svd_callback",
ConfigValue(
default=svd_dense,
default=svd_rayleigh_ritz_callback,
domain=svd_callback_validator,
description="Callback to SVD method of choice (default = svd_dense)",
doc="Callback to SVD method of choice (default = svd_dense). "
description="Callback to SVD method of choice (default = svd_rayleigh_ritz_callback)",
doc="Callback to SVD method of choice (default = svd_rayleigh_ritz_callback). "
"Callbacks should take the Jacobian and number of singular values "
"to compute as options, plus any method specific arguments, and should "
"return the u, s and v matrices as numpy arrays.",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading