Skip to content

Add matid capability to the sesame2spiner library - #659

Open
buechlerm wants to merge 3 commits into
mainfrom
buechler/writeMaterials
Open

buechlerm wants to merge 3 commits into
mainfrom
buechler/writeMaterials

Conversation

@buechlerm

@buechlerm buechlerm commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Add API for a vector of matid's in the sesame2spiner library.

PR Summary

Adds a saveAllMaterials interface to the sesame2spiner library so host codes can generate an sp5 file directly from a list of sesame matids — with or without per-material Params overrides — instead of having to write out input files first, plus an hid_t overload that lets callers build a file up one material at a time. All overloads, including the existing file-based one, now funnel into a single core implementation, so duplicate matid and name detection queries the HDF5 file itself (H5Lexists) rather than in-memory sets and stays correct across incremental calls. Also fixes three latent bugs surfaced by the refactor: a matid absent from the sesame file previously yielded all-zero metadata bounds that reached log() and produced NaN grids with no diagnostic (now reported and skipped, other materials still save), eosGetMetadata no longer ignores the caller's verbosity in favor of a hardcoded Verbosity::Debug, and appending to an existing file now validates its log_type root attribute against the current build.

  • Adds a test for any bugs fixed. Adds tests for new features.
  • Format your changes by using the make format command after configuring with cmake.
  • Document any new features, update documentation for changes made.
  • Make sure the copyright notice on any files you modified is up to date.
  • After creating a pull request, note it in the CHANGELOG.md file.
  • LANL employees: make sure tests pass both on the github CI and on the Darwin CI
  • If ML was used, make sure to add a disclaimer at the top of a file indicating ML was used to assist in generating the file.
  • If Agentic AI was used, have the AI generate a "proposed changes" markdown file and store it in the plan_histories folder, with a filename the same as the MR number.

If preparing for a new release, in addition please check the following:

  • Update the version in cmake.
  • Move the changes in the CHANGELOG.md file under a new header for the new release, and reset the categories.
  • Maintainers: ensure spackages are up to date:
    • LANL-internal team, update XCAP spackages
    • Current maintainer of upstream spackages, submit MR to spack
Comment on lines +263 to +268
if (H5Lexists(file, name.c_str(), H5P_DEFAULT) > 0) {
std::string new_name;
int suffix = 2;
do {
new_name = name + "_" + std::to_string(suffix++);
} while (H5Lexists(file, new_name.c_str(), H5P_DEFAULT) > 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i haven't wrapped my head around what this is for yet...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if multiple materials are named the same thing but have different matids, this lets you add duplicates of them. It has to walk through the file and increment the "index" of the material, so you might have steel, steel_2, steel_3, etc... I'm not sure how important this is, but now that the file is queried, keeping the old functionality requires this do while loop.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Although actually, would a cleaner implementation be while(H5Lexists) and drop the if () { do {} while()} construction?

Comment thread sesame2spiner/README.md

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this new section in the README should also be added to the singularity-eos sphinx-rst. These readmes should maybe be deprecated as I want people to not have to hunt through multiple places for documentation.

Comment thread CHANGELOG.md

### Added (new features/APIs/variables/...)
- [[PR658]](https://github.com/lanl/singularity-eos/pull/XXX) Add `MinimumInternalEnergy`/`MaximumInternalEnergy` to the EOS introspection API, so energy bounds are reachable through modifiers and the `singularity::EOS` variant
- Added `sesame2spiner::saveAllMaterials` overloads taking a list of matids instead of a list of input files, with optional per-material `Params` overrides, so host codes can generate an sp5 file without writing input decks to disk. Also added an overload taking an already-open `hid_t`, plus `writeSP5RootAttributes`, so a single sp5 file can be built up one material at a time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change should be pinned to an MR link.

Comment thread CHANGELOG.md
Comment on lines +17 to +18
- `sesame2spiner` now honors the requested verbosity when reading material metadata, rather than always using `Verbosity::Debug`. Default command line output is correspondingly quieter.
- `sesame2spiner::getMatBounds` no longer takes a leading index argument, which was unused.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These changes should be pinned to an MR link.

Comment on lines +263 to +268
if (H5Lexists(file, name.c_str(), H5P_DEFAULT) > 0) {
std::string new_name;
int suffix = 2;
do {
new_name = name + "_" + std::to_string(suffix++);
} while (H5Lexists(file, new_name.c_str(), H5P_DEFAULT) > 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if multiple materials are named the same thing but have different matids, this lets you add duplicates of them. It has to walk through the file and increment the "index" of the material, so you might have steel, steel_2, steel_3, etc... I'm not sure how important this is, but now that the file is queried, keeping the old functionality requires this do while loop.

Comment on lines +263 to +268
if (H5Lexists(file, name.c_str(), H5P_DEFAULT) > 0) {
std::string new_name;
int suffix = 2;
do {
new_name = name + "_" + std::to_string(suffix++);
} while (H5Lexists(file, new_name.c_str(), H5P_DEFAULT) > 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Although actually, would a cleaner implementation be while(H5Lexists) and drop the if () { do {} while()} construction?

Comment on lines +288 to +305
// Track status per material so that one failure does not get reported against
// every material that follows it.
const herr_t mat_status = saveMaterial(file, metadata, lRhoBounds, lTBounds, leBounds,
name, add_subtables, eospacWarn);
if (mat_status != H5_SUCCESS) {
std::cerr << "ERROR [" << matid << "]: problem with HDF5 while saving material."
<< std::endl;
num_failed += 1;
}
}

if (num_failed > 0) {
std::cerr << "WARNING: " << num_failed << " of " << matids.size()
<< " materials could not be saved." << std::endl;
}
// Count failures rather than summing herr_t values, which can cancel out and
// report success.
return (num_failed == 0) ? H5_SUCCESS : -1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

perhaps we should track which matids failed and summarize them at the end. I know it's in the error messages above, but I think that might still be nice to have a summary at the bottom.

This branch has not been deployed

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

Labels

None yet

3 participants