Skip to content

Conversation

JHopeCollins
Copy link
Member

Switch from an un-namespaced python dict to the namespaced petsctools.AppContext in this PR: firedrakeproject/petsctools#16

@JHopeCollins JHopeCollins self-assigned this Aug 28, 2025
Copy link
Contributor

@connorjward connorjward left a comment

Choose a reason for hiding this comment

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

Quick skim. I hope this is useful and not just annoying!

A, P = pc.getOperators()

if pc.type != "python":
raise ValueError("Expecting PC type python")
opc = pc
appctx = self.get_appctx(pc)
fcp = appctx.get("form_compiler_parameters")
fcp = get_appctx(pc).fcp
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you set fcp? It's not a clear name.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is already attached to the _SNESContext. I'm just switching to getting the compiler parameters from there instead of the appctx because it is a "global" rather than a namespaced (prefixed) thing.

ctx = get_appctx(pc)
fcp = ctx.fcp

appctx = ctx.appctx
Copy link
Contributor

Choose a reason for hiding this comment

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

This is weird. This is saying appctx = get_appctx(pc).appctx

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, this is really annoying. There is the _SNESContext object and the dict object, both of which are called appctx in various places.

  • _SNESContext.appctx is the dict we call the appctx in user-code.
  • dmhooks.get_appctx returns the _SNESContext.
  • PCSNESBase.get_appctx returns dmhooks.get_appctx(pc_or_snes).appctx which is the dict.

I would be in favour of cleaning up this naming, but it'd touch a lot of code and I don't want to do it unilaterally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. I'd be happy for now to just open an issue about it, plus perhaps an explanatory comment.

@@ -194,14 +193,13 @@ def __init__(self, problem, mat_type, pmat_type, appctx=None,
self._x = problem.u_restrict

if appctx is None:
appctx = {}
from petsctools import AppContext
Copy link
Contributor

Choose a reason for hiding this comment

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

Do import at the top level

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