-
Notifications
You must be signed in to change notification settings - Fork 35
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
Migrate Parameter Parsing: introducing ParameterAccessor
#341
Conversation
mentioning the old approach). I found this to be a difficult topic to talk about. But, this seems like a good start (and hopefully it is helpful).
b8c2159
to
c954db4
Compare
@jobordner - I know a while back that you mentioned you had concerns about safe-parsing in SMP-mode. I can/should explicitly check that. But, don't let this stop you from reviewing this PR. I'm very confident that there really shouldn't be any problems at all since I changed any of the underlying parsing code (or when the parsing is done) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me -- the ParameterAccessor seems good to me. Requested changes are just cosmetic. Thanks @mabruzzo!
Commenting briefly on the questions raised: (1) I think the ability to specify an absolute and relative parameter path seems useful (but if this introduces too much more complexity in the code base, it is less appealing). The parameter-path analogy is immediately clear (at least to me). (2) I very much like the idea of eventually introducing checking for parameter use -- as you note, typos in parameter files are an ongoing issue and helping to catch them would be useful. Again, the issue is how much machinery is required to implement. |
Co-authored-by: Greg Bryan <gbryan@astro.columbia.edu>
Here's a link to my possibly excessive PR Review Nothing really critical--I will accept the PR after you've made whichever of the changes you decide to make. Let me know if you have any questions, and hope you don't mind the unconventional review approach. As the first in a series of PR's, I wanted to err on the side of thoroughness. |
Thanks James! I'll make a point of addressing these suggestions (they're all really helpful!) |
The changes include: - renaming `ParameterAccessor` -> `ParameterGroup` - removing some unnecessary comments - renaming `ParameterGroup::get_root_parpath` -> `ParameterGroup::get_group_path` - deleting `ParameterGroup::wrapped_Parameters_ref`
…stently ParameterGroup instances by value when constructing Method objects.
…structor rather than a factory method.
…o a constructor rather than a factory method.
5b64814
to
7831d9f
Compare
Thanks for responding to these points. It's my plan to definitely to eventually implement parameter-checking (a lot of the necessary infrastructure is already in place from a long time ago). I think I will probably implement the absolute parameter-path stuff at some (assuming it doesn't involve introducing too much machinery). But I probably want to wait on that until after we can remove some functionality from the |
I've finished revising the code. @gregbryan and @jobordner, I'm ready for you to take one more look (I think this about ready to be merged at this point). I haven't changed anything too dramatic (it's mostly just systematic simple changes) @jobordner in particular, I just wanted to briefly go down your list of suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified version looks good to me -- left a few minor comments (but approved because this doesn't need me to look at it again). Thanks!
Co-authored-by: Greg Bryan <gbryan@astro.columbia.edu>
…odMHDVlct` from `EnzoConfig` into constructor (and helper functions).
This PR is the first in a series of that alters the way in which classes (like
Method
orPhysics
) are configured from values taken from the parameter file.Plan to roll out these changes
We need to introduce these changes in discrete steps because (i) it would take a lot of work to create (and review) a PR migrating everything at once, and (ii) additional work needs to be done every time a new parameter gets added via the old approach (to convert it so that it uses the new approach).
With that in mind, this PR takes a large first step to begin overhauling parameter parsing. It starts by shifting the vast majority of
Method
config-parsing fromCello
'sConfig
object into theMethod
subclasses (the remaining stuff needs to be addressed after we finish the conversion in the Enzo-layer). It also overhauls the process of configuring someMethod
objects from the Enzo-layerAdditional PRs will follow that deal with migrating other
Method
classes in the Enzo-layer. The changes in many of these cases are slightly more involved/less straightforward. In the future I also plan to extend this to other parts of the codebase (likeInitial
subclasses orPhysics
subclasses).Motivation
Since I'm not rolling out this transition all at once, I have added quite a bit of website documentation for this new approach. This documentation explains the differences in the approaches and motivates why we are making this change:
doc/source/devel/param.rst
Developer Guide
->Parameter Parsing and Configuration
With that said I will try to highlight some weaknesses (that emerged for historical reasons) of the old approach:
Method
subclass in the Cello layer (Enzo layer), one must store the parsed the value as an attribute of the globalConfig
(EnzoConfig
), forward it to the subclass, where the value is also stored as an attribute. This involves ~7 steps (see documentation).Config
(orEnzoConfig
) object and always access the value from there. This is equivalent to storing the parsed values as global variables (which is obviously undesirable for a number of reasons).Method
subclass could be made cleanerThe change made to the parameter-parsing by this PR is fairly simple:
This change reduces the number of steps needed to introduce a new parameter from 7 to 3, and strongly discourages the usage of global variables. This takes inspiration from Athena++
The
ParameterAccessor
classWhile one can imagine implementing our new approach by passing a reference to the
Parameters
class to the constructors of variousMethod
classes, we instead choose to pass the newly definedParameterAccessor
class.To understand ``ParameterAccessor``, I need to define a "parameter-path" (within the spoiler tag)
Parameters in Enzo-E parameter files for are organized into hierarchical groups. This mirrors in which files are organized within a directory hierarchy. The following block shows a snippet from a hypothetical parameter file that configures
EnzoMethodHeat
.To unambiguously refer to a parameter in the file, we would refer to the parameters in this snippet of
Method:list
andMethod:heat:alpha
. This shorthand is similar to file paths on a unix-like operating system (e.g./home/matthew/my_file.txt
). For that reason, I will use term "parameter-path" to refer to these "full names of these parameters".Essentially, the
ParameterAccessor
has an associated root-parameter path specified during its construction:Method
subclass.Parameters
class supports a similar feature, but it's less obvious when code is relying upon that feature (when you seeParameterAccessor
, you know that the feature is being used).Notes for the reviewers
ParameterAccessor.[ch]pp
just consist of moving parsing out ofConfig
andEnzoConfig
Addressing drawback of ``ParameterAccessor``
The primary drawback of
ParameterAccessor
is that we no longer specify the full parameter-paths of every parameter. While this is fundamentally necessary for gracefully handling the case where we want to configure multiple instances of a givenMethod
class, it's still less obvious for new users.My thought is: what it we extend the analogy between parameter-paths and file-paths?
- We could make a leading
":"
signify an absolute parameter-path (much in the same way that a leading"/"
signifies an absolute file path).- For example, passing
":Method:heat:alpha"
to an instance method ofParameterAccessor
would always refer to the same parameter regardless of the root-path currently associated with the instance ofParameterAccessor
- This could be used in cases where we don't expect more than 1 instance of the
Method
subclass to need to be configured in a given simulation (which is a lot of them).- We could also make a leading
".:"
signify that a parameter-path is explicitly a relative path (much in the same way that a leading"./"
explicitly signifies that a file-path is relative to the current directory).Do you have any thoughts about this?
Future Plans:
Cello
/Enzo-E
automatically set the courant factor of eachMethod
subclass. Instead, I want eachMethod
subclass to parse and set their own courant factor, especially since the default courant value may differ from case to case (for example, the VL+CT solver requires a value at or below 0.5 while lots of other methods require a value at or below 1.0).Method
objects, I want to start raising warnings (or optionally raising errors), when users specify parameters that aren't used for anything in a parameter file (usually this means there is some kind of typo - I've done this a lot).