-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add a customized config parser #344
Conversation
Example result:Here is part of the config file for # Options related to the current test case
[test_case]
# source: /home/xylar/code/compass/customize_config_parser/compass/setup.py
steps_to_run = initial_state forward
# Options related to downloading files
[download]
# the base url for the server from which meshes, initial conditions, and other
# data sets can be downloaded
# source: /home/xylar/code/compass/customize_config_parser/compass/default.cfg
server_base_url = https://web.lcrc.anl.gov/public/e3sm/mpas_standalonedata
# whether to download files during setup that have not been cached locally
# source: /home/xylar/code/compass/compass/inej.cfg
download = True
# whether to check the size of files that have been downloaded to make sure
# they are the right size
# source: /home/xylar/code/compass/compass/inej.cfg
check_size = False
# whether to verify SSL certificates for HTTPS requests
# source: /home/xylar/code/compass/customize_config_parser/compass/default.cfg
verify = True
# the path on the server for MPAS-Ocean
# source: /home/xylar/code/compass/customize_config_parser/compass/ocean/ocean.cfg
core_path = mpas-ocean
# The parallel section describes options related to running tests in parallel
[parallel]
# the program to use for graph partitioning
# source: /home/xylar/code/compass/customize_config_parser/compass/default.cfg
partition_executable = gpmetis
# parallel system of execution: slurm or single_node
# source: /home/xylar/code/compass/compass/inej.cfg
system = single_node
# whether to use mpirun or srun to run the model
# source: /home/xylar/code/compass/compass/inej.cfg
parallel_executable = mpirun
# cores per node on the machine
# source: /home/xylar/code/compass/compass/inej.cfg
cores_per_node = 8
# the number of multiprocessing or dask threads to use
# source: /home/xylar/code/compass/compass/inej.cfg
threads = 8
... |
9799d70
to
e77a1d5
Compare
@matthewhoffman, this is now ready to review if you would have time. I tested the functionality I needed for QU meshes in #246 and it worked great! The user config options take precedence over those defined anywhere else so that you can compute other config options based on existing ones anytime you like without having to worry that you might either not yet know or accidentally overwrite what the user has requested. |
compass/config.py
Outdated
self._combine() | ||
return self._combined.has_option(section, option) | ||
|
||
def set(self, section, option, value=None, comment=''): |
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.
@matthewhoffman, I haven't yet used the comment
argument anywhere in the code. I'd like to add a few examples both to make sure it works as expected and because I think config options that are created in the code (as opposed to just having their previous values changed) should ideally have a comment in the resulting file.
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.
Okay, I've now done this (and fixed a bug related to it).
TestingI set up a few test cases on my Linux laptop to test the user config file and could verify that I saw the user config options in the resulting config files. I also tested various QU resolutions in #246 with this funcationality. I set up and ran the I looked a sampling of config file from test cases in the |
2751905
to
391afc1
Compare
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.
Xylar, I looked this over and tested it out, and it looks very useful! I had actually never used a user config file, so this was a good excuse to learn how that works, and that was useful for me to understand. I made a few small comments, nothing major. I marked 'request changes' only because I'd like to see the commenting feature documented in the docs. I don't necessarily need to re-review this though if you're happy with changes you add for that.
import os | ||
import pickle | ||
import warnings | ||
|
||
from mache import MachineInfo, discover_machine |
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.
Is this change (and related deletions below at ~70 and beyond) just incidental cleanup unrelated to this PR?
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.
No, this is not just clean-up, though I can understand how it might look that way. Before, we were merging a ConfigParser
object from mache
with one from compass
. This previous approach has the advantage that it includes some config options set at runtime in mache
such as the username. But it doesn't work with the new approach and it isn't important for compass
. So I switched to parsing the config files out of mache
instead of using the ConfigParser
object, which means that the MachineInfo
object is no longer needed.
@@ -195,10 +188,6 @@ def setup_case(path, test_case, config_file, machine, machine_info, work_dir, | |||
The name of one of the machines with defined config options, which can | |||
be listed with ``compass list --machines`` | |||
|
|||
machine_info : mache.MachineInfo |
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.
Related to previous comment, why are you able to drop this argument now?
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.
See previous comment.
@@ -251,20 +243,10 @@ def setup_case(path, test_case, config_file, machine, machine_info, work_dir, | |||
test_case.work_dir = test_case_dir | |||
test_case.base_work_dir = work_dir | |||
|
|||
# add the custom config file once before calling configure() in case we |
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.
Out of curiosity, how are you able to drop these config reads?
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.
The design of the new meta-config-parser is that it always prioritizes user config options by parsing them last in the _combine()
method. This is much more robust and (I think) more intuitive than the approach used previously (where we added the user config file twice).
... | ||
|
||
But it does not allow assignment of a section or many of the other | ||
dictionary-like features supported by :py:class:`configparser.ConfigParser`. |
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 is because the CompassConfigParser primarily needs to read configs and not write them, correct? I.e. you only wrapped the configParser functionality we actually need.
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.
Yes, that's exactly right. I only implemented the __getitem__
method and not the other dictionary methods. They would potentially be complicated to implement because of the comment and provenance handling, and I don't foresee a need.
391afc1
to
a083f09
Compare
@matthewhoffman, thank you for an excellent review. I have addressed all of your comments and I think the documentation is much improved. I also added a new |
I reran the |
a083f09
to
b9b6b60
Compare
This is a "meta" config parser that keeps a dictionary of config parsers and their sources to combine when needed. The custom config parser allows provenance of the source of different config options and allows the "user" config options to always take precedence over other config options (even if they are added later).
This is needed to set user config options that come from the command-line and not from config files (e.g. the MPAS path)
b9b6b60
to
a72aed6
Compare
This config parser can:
closes #247