-
Notifications
You must be signed in to change notification settings - Fork 64
Add capability to parse nested suites in capgen #691
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
base: develop
Are you sure you want to change the base?
Conversation
…pp_suite.py, scripts/parse_tools/xml_tools.py, and test/nested_suite_test/test_host.F90
… feature/nested_suites
mkavulich
left a 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.
I have a few questions
scripts/parse_tools/xml_tools.py
Outdated
| ... </suites> | ||
| ... ''' | ||
| >>> root = ET.fromstring(xml) | ||
| >>> expand_nested_suites(root, logger) |
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.
I'm curious if you've tested the behavior of infinite recursion, is that something we should have a test for to make sure it fails gracefully?
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, and I recall that we discussed this two weeks ago. If I remember correctly, we assumed that Python would throw an error about the recursion (but we didn't try). We could make a doctest for this, though.
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.
I wonder as part of this algorithm if it would make sense to keep a list of nested suites that have been processed that contain another nested suite. Couldn't you avoid infinite recursion by stopping if you're currently trying to processes a nested suite that already occurs in the list of already-processed nested suites that contain nested suites?
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.
Implemented in 0d144ae
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.
I'm not happy with the current solution, it gives no hints as to where the problem might lie.
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.
How about we use the current solution (since it is the safest and easiest one), but collect the names of the suites and just spit out that list when we throw the exception?
grantfirl
left a 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.
This is slick. I tried to review in order to understand how to use the new functionality and the implementation in the python scripts. I didn't really review the added test.
peverwhee
left a 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.
a couple of requests. I haven't done a full test review yet but will get to that in my second review!
… feature/nested_suites
… absolute or relative, always write expanded SDF
…ccpp-framework into feature/nested_suites
Why is this requirement needed or desired? |
|
Is it okay for a SDF to have more than one suite after expansion of the nested suites? |
Since you are still awake ;-) The removal of the expanded suite happens entirely in memory and ONLY within the expansion of the top-level suite you are processing. That means if you have two suites A and B that capgen is supposed to process, and both refer to the same nested suite, they will both see the original, unmodified suites as they are on the file system. The removal was at least for the reason of writing the fully expanded suite to disk and to the datatable (so that it is clear that this is the final suite that is getting processed). I don't recall immediately if there was another reason for it - it's been too long ago that I worked on the code. |
I do not have any issue with this feature, removing a suite which is nested inside another suite in the same file seems correct. However, that is not my question. As an example, say you have an SDF which has two suites with neither being nested. I think we end up with two suites. Is that correct? Does / should capgen handle that situation as if these suites were in two different SDFs? |
|
@gold2718 Ignore all of what I wrote at an apparently too early time today. PEBKAC. I do see this when I process multiple suites in one SDF that remain after expansion: But questions remain. Do we want this? Should there be only one remaining suite after expanding suites? The more I think about it, I get the impression that it would be easier to go back to just one suite per SDF. |
|
@gold2718 I implemented the capability to insert a specific group at the suite level, as per #691 (comment) and the discussion we had at the tag up on Monday. Commit: The output for the |
I would support this. We could drop the |
I agree - one suite per SDF sounds simplest. |
…ion of nested suites
|
@peverwhee @gold2718 I reverted back to only one suite per SDF. The code is so much cleaner! The only things that got a little messy are the doctests, because I need to read nested suites from files (I could have tried Python mock etc, but this seemed easy enough). I also implemented a - what I believe - robust way of catching recursions. |
|
@climbfuji So if I'm understanding right, the difference between this latest implementation and the original is that we allow nested suites, but only if they are defined in another file? |
Correct. That eliminates the need for |
mkavulich
left a 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.
Looks good to me (again)
peverwhee
left a 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.
thanks @climbfuji !
SIMA will eventually need an offline way to generate the expanded SDF because of the way the build system works, but I'll open an issue and make a PR for that in the future!
gold2718
left a 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.
I have not done a complete code review but I wrote some tests instead. I will submit my changes and new test files as a PR to this branch.
I think all the tests should pass, we should discuss any with which you disagree.
schema/suite_v2_0.xsd
Outdated
| </xs:choice> | ||
| </xs:sequence> | ||
| <xs:attribute name="name" type="xs:ID" use="required"/> | ||
| <xs:attribute name="lib" type="xs:string" use="optional"/> |
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.
What is this for?
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.
I don' think it's used anywhere. This came from the suite_v1.0 schema. I'll comb through the code and if we don't need it, I'll remove it. My guess is that it's from the old days of the "dynamic CCPP".
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.
Removed in 4ac80e4
|
Is there a purpose to this branch? |
No, I must have accidentally pushed to the wrong remote. I deleted it. |
@peverwhee. if my new tests get accepted, there are examples of generating the expanded suites. Something like: Can the CAM-SIMA build system just wrap this in a function if it needs an expanded suite file? All the routines are in xml_tools.py |
|
Interesting, after merging @gold2718's PR into my branch (all tests passed for that PR in my fork), I am now seeing this (https://github.com/NCAR/ccpp-framework/actions/runs/19524388803/job/55894181408): |
|
@climbfuji You could modify the |
db06414 to
e0d375b
Compare
Thanks. I was able to reproduce this locally, too. But I ended up backing out the PR from @gold2718 entirely, because I am running out of time before the Thanksgiving break and I really want to get this in. Because I force-pushed the older commit, @gold2718 can simply direct his branch/PR to NCAR develop after my PR went in and there won't be any merge conflicts etc. Besides, the changes in @gold2718 didn't really have anything to do with my changes, therefore it's better to keep them separate anyway. I will address the other questions/issue directly related to my PR before requesting a final review from @gold2718. |
…when maximum number of iterations is exceeded
Description
This PR adds the capability to parse nested suites in capgen, as discussed in #275. The implementation supports two types of nested suites using the XML element
nested_suite.Notes/Features
<suites>element.group=attribute; the content of that group in the referenced suite is merged into the existing group while preserving the order. This is the first example (aka the merge=true example) described in Add suite keyword to suite definition file? #275 (comment).group=attribute; the content of the entire referenced suite (i.e. all groups) is added in the correct location in the main suite. This is the second example (aka the merge=false example) described in Add suite keyword to suite definition file? #275 (comment).PrettyElementTreeclass was replaced by a much shorter functionwrite_xml_filethat uses features available in the already-used XML python library. And since it containeddomtwice in the name, I simply couldn't resist! The output of the new implementation is almost identical to the previousPrettyElementTreeoutput, see screenshot at the bottom of the PR description.nested_suite_test, thus the actual changes to the code are quite small and hopefully easy to review.User interface changes?: Yes (sort of), but these are optional. In order to use the new functionality, users have to update their suite definition file to the new XML schema version 2.0 (including all XML files that contain nested suites) and use the above syntax for
nested_suiteelements. There are no user interface changes for the previous XML schema 1.0, which remains valid, and there are no user interface changes for invoking capgen or in the auto-generated code.Issues
Fixes #275
Testing
Test removed: none
Test added:
- added
test/nested_suite_test- seeREADME.mdin that directory for more information- added doctests for the new functions in
xml_tools.pyUnit tests: all pass
System tests: all pass
Manual testing:
nested_suite_testAdditional information
Difference in
datatable.xmloutput of the newwrite_xml_filefunction (left) and the oldPrettyElementTreeclass (right):In a nutshell, the differences are no white spaces before the closing characters of XML elements, and the additional
<? xml ...?>line at the top. Both of these seem reasonable to me.