Skip to content

Convert PC Python objects into strings - #46

Open
connorjward wants to merge 4 commits into
connorjward/appctx-autofrom
connorjward/pcpython-detect
Open

Convert PC Python objects into strings#46
connorjward wants to merge 4 commits into
connorjward/appctx-autofrom
connorjward/pcpython-detect

Conversation

@connorjward

Copy link
Copy Markdown
Collaborator

Makes it much more pleasant to construct preconditioners.

It really is that easy.

(Tests and Firedrake PR to follow)

Makes it much more pleasant to construct preconditioners.
Comment thread petsctools/options.py
Comment thread petsctools/options.py
@JHopeCollins

Copy link
Copy Markdown
Member

I am very happy with this functionality!

One small request. Can we have a test that non-PC objects also get converted?
Doesn't have to set up a solver or anything, just something like:

class MyPythonSNES:
	pass

def test_python_type_option():
	with petsctools.inserted_options(
		parameters={
			"snes_type": "python",
			"snes_python_type": MyPythonSNES,
		}
	):
		assert PETSc.Options()["snes_python_type"] == f"{__name__}.MyPythonSNES", "Python type name was not substituted into the options dictionary"

@JHopeCollins

Copy link
Copy Markdown
Member

One small request. Can we have a test that non-PC objects also get converted?
Doesn't have to set up a solver or anything, just something like:

As discussed, I added the test in 78ded27

@connorjward
connorjward marked this pull request as ready for review August 25, 2026 13:14
Comment thread petsctools/options.py
appmngr = AppContextManager()
for key, value in parameters.items():
if not isinstance(value, _native_petsc_option_types):
# Convert Python PC objects into their string representation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Convert Python PC objects into their string representation
# Convert Python objects into their string representation for things
# like 'pc_python_type' and 'snes_python_type'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants