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

ParameterHandler::parse_input_from_json(): do not use mangled parameter names anymore #16544

Merged
merged 1 commit into from Mar 16, 2024

Conversation

mschreter
Copy link
Contributor

@mschreter mschreter commented Jan 25, 2024

As described in #16453 parameter names in *.json needed to be mangled. In this PR, we suggest to not use mangled parameter names in a *.json-file anymore. We mangle them internally to use the existing XML reading functionality.
I also renamed the corresponding tests to keep the naming consistent, which was not the case before.

closes #16453

Copy link
Member

@marcfehling marcfehling left a comment

Choose a reason for hiding this comment

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

After #13815, this PR is the only logical step to have a consistent input and output for the JSON format. Thank you.

The function no longer works for mangled JSON files, correct? I can imagine that this would be a big incompatibility for some users (including aspect? @gassmoeller @tjhei, referring to #13815 (comment)).

Is there a way to check whether a tree is mangled? Is there a way to convert a json file from mangled to demangled (that you could mention in the changelog)? This could be helpful for the transition.

source/base/parameter_handler.cc Outdated Show resolved Hide resolved
source/base/parameter_handler.cc Outdated Show resolved Hide resolved
source/base/parameter_handler.cc Outdated Show resolved Hide resolved
recursively_mangle_or_demangle(p.second,
temp,
is_parameter_node(p.second) ||
is_alias_node(p.second));
tree_out.put_child(demangle(p.first), temp);
Copy link
Member

Choose a reason for hiding this comment

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

So demangle works bidirectional from mangled to demangled and vice versa? It isn't obvious to me how the mangle part in recursively_mangle_or_demangle works. Could you elaborate (maybe with in-source commentary)?

Copy link
Contributor Author

@mschreter mschreter Jan 31, 2024

Choose a reason for hiding this comment

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

There was something missing in the old state of the code. Now, it should work bidirectional since we perform either mangling/demangling depending on the flag do_mangle. I rephrased the documentation accordingly.

@bangerth
Copy link
Member

ASPECT doesn't use JSON. I think the compatibility issue is not huge. I'm ok with the incompatibility assuming it is properly documented in the changelog.

I had been under the impression that keys in JSON cannot have spaces in it, but looking at the changed output files, this seems to work just fine because both keys and values (if necessary) can be put in double quotes. So this is fine with me.

@bangerth
Copy link
Member

@mschreter Ping?

@mschreter
Copy link
Contributor Author

mschreter commented Jan 31, 2024

Thank you for your review @marcfehling.

The function no longer works for mangled JSON files, correct? I can imagine that this would be a big incompatibility for some users (including aspect? @gassmoeller @tjhei, referring to #13815 (comment)).

Correct, after this change json files are always assumed to be demangled. If this is a big incompatibility, we probably need to extend this PR.

Is there a way to check whether a tree is mangled? Is there a way to convert a json file from mangled to demangled (that you could mention in the changelog)? This could be helpful for the transition.

There is certainly a way to determine the state of the json file, but I am not sure if this is really what we want and I don't feel qualified enough to make this decision :-). However, if I interpret @bangerth's comment correctly, he would be fine with the incompatibility break in terms of requiring demangled json files in the future. Or do you @marcfehling/@bangerth have any specific use cases in mind where this PR could have a huge impact?

@tjhei
Copy link
Member

tjhei commented Jan 31, 2024

@bangerth we use the JSON parameter output in ASPECT to generate the markdown documentation and this depends on mangling: https://github.com/geodynamics/aspect/blob/main/contrib/utilities/jsontomarkdown.py

This PR would break this. It wouldn't be hard to fix, but it is a bit annoying because we need to know what deal.II version was used.

@tjhei
Copy link
Member

tjhei commented Jan 31, 2024

That said, I am ok with changing it. It makes sense.

Is there a way to see which deal.II version wrote the file? If not, can we add this inside the output?

@bangerth
Copy link
Member

bangerth commented Feb 1, 2024

JSON does not allow for comments (one of the more startling decisions in the software world), so we cannot write the version number into a comment as we do in other file formats. We could put it into a "magic" variable, but that has the disadvantage that it is not backward compatible because previous version's readers do not know about the magicness of the variable.

@tjhei
Copy link
Member

tjhei commented Feb 1, 2024

JSON does not allow for comments (one of the more startling decisions in the software world),

True. It would also have the disadvantage that parsing the comment would be more difficult.

We could put it into a "magic" variable, but that has the disadvantage that it is not backward compatible

Sadly we did not put all the output inside a "parameters" (or similar) block. Then we could include a version string. While breaking everybody, this would allow adding additional information...

@peterrum
Copy link
Member

peterrum commented Feb 6, 2024

/rebuild

@mschreter
Copy link
Contributor Author

mschreter commented Feb 6, 2024

How shall we proceed @bangerth @tjhei?

Another point which I would like to mention: The current implementation prints parameters in the *.json format in a demangled state. So we cannot read them anymore as long as we require mangled *.json files for parsing. I am afraid we have to fix this incompatibility one way or the other.

@marcfehling marcfehling added this to the Release 9.6 milestone Feb 9, 2024
@mschreter
Copy link
Contributor Author

ping :)

@tjhei
Copy link
Member

tjhei commented Mar 5, 2024

I am okay updating to using demangled read/write.

How do you feel about moving all entries into a single "parameters" root? That would allow us to add other information in the future (version info, etc.). You can even detect the two kinds of formats when loading (if there is a "parameters" root, you know you have the new version).

@peterrum
Copy link
Member

peterrum commented Mar 7, 2024

How do you feel about moving all entries into a single "parameters" root? That would allow us to add other information in the future (version info, etc.). You can even detect the two kinds of formats when loading (if there is a "parameters" root, you know you have the new version).

@tjhei I am afraid that moving everything into a new section/node will break all json parameter files used by the users. This patch only fixes an inconsistency between reading/writing json files. At the moment we can write json files (by deal.II) in such a way that we cannot read it anymore.

@peterrum
Copy link
Member

@mschreter Could you rebase the PR? I think after that we can merge 👍

Co-authored-by: Magdalena Schreter-Fleischhacker <schreter.magdalena@gmail.com>
@mschreter mschreter force-pushed the parse_input_from_json_mangle branch from 717976f to b8ef99c Compare March 13, 2024 18:57
@peterrum
Copy link
Member

If there are no objections, I will merge this PR tomorrow.

@peterrum peterrum merged commit 5117a55 into dealii:master Mar 16, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParameterHandler: *.json files with keys containing underscores cannot be parsed
5 participants