Convert PC Python objects into strings - #46
Draft
connorjward wants to merge 3 commits into
Draft
Conversation
| for key, value in parameters.items(): | ||
| if not isinstance(value, _native_petsc_option_types): | ||
| # Convert Python PC objects into their string representation | ||
| if key.endswith("python_type") and isinstance(value, type): |
Member
There was a problem hiding this comment.
Can we let the user do a single options entry:
"pc_type": module.FancyPCand under the hood we split this into the pc_type and pc_python_type options?
Suggested change
| if key.endswith("python_type") and isinstance(value, type): | |
| if key.endswith("pc_type") and isinstance(value, type): |
Collaborator
Author
There was a problem hiding this comment.
Good idea. We have to be careful to not accidentally break anything and we also want to work with snes_type=python too. I will have a think.
| if not isinstance(value, _native_petsc_option_types): | ||
| # Convert Python PC objects into their string representation | ||
| if key.endswith("python_type") and isinstance(value, type): | ||
| parameters[key] = f"{value.__module__}.{value.__name__}" |
Member
There was a problem hiding this comment.
Does this work with multiply nested names? i.e. module.submodule.MyPC
Collaborator
Author
There was a problem hiding this comment.
I think so. For example:
(venv-firedrake-main-py313) [connor@levi petsctools]$ python
Python 3.13.11 (main, Jan 28 2026, 10:53:04) [GCC 15.2.1 20260103] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> scipy.minimize
...
AttributeError: Module 'scipy' has no attribute 'minimize'. Did you mean: 'optimize'?
>>> scipy.optimize.minimize
<function minimize at 0x7f5ce5afe020>
>>> scipy.optimize.minimize.__module__
'scipy.optimize._minimize'
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.
Makes it much more pleasant to construct preconditioners.
It really is that easy.
(Tests and Firedrake PR to follow)