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

Refactor DiscretizationCollection constructor #122

Closed
wants to merge 15 commits into from

Conversation

thomasgibson
Copy link
Collaborator

@thomasgibson thomasgibson commented Jun 7, 2021

This PR removes all the work that the current constructor for DiscretizationCollection is doing for setup. The proposed interface for creating these discretization collections is provided by the function make_discretization_collection.

@thomasgibson thomasgibson marked this pull request as draft June 7, 2021 01:03
@thomasgibson thomasgibson linked an issue Jun 7, 2021 that may be closed by this pull request
grudge/discretization.py Outdated Show resolved Hide resolved
Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

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

Thanks for starting to think about this. Some thoughts from a quick scroll.

grudge/discretization.py Outdated Show resolved Hide resolved
grudge/discretization.py Outdated Show resolved Hide resolved
@thomasgibson thomasgibson added the design decisions Anything related to overhauling or redesigning code label Jun 7, 2021
@thomasgibson thomasgibson marked this pull request as ready for review June 17, 2021 17:59
@inducer
Copy link
Owner

inducer commented Jul 16, 2021

Is this ready for review from your end? (I ask because of the ambiguous state: no review requested, work still ongoing, but also not marked as draft)

Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

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

Thanks! A few comments below.

grudge/discretization.py Outdated Show resolved Hide resolved
from a :class:`grudge.dof_desc.DOFDesc`
to a :class:`meshmode.discretization.Discretization`.
At minimum, this should include a base discretization given by
the dof descriptor :class:`grudge.dof_desc.DD_VOLUME`.
Copy link
Owner

Choose a reason for hiding this comment

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

I think the documentation of what this is needs to be expanded a bit, to avoid some misunderstandings that I had when first reading this, mainly on how this relates to the discr_from_dd method. (Maybe a different name would also help... vol_discr_from_dd?)

  • The discr_from_dd method can be used to retrieve all sorts of stuff (boundary discretizations and whatnot). This discr_from_dd dictionary cannot be used to supply "pre-made" versions of those. (It might be attractive to allow that? not sure) Said another way, this should set an expectation for what can and cannot be part of this mapping.
  • This is treated as read-only, i.e. additional discretizations made by discr_from_dd aren't added to this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided to do away with the redundant discretizations altogether and streamline them through to discr_from_dd where possible: ae3a105.

I personally like this a lot more

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven’t been following this PR closely, so I’m way out of the loop on what exactly is being changed… But I just wanted to ask: what will happen here when we add multiple volume discretizations? Is the _base_discr change going to be compatible with that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The _base_discr is specifying the "base"/interpolatory element group on the mesh. So one question I have: If you have multiple volume discretizations, will they have different meshes? If so, then _base_discr should probably be a set of "base"/interpolator discretization objects defined on their appropriate volume meshes.

Copy link
Collaborator Author

@thomasgibson thomasgibson Sep 22, 2021

Choose a reason for hiding this comment

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

@majosm When you are at a point where you are trying to couple different discretizations (I think that's going to be MIRGECom + MIRGEHeat right?), I would appreciate being involved at some point in the discussion so I can see what's needed in grudge.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The _base_discr is specifying the "base"/interpolatory element group on the mesh. So one question I have: If you have multiple volume discretizations, will they have different meshes? If so, then _base_discr should probably be a set of "base"/interpolator discretization objects defined on their appropriate volume meshes.

I think there will need to be a global mesh (so we have connectivity between the different volumes), but it will get split into sub-meshes for each volume in order to construct the discretizations for each.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah okay! This makes sense. Then it sounds like what we want to make sure is that we pass in some mapping to make_discretization_collection (I proposed doing this as some kwarg for metadata) that associates sub-meshes with "base" (often referred to as the volume discretization) discretizations. I would be curious to know your opinion on the matter discussed here: #122 (comment)

grudge/discretization.py Outdated Show resolved Hide resolved
discr_tag_to_group_factory,
discr_from_dd,
dist_boundary_connections,
mpi_communicator=None):
"""
Copy link
Owner

Choose a reason for hiding this comment

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

This version is definitely no longer compatible with code that calls the DiscretizationCollection constructor directly. That's OK for grudge because you've fixed all the call sites, and it's OK for mirgecom because it only uses EagerDiscretization to which you've added the backward compatibility code. But I'm not sure it's OK for all other users? (cc @alexfikl)

Alternatively, the compat code could live here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have some grudge code sitting around, but it needs a lot of changes to move away from the deprecated symbolic stuff, so I'm fine with making a more breaking change here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Afraid I don't really know a way around this without resorting to some hacky python. I'd prefer not to make this overly complicated if possible. How about once this PR is merged, we pin an issue describing how the interface has changed?

Comment on lines +580 to +581
:arg discr_context: A :class:`~meshmode.mesh.Mesh` object to define
the discretization collection over.
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure I love the name. In pytential, @alexfikl used "places": https://documen.tician.de/pytential/symbolic.html in a similar role.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In particular, the GeometryCollection class in there. (The name was used in the code before introducing the GeometryCollection, so I just named it like that to stay consistent)

Copy link
Collaborator Author

@thomasgibson thomasgibson Sep 22, 2021

Choose a reason for hiding this comment

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

To be honest, I'm starting to like this placeholder business less and less the more I think about it. make_discretization_collection is intended to be the primary user-facing way to create the DiscretizationCollection And I can already imagine having an ambiguous placeholder argument causing confusion later on down the line.

I am not a fan, and I think we should avoid them if we can. I would rather just rename discr_context back to mesh, document it as such, and add an optional kwarg for discretization-related metadata that can be leveraged in the future. Thoughts @inducer @alexfikl ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@majosm This is probably a relevant discussion.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm starting to like this placeholder business less and less the more I think about it.

Not sure I understand what you're objecting to. Having symbolic names for parts of the domain? Something else? Sorry if I'm being dense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry if I wasn't very clear. I was referring to using placeholder arguments in make_discretization_collection like places or discr_context (determined by position alone) which can be pretty much anything (mesh, discretizations, dicts of discretizations). I don't feel comfortable doing that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would rather try to use something along the lines of **kwargs, which is a bit more controlled from my perspective.

Copy link
Owner

Choose a reason for hiding this comment

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

Personally, I feel like I've had OK experiences with those types of arguments, if used judiciously. Examples:

  • loopy functions will often take objects or string representations that parse to them. (e.g. domains, statements)
  • pyopencl.Array's constructor can take a context or an array as first argument.

The type of an object can be unambiguously determined, so I don't see a big risk in taking e.g. mesh as a shorthand for {DEFAULT_VOLUME: mesh}.

On the other hand, I find **kwargs parsing kind of unattractive:

  • Forget to check for extra arguments
  • Assuming you mean we would use mesh= or geometries= as alternatives to each other, we'd need to add logic to reject calls that have both.
  • **kwargs have to be the last argument. If that makes the interface kwargs-only, then all calls become kind of wordy, which isn't amazing for high-profile API real estate like the effective discretization collection constructor.

the discretization collection over.
:arg discr_tag_to_group_factory: A mapping from discretization tags
(typically one of: :class:`grudge.dof_desc.DISCR_TAG_BASE`,
:class:`grudge.dof_desc.DISCR_TAG_MODAL`, or
Copy link
Owner

Choose a reason for hiding this comment

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

Is overriding the meaning of "modal" allowed?

Copy link
Collaborator Author

@thomasgibson thomasgibson Sep 22, 2021

Choose a reason for hiding this comment

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

I think this is addressed in 23dfa75. A default modal factory is provided whenever it is not explicitly provided by the user (in a similar way to how there is a default simplex group factor)

Comment on lines 625 to 629
# Modal discr should always comes from the base discretization
discr_tag_to_group_factory[DISCR_TAG_MODAL] = \
_generate_modal_group_factory(
discr_tag_to_group_factory[DISCR_TAG_BASE]
)
Copy link
Owner

Choose a reason for hiding this comment

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

This should error if DISCR_TAG_MODAL was supplied, instead of silently overwriting. The docs specifically allow supplying modal.

Copy link
Collaborator Author

@thomasgibson thomasgibson Sep 22, 2021

Choose a reason for hiding this comment

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

I've updated this in 23dfa75; I've opted to only provide the group factor when it's not provided by the user

grudge/discretization.py Outdated Show resolved Hide resolved
grudge/discretization.py Outdated Show resolved Hide resolved
@inducer
Copy link
Owner

inducer commented Jul 16, 2021

Unsubscribing... @-mention or request review once it's ready for a look or needs attention.

@inducer
Copy link
Owner

inducer commented Mar 17, 2022

Superseded by #236.

@inducer inducer closed this Mar 17, 2022
@inducer inducer deleted the dcoll-refactor branch March 17, 2022 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design decisions Anything related to overhauling or redesigning code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DiscretizationCollection constructor should do no work
4 participants