Iris meshes are not pickle safe
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
Research direction
Start with iris/mesh/components.py, especially the mesh connectivity manager shown in the traceback, and reproduce the failure using test_data/NetCDF/ugrid/21_triangle_example.nc. Ensure a pickled and reloaded cube retains usable mesh connectivities, then rerun the demonstrated connectivity check to confirm it succeeds.
Written by the indexing model from the issue text.
Description
🐛 Bug Report
Highlighting this behaviour with the iris UGRID 21_triangle_example.nc test data, which loads 5 cubes with meshes, but let's just focus on one of them:
>>> import iris
>>>
>>> fname = "test_data/NetCDF/ugrid/21_triangle_example.nc"
>>> cube = iris.load_cube(fname, "volume flux between cells")
>>> print(cube)
Yields:
volume flux between cells / (m^3/s) (-- : 41)
Mesh coordinates:
latitude x
longitude x
Mesh:
name Topology data of 2D unstructured mesh
location edge
Attributes:
Conventions 'UGRID-0.9'
Let's see the available connectivities attached to the mesh:
>>> from pprint import pprint
>>>
>>> pprint(cube.mesh.connectivities)
[<Connectivity: Maps every triangular face to its three corner nodes. / (unknown) [...] shape(21, 3)>,
<Connectivity: Maps every edge to the two nodes that it connects. / (unknown) [...] shape(41, 2)>,
<Connectivity: Maps every boundary segment to the two nodes that it connects. / (unknown) [...] shape(19, 2)>]
Now let's serialize the cube (along with its mesh et al) using pickle:
>>> import pickle
>>>
>>> with open("flux.pkl", "wb") as fh:
... pickle.dump(cube, fh)
...
Now load the pickle back and recheck the connectivities again:
>>> with open("flux.pkl", "rb") as fh:
... flux = pickle.load(fh)
...
>>> print(flux)
volume flux between cells / (m^3/s) (-- : 41)
Mesh coordinates:
latitude x
longitude x
Mesh:
name Topology data of 2D unstructured mesh
location edge
Attributes:
Conventions 'UGRID-0.9'
Seems fine so far ...
>>> pprint(flux.mesh.connectivities())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/apps/sss/environments/default-2025_11_26/lib/python3.12/site-packages/iris/mesh/components.py", line 1433, in connectivities
result = self._connectivity_manager.filters(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/apps/sss/environments/default-2025_11_26/lib/python3.12/site-packages/iris/mesh/components.py", line 2617, in filters
supports_faces = any(["face" in role for role in self.ALL])
^^^^^^^^
AttributeError: '_Mesh2DConnectivityManager' object has no attribute 'ALL'
💣 Oppsie!
We need to add additional __setstate__ and __getstate__ methods to provide full pickling coverage for meshes.
Ping @jrackham-mo
- Dominant language
- Python
- Stars
- 724
- Forks
- 317
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SciTools/iris
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100