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

Matrix-Free Linear Operator #7

Merged
merged 13 commits into from
Jul 19, 2024
Merged

Matrix-Free Linear Operator #7

merged 13 commits into from
Jul 19, 2024

Conversation

e-moral-sanchez
Copy link
Collaborator

@e-moral-sanchez e-moral-sanchez commented Jul 4, 2024

This PR provides a MatrixFreeLinearOperator class which is a subclass of the abstract class LinearOperator.

The new class allows to create a general matrix-free linear operator. The constructor only requires the domain, codomain and a callable dot method.

Notes:

  • the provided dot method may or may not take an 'out' argument
  • a transpose_dot method may also be provided (mandatory to instantiate the transpose() linear operator)
  • unit tests have been added

Additional change:

  • in this PR we stop passing the deprecated tol argument in calls to scipy's minres. This forces us to use scipy >= 1.14 and hence python >= 3.9
  • we also added a convergence verification in minres linear solver to avoid iterating when the initial solution is good enough (which may cause a division-by-zero error)

@campospinto
Copy link
Owner

This is useful I think, thanks!

As a test, you can check the behaviour of a "fake" matrix-free operator: an operator created with a dot product involving a Stencil Matrix should act exactly like the matrix itself.

You can also check that an iterative solver (like cg) can run with an object of this new class.

@campospinto
Copy link
Owner

I see that some tests are failing because of minres() getting an unexpected keyword argument tol. Is this related to this new class?

@e-moral-sanchez
Copy link
Collaborator Author

The new version 1.14.0 of SciPy removed the tol argument in minres: https://docs.scipy.org/doc/scipy-1.13.1/reference/generated/scipy.sparse.linalg.minres.html

This also affects PR #6 .

I will fix this in this PR.

@campospinto
Copy link
Owner

campospinto commented Jul 12, 2024

This PR provides the class MatrixFreeLinearOperator, which is a subclass of the abstract class LinearOperator.

The class MatrixFreeLinearOperator allows to create a general matrix-free linear operator. The constructor only requires the domain, codomain and a callable dot method.

TODO: add simple unit tests (ideas are welcome!)

I am just adding a few unit tests

@campospinto
Copy link
Owner

campospinto commented Jul 12, 2024

I am also adding some features to handle the case where the given dot method has not optional 'out' argument, and the possibility (not mandatory) to pass a 'transpose_dot' method

campospinto and others added 4 commits July 12, 2024 19:47
Calls to scipy `minres` now use `rtol` instead of `tol` to support  version 1.14.0, but this causes previous versions of scipy to fail
calls to scipy's minres now only use rtol which prevents from using scipy < 1.14. In turns this prevent from using python3.8 which is close to being unsupported anyway, see https://devguide.python.org/versions/
@campospinto campospinto self-assigned this Jul 16, 2024
@campospinto campospinto added bug Something isn't working enhancement New feature or request labels Jul 16, 2024
@campospinto campospinto merged commit 0988f76 into devel Jul 19, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants