Converting 3D mesh to xdmf/h5

So far I’ve been using .xml files to read in meshes. Workflow was as follows:
convert .geo to .msh using
gmsh -3 spheres.geo -format msh2,
running
dolfin-convert spheres.msh spheres.xml,
read in via
mesh = Mesh('spheres.xml').

Now I’d like to use a much larger mesh, which, when run using
mpirun -n 12 python test.py
gives me a warning
Process 0: *** Warning: XML file 'te.xml' is very large. XML files are parsed in serial, which is not scalable. Use XMDF/HDF5 for scalable IO in parallel
and takes forever.

Looking around here, and from the error message, I see that I somehow need to create an XMDF/HDF5 file. Specifically, I’ve looked at this post. However, if I follow dokken’s answer, I get an error in

meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))

list indices must be integers or slices, not str

Using msh.cells[2][1] instead of “tetra” works, but I get a similar error in the next line, which I can’t resolve:

TypeError: The first input argument needs to be a sequence

Bonus question: are there any docs/examples for this type of problem? Surely this is very common?

In the post you are referring to, there are many examples on how to load meshes with xdmf.
For anyone to be of further help, you need to supply the meshio version you are using, as the user interface has changed lately (Latest version syntax can be found in this post in the same thread as above: Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio)

Alright, thanks for pointing this out. If I amend the snippet you linked to like so:

    elif cell.type == 'tetra':
        tetra_cells = cell.data

and

    elif key == "tetra":
        tetra_data = msh.cell_data_dict["gmsh:physical"][key]

How do I do the writing to file, i.e. how do I amend

meshio.write("mesh.xdmf", triangle_mesh)
meshio.xdmf.write("mf.xdmf", line_mesh)

?

If you have added the data to the meshio.Mesh you have created (lets call it tetra_mesh), you simple write it to file by meshio.write("mesh.xdmf", tetra_mesh).