Skip to content

Update to_xml() methods#3

Open
orlandoisepic wants to merge 24 commits intomainfrom
to_xml_methods
Open

Update to_xml() methods#3
orlandoisepic wants to merge 24 commits intomainfrom
to_xml_methods

Conversation

@orlandoisepic
Copy link
Copy Markdown
Contributor

They now have a clearer indent (tabs vs spaces) and the elements follow the order described in precice/config-format#2

Instead of spaces
This was the previously used name.
In this case the / needs to be at the beginning
Copy link
Copy Markdown
Member

@fsimonis fsimonis left a comment

Choose a reason for hiding this comment

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

We consistently use spaces in preCICE, using tabs here will break this convention.

I propose two ways regarding the formatting:

  • Generate output that leads to no changes when applying precice-config-format to it.
  • Generate unformatted output, then load precice-config-format as a library and use it to format the output.

I would personally tend towards the latter option, as it doesn't require any future changes.

@orlandoisepic
Copy link
Copy Markdown
Contributor Author

orlandoisepic commented Apr 9, 2026

Thank you for the feedback.

Generate unformatted output, then load precice-config-format as a library and use it to format the output

Currently, this is not possible as the to_xml() methods (producing a string) are only defined on the nodes themselves. The graph does not create an XML file.
This means that the user calls these 5 methods and receives the XML string, which can then be used to create the XML file, or whatever.

However, it would be possible to simply create a "global" to_xml() method, that receives a graph-object and then creates a formatted XML file.

If this is not desired, then I see only the option to modify the to_xml() methods of the nodes themselves.

and other indent issues
Default values
I moved the functions in their own directories based on their purpose.
Used default helper values
to use the new graph pacakge
Comment thread precice_config_graph/graph/operations.py Outdated
@fsimonis
Copy link
Copy Markdown
Member

Currently, this is not possible as the to_xml() methods (producing a string) are only defined on the nodes themselves. The graph does not create an XML file.

At some point you call, to_xml() and generate the string that needs to be written to file. This is the place where you can format the output.

Added missing attribute and made api_access optional.
fix wrong names
That are expected / optional in our nodes.
Still doesnt cover all possible arguments (tags), but at least the most important ones
the test tests that the created config is equivalent to the orginal one and that formatting works as expected.
they now check all available tags
create method for generating only the string.
Optional dependency when creating file.
Now the graph package will be found
and now the optional generate dependency will be installed for testing
Fix imports with new structure
@orlandoisepic
Copy link
Copy Markdown
Contributor Author

To summarize what this does now (because it is a bit more than anticipated):

  • Parse all attributes that the graph nodes have from a config file
  • There are global create_config_file(graph) and create_config_str(graph) now that format the config string with precice-config-format
  • There are corresponding tests
  • Old tests were updated to match the new functionality
  • Default values / constants are now stored centrally in helper.py
  • Graph manipulation is split into builder (creates the graph), operations (equivalence tests and config creation) and visualizer (plots the graph, used only in the CLI)

@orlandoisepic orlandoisepic requested a review from fsimonis April 10, 2026 15:16
Copy link
Copy Markdown
Member

@fsimonis fsimonis left a comment

Choose a reason for hiding this comment

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

A general improvement would be to switch to single ticks for strings including escaped quotes:

"attrib=\"val\""'attrib="val"'

try:
from preciceconfigformat.cli import parseXML, PrettyPrinter
except ImportError:
raise ImportError("The precice-config-format library is not installed. "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can add this as a dependency to the package. This way you can assume that the formatter is importable.

import networkx as nx
try:
import matplotlib.pyplot as plt
except ImportError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar story here. You can just add this as a dependency.

Comment on lines +115 to +116
THIN_PLATE_SPLINE = "thin-plate-splines"
VOLUME_SPLINE = "volume-splines"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The enums are now inconsistent though 😉

return _format_config_string(config_str)


def _create_unformatted_config_str(config_dict: dict[str, list[n.ParticipantNode |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The generated string is still formatted.
I suggest removing all kinds of indentation.
Theoretically, you could even remove the newlines, but this can make debugging a challenge.

The key is simple code.

Comment on lines +147 to +149
f"{h.INDENT}{h.INDENT}{h.INDENT}filter=\"%Severity% > debug\"\n"
f"{h.INDENT}{h.INDENT}{h.INDENT}format=\"---[precice] %ColorizedSeverity% %Message%\"\n"
f"{h.INDENT}{h.INDENT}{h.INDENT}enabled=\"true\" />\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
f"{h.INDENT}{h.INDENT}{h.INDENT}filter=\"%Severity% > debug\"\n"
f"{h.INDENT}{h.INDENT}{h.INDENT}format=\"---[precice] %ColorizedSeverity% %Message%\"\n"
f"{h.INDENT}{h.INDENT}{h.INDENT}enabled=\"true\" />\n"
f"{h.INDENT}{h.INDENT}{h.INDENT}format=\"---[precice] %ColorizedSeverity% %Message%\" />\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants