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

Error when loading mesh from statepoint #3249

Closed
shimwell opened this issue Jan 8, 2025 · 5 comments · Fixed by #3253
Closed

Error when loading mesh from statepoint #3249

shimwell opened this issue Jan 8, 2025 · 5 comments · Fixed by #3253
Assignees
Labels

Comments

@shimwell
Copy link
Member

shimwell commented Jan 8, 2025

Bug Description

I think the changes introduced by #3221 broke some of the mesh reading from a statepoint file. Not sure how it got through the CI but this is the error I'm seeing from this commit or newer in the develop branch

It looks like the unstructured mesh is somehow getting read in with routines designed for regularmesh. It is being assumed to be a regular mesh due to this line in mesh.py

mesh_type = 'regular' if 'type' not in group.attrs else group.attrs['type'].decode()

Screenshot From 2025-01-08 13-24-56

Steps to Reproduce

git checkout 775c41512283d178a49c787dc5fdfe617bac4938
pip install .
 import openmc
 sp=openmc.StatePoint('statepoint.4.h5')  # contains a unstructured mesh, file attached to issue
 sp.meshes
    um = sp.meshes[1] 
         ^^^^^^^^^
  File "/home/jon/openmc/openmc/statepoint.py", line 311, in meshes
    mesh = openmc.MeshBase.from_hdf5(group)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jon/openmc/openmc/mesh.py", line 107, in from_hdf5
    return RegularMesh.from_hdf5(group, mesh_id, mesh_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jon/openmc/openmc/mesh.py", line 819, in from_hdf5
    mesh.dimension = group['dimension'][()]
                     ~~~~~^^^^^^^^^^^^^
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/home/jon/miniforge3/envs/openmc-dev/lib/python3.12/site-packages/h5py/_hl/group.py", line 357, in __getitem__
    oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5o.pyx", line 257, in h5py.h5o.open
KeyError: "Unable to synchronously open object (object 'dimension' doesn't exist)"

Environment

openmc develop
ubuntu 24.04
python 3.12
statepoint.4.zip

@shimwell shimwell added the Bugs label Jan 8, 2025
@shimwell
Copy link
Member Author

shimwell commented Jan 8, 2025

a h5dump of the statepoint file shows that the type is "unstructured"

            DATASET "type" {
               DATATYPE  H5T_STRING {
                  STRSIZE 12;
                  STRPAD H5T_STR_NULLTERM;
                  CSET H5T_CSET_ASCII;
                  CTYPE H5T_C_S1;
               }
               DATASPACE  SCALAR
               DATA {
               (0): "unstructured"
               }
            }

So I think the fix is to change this line

mesh_type = 'regular' if 'type' not in group.attrs else group.attrs['type'].decode()

to

        if 'type' in group.keys():
            mesh_type = group['type'][()].decode()
        else:
            mesh_type = 'regular'

@shimwell shimwell self-assigned this Jan 8, 2025
@shimwell
Copy link
Member Author

shimwell commented Jan 8, 2025

Ah perhaps this is just due to me reading a statepoint file produced with the version of openmc before the #3221 and reading it with a newer version

@shimwell
Copy link
Member Author

shimwell commented Jan 8, 2025

Confirmed this is just that the statepoint mesh reading part of the python API is not compatible with statepoints written with earlier versions API.

@shimwell shimwell closed this as completed Jan 8, 2025
@pshriwise
Copy link
Contributor

Hrmmm yeah before that PR the type was written as a dataset not an attribute, that's going to cause a compatibility issue for sure. I think we should revert that and update the Mesh.from_hdf5 code accordingly. Thanks for catching this quickly @shimwell. I'll try to find a convenient place to add a test for this as well.

@pshriwise
Copy link
Contributor

OR we should increment the statepoint version, but I think in this case I'd rather revert the file structure change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants