Make EigenSolver and NonlinearVariationalSolver have an OptionsManager, not be one#5251
Open
connorjward wants to merge 3 commits into
Open
Make EigenSolver and NonlinearVariationalSolver have an OptionsManager, not be one#5251connorjward wants to merge 3 commits into
connorjward wants to merge 3 commits into
Conversation
Composition > inheritance. This is a step along the way to cleaning up the appctxs in Firedrake.
connorjward
marked this pull request as ready for review
July 15, 2026 14:14
dham
approved these changes
Jul 21, 2026
JHopeCollins
requested changes
Jul 21, 2026
JHopeCollins
left a comment
Member
There was a problem hiding this comment.
Suggested updates to the EigenSolver to use the petsctools.options free functions. This mean that the OptionsManager is attached directly to the PETSc object and we don't have to carry it around separately.
Similar edits needed for the NLVS.
See demo for full example: https://www.firedrakeproject.org/petsctools/appctx.html#the-options-and-the-appcontext
| from functools import cached_property | ||
|
|
||
| from petsc4py import PETSc | ||
| from petsctools import OptionsManager, flatten_parameters |
Member
There was a problem hiding this comment.
Suggested change
| from petsctools import OptionsManager, flatten_parameters | |
| import petsctools |
Comment on lines
+169
to
+170
| self.options_manager = OptionsManager(solver_parameters, options_prefix) | ||
| self.options_manager.set_from_options(self.es) |
Member
There was a problem hiding this comment.
Suggested change
| self.options_manager = OptionsManager(solver_parameters, options_prefix) | |
| self.options_manager.set_from_options(self.es) | |
| petsctools.set_from_options(self.es, solver_parameters, options_prefix) |
|
|
||
| @property | ||
| def parameters(self) -> dict: | ||
| return self.options_manager.parameters |
Member
There was a problem hiding this comment.
Suggested change
| return self.options_manager.parameters | |
| return petsctools.get_options(self.es).parameters |
|
|
||
| @property | ||
| def options_prefix(self) -> str: | ||
| return self.options_manager.options_prefix |
Member
There was a problem hiding this comment.
Suggested change
| return self.options_manager.options_prefix | |
| return petsctools.get_options(self.es).options_prefix |
Comment on lines
+180
to
+186
| def set_from_options(self, snes: PETSc.SNES) -> None: | ||
| warnings.warn( | ||
| "'LinearEigensolver.set_from_options' is deprecated, use " | ||
| "'LinearEigensolver.options_manager.set_from_options' instead", | ||
| FutureWarning | ||
| ) | ||
| self.options_manager.set_from_options(snes) |
Member
There was a problem hiding this comment.
Suggested change
| def set_from_options(self, snes: PETSc.SNES) -> None: | |
| warnings.warn( | |
| "'LinearEigensolver.set_from_options' is deprecated, use " | |
| "'LinearEigensolver.options_manager.set_from_options' instead", | |
| FutureWarning | |
| ) | |
| self.options_manager.set_from_options(snes) | |
| def set_from_options(self, snes: PETSc.SNES) -> None: | |
| warnings.warn( | |
| "'LinearEigensolver.set_from_options' is deprecated, " | |
| "'the ES has already been set from options.", | |
| FutureWarning | |
| ) |
Comment on lines
+188
to
+194
| def inserted_options(self): | ||
| warnings.warn( | ||
| "'LinearEigensolver.inserted_options' is deprecated, use " | ||
| "'LinearEigensolver.options_manager.inserted_options' instead", | ||
| FutureWarning | ||
| ) | ||
| return self.options_manager.inserted_options() |
Member
There was a problem hiding this comment.
Suggested change
| def inserted_options(self): | |
| warnings.warn( | |
| "'LinearEigensolver.inserted_options' is deprecated, use " | |
| "'LinearEigensolver.options_manager.inserted_options' instead", | |
| FutureWarning | |
| ) | |
| return self.options_manager.inserted_options() | |
| def inserted_options(self): | |
| warnings.warn( | |
| "'LinearEigensolver.inserted_options' is deprecated, use " | |
| "'petsctools.inserted_options(LinearEigensolver.es)' instead", | |
| FutureWarning | |
| ) | |
| return petsctools.inserted_options(self.es) |
| self.es.setDimensions(nev=self.n_evals, ncv=self.ncv, mpd=self.mpd) | ||
| self.es.setOperators(self.A_mat, self.M_mat) | ||
| with self.inserted_options(): | ||
| with self.options_manager.inserted_options(): |
Member
There was a problem hiding this comment.
Suggested change
| with self.options_manager.inserted_options(): | |
| with petsctools.inserted_options(self.es): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Composition > inheritance.
This is a step along the way to cleaning up the appctxs in Firedrake.
I've also cleaned up the imports a little.