Skip to content

Add properties to settings w/ documentation, c++ loading of filename, and python round-trip test#3808

Open
gonuke wants to merge 32 commits intoopenmc-dev:developfrom
gonuke:properties_in_settings
Open

Add properties to settings w/ documentation, c++ loading of filename, and python round-trip test#3808
gonuke wants to merge 32 commits intoopenmc-dev:developfrom
gonuke:properties_in_settings

Conversation

@gonuke
Copy link
Contributor

@gonuke gonuke commented Feb 16, 2026

Description

This adds the path of the properties.h5 file as a new entry in the simulation settings. This file path can be used for loading properties from a file other than the default.

This will replace #3807 that has been withdrawn.

Fixes # (issue)

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Copy link
Contributor

@lewisgross1296 lewisgross1296 left a comment

Choose a reason for hiding this comment

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

I like the settings approach, probably best to have it in one place, as opposed to every cell that has properties.

Might be a future issue/PR, but we should discuss how to handle if there are cells with instances in the properties file that are not distribcell in our current model. (e.g. programmatically added tallies from Cardinal)

@gonuke
Copy link
Contributor Author

gonuke commented Feb 19, 2026

Hmmm... seems like my version of clang-format is too new and it is aligning comments differently that v15 (although the style guide does call for aligning comments)

@lewisgross1296
Copy link
Contributor

Recently, I've been installing clang-format-15 inside my docker image and formatting from the command line via clang-format-15 -i FILE

@lewisgross1296
Copy link
Contributor

Looked around / thinking about testing. It seems like this is the only OpenMC test that uses properties.h5.

Our tests could also take advantage of lib_init and export properties files with temperatures only/densities only/both. We could use the lattice_distribmat and lattice_distribrho tests as a base for the models that will have properties.

I can imagine the following tests being useful (and maybe more?)

  1. import a property file that has both temperature/density and ask for both. Some kind of check that the cells have the temps we expect.
  2. import a property file that only has temperature, ask for density, and test for the error
  3. import a property file that has only density, ask for temperature, and test for the error
  4. ask for temperature and density from a file that has neither, and test for both errors
  5. ask for properties when no properties file exists

@gonuke
Copy link
Contributor Author

gonuke commented Feb 20, 2026

Recently, I've been installing clang-format-15 inside my docker image and formatting from the command line via clang-format-15 -i FILE

That's what I get for trying to do this on my Mac :)

@gonuke
Copy link
Contributor Author

gonuke commented Feb 22, 2026

It looks like I need to figure out how to place a dummy properties.h5 file in the tmpdir to test this - or back off ever further on testing this, noting that the existence of other files is not tested in unit tests

@pshriwise
Copy link
Contributor

pshriwise commented Feb 22, 2026

It looks like I need to figure out how to place a dummy properties.h5 file in the tmpdir to test this - or back off ever further on testing this, noting that the existence of other files is not tested in unit tests

This context managet may be of help

def cdtemp(files=None):
"""Context manager to change to/return from a tmpdir.
Parameters
----------
files : Iterable of str or Path-like
Set of files to copy into the temporary directory
"""
with tempfile.TemporaryDirectory() as tmpdir:
cwd = os.getcwd()
if files:
for file in files:
copy(file, tmpdir, follow_symlinks=True)
try:
os.chdir(tmpdir)
yield
finally:
os.chdir(cwd)

@gonuke
Copy link
Contributor Author

gonuke commented Feb 22, 2026

It looks like I need to figure out how to place a dummy properties.h5 file in the tmpdir to test this - or back off ever further on testing this, noting that the existence of other files is not tested in unit tests

This context manager may be of help

Perhaps, but it's already using a temp directory fixture. I could use both but not sure how they interact. I could also just use os to touch a file in the current temp dir.

The fixture is a little mysterious because it refers to a tmpdir but I can't find anywhere that tmpdir is defined??

@pshriwise
Copy link
Contributor

Oh, I misunderstood. I thought you were trying to reference an already-present properties file. I don't quite understand why we need the file to exist though, it looks like that's only checked on the C++ side.

I think comparison of the str vs. Path types might be an issue. The value passed to the Settings.properties_file property is converted to a Path object in the call to input_path (if it isn't one already).

@gonuke
Copy link
Contributor Author

gonuke commented Feb 22, 2026

I think comparison of the str vs. Path types might be an issue. The value passed to the Settings.properties_file property is converted to a Path object in the call to input_path (if it isn't one already).

Yeah - that's probably the problem. I was getting wrapped around on the type of the filename and not sure what will resolve to true.

@gonuke gonuke marked this pull request as ready for review February 23, 2026 00:49
@gonuke gonuke requested a review from paulromano as a code owner February 23, 2026 00:49
@gonuke gonuke requested a review from pshriwise February 23, 2026 00:49
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Thanks @gonuke! I've included some minor comments here.

My comment on load order can be tackled in a separate PR.

src/summary.cpp Outdated
// Read material properties
for (const auto& mat : model::materials) {
mat->import_properties_hdf5(materials_group);
mat->import_properties_hdf5(
Copy link
Contributor

Choose a reason for hiding this comment

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

Commenting on what I think may be a pre-existing issue here and looking for guidance:

Above, we call Cell::set_density which populates the density multiplier vector based on the density of the material filling that cell. Here, we read the density of the material from the file, which may change the baseline density of the material from what it was at the time we called Cell::set_density and possibly invalidate the density multipliers of the cells? In a separate effort, should we perhaps change the order of these imports?

Looping @nuclearkevin in for a take as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A simple change to mitigate (but not entirely prevent) this is to have two read_density flags: read_cell_densities and read_material_densities, and document that one will override the other.

Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would be to either read all domain densities or none and fix the ordering (again, in a separate PR if need be). My understanding is that some cells may have density multipliers and others may not, so the additional option could leave us in a confusing state where some densities are original and some from the properties file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misunderstood your early comment. I thought you were worried about one of them overwriting the other, but I see that the concern is more subtle.

@lewisgross1296
Copy link
Contributor

lewisgross1296 commented Feb 24, 2026

I think it's working!
Screenshot 2026-02-24 at 12 37 32 PM
Screenshot 2026-02-24 at 12 57 16 PM

 Importing properties from
 /home/lgross/cnerg/gcmr/multiphysics_depletion/BOL_mp_depl/180/properties.h5...
[openmc.deplete] t=0.0 s, dt=86400 s, source=3333333.3333333335

@gonuke
Copy link
Contributor Author

gonuke commented Feb 24, 2026

I can't quite figure out why this test is failing? It seems like one of the python version tests was cancelled and that caused CI to be determined as failed. Can someone relaunch tests?

@gonuke gonuke force-pushed the properties_in_settings branch 2 times, most recently from aaee4fc to a0ace4e Compare March 5, 2026 12:06
@gonuke gonuke force-pushed the properties_in_settings branch from a0ace4e to cde42e1 Compare March 5, 2026 12:07
@gonuke gonuke requested a review from pshriwise March 5, 2026 12:08
def _create_properties_file_element(self, root):
if self.properties_file is not None:
element = ET.Element("properties")
element.text = str(self.properties_file)
Copy link
Contributor

@lewisgross1296 lewisgross1296 Mar 5, 2026

Choose a reason for hiding this comment

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

Something went wrong in the latest update @gonuke, I think it's here (i.e there's nothing called properties_file in the XML now.) I just re-tried and my settings looks like this

  <settings>
    <properties>/home/lgross/cnerg/gcmr/multiphysics_depletion/BOL_mp_depl/180/properties.h5</properties>
  </settings>

which leads to this behavior

                                %%%%%%%%%%%%%%%
                         %%%%%%%%%%%%%%%%%%%%%%%%
                      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                                  %%%%%%%%%%%%%%%%%%%%%%%%
                                   %%%%%%%%%%%%%%%%%%%%%%%%
               ###############      %%%%%%%%%%%%%%%%%%%%%%%%
              ##################     %%%%%%%%%%%%%%%%%%%%%%%
              ###################     %%%%%%%%%%%%%%%%%%%%%%%
              ####################     %%%%%%%%%%%%%%%%%%%%%%
              #####################     %%%%%%%%%%%%%%%%%%%%%
              ######################     %%%%%%%%%%%%%%%%%%%%
              #######################     %%%%%%%%%%%%%%%%%%
               #######################     %%%%%%%%%%%%%%%%%
               ######################     %%%%%%%%%%%%%%%%%
                ####################     %%%%%%%%%%%%%%%%%
                  #################     %%%%%%%%%%%%%%%%%
                   ###############     %%%%%%%%%%%%%%%%
                     ############     %%%%%%%%%%%%%%%
                        ########     %%%%%%%%%%%%%%
                                    %%%%%%%%%%%

               | The OpenMC Monte Carlo Code
     Copyright | 2011-2025 MIT, UChicago Argonne LLC, and contributors
       License | https://docs.openmc.org/en/latest/license.html
       Version | 0.15.3-dev282
   Commit Hash | 0e9eea39a8243b2223bb345d01fd091906a629f8
     Date/Time | 2026-03-05 10:59:29
 MPI Processes | 1
OpenMP Threads | 96

Reading model XML file 'model.xml' ...
ERROR: Node "filepath" is not a member of the "properties" XML node

I think you either want to use element.setAttribute to set filepath or have the code just look for the properties element

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kind of confused why the test didn't fail though

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually

  // read properties from file
  if (check_for_node(root, "properties")) {
    properties_file = get_node_value(root, "properties");
    if (!file_exists(properties_file)) {
      fatal_error(fmt::format("File '{}' does not exist.", properties_file));
    }
  }

The test looks for a node called properties, which is why it works. Perhaps now we just call it properties instead of properties_file now that we only supply a file

Copy link
Contributor

Choose a reason for hiding this comment

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

Is your executable up to date?

Copy link
Contributor

@lewisgross1296 lewisgross1296 Mar 5, 2026

Choose a reason for hiding this comment

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

nvm I forgot to do make install after make and before installing the python api

EDIT: It's running now... I'll report back when it completes and hopefully it will be statistically equivalent to cardinal / OpenMC depletion. Also it printed

 Importing properties from
 /home/lgross/cnerg/gcmr/multiphysics_depletion/BOL_mp_depl/180/properties.h5...

Copy link
Contributor

Choose a reason for hiding this comment

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

Any word here @lewisgross1296?

Copy link
Contributor

Choose a reason for hiding this comment

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

Still going :/ looks more promising so far. Probably will know by tomorrow

       59/1    1.03796    1.04088 +/- 0.00175

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.

4 participants