openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Add model.description attribute and persist to model.xml output

Open ondrejch opened this issue 3 months ago • 0 comments

Description

Add a description attribute to the openmc.Model class, allowing users to store an arbitrary description string for the model. This description should be written as an XML element in the model.xml file when exported via export_to_model_xml. If possible, also add support for reading the description back into the model when loading from XML via from_model_xml.

This feature will make it easier to document models, track provenance, and automate workflows where model metadata is useful.

Proposed change:

  • Add a description property/attribute to the Model class, defaulting to an empty string.
  • Update export_to_model_xml to include a <description>...</description> element right after the <model> root tag.
  • Update from_model_xml to read the <description> element and populate the new model attribute.
  • Ensure round-trip compatibility: description set on model ➜ saved in XML ➜ loaded back into Python.
  • Optionally, document and test this feature.

Alternatives

  • Continue to use Python-only ad-hoc attributes (not saved in XML).
  • Use external metadata files (less convenient, not coupled to model).
  • Overload an existing field (not semantically correct).

Compatibility

  • This enhancement adds a new attribute and XML element. If implemented to be optional and default to empty, it should not break existing models or workflows.
  • Models created with a description will still be readable by older OpenMC versions, which should ignore the unknown <description> element in XML.

Relevant code locations

Test example

  • Add a test: set model.description = "Test description", export to XML, reload with from_model_xml, and assert the description value is preserved.

ondrejch avatar Oct 01 '25 17:10 ondrejch