Error converting mesh from GMSH to DOLFINx

I’m running one of the base tutorials by @dokken (deflection of a membrane). I’m using WSL (Ubuntu 22.04.2 LTS distro) with minconda and vscode as interface, here are the versions of the relevant packages:

fenics-basix              0.6.0           py310hdf3cbec_0    conda-forge
fenics-dolfinx            0.6.0           py310h25dff07_104    conda-forge
fenics-ffcx               0.6.0              pyh56297ac_0    conda-forge
fenics-libbasix           0.6.0                h1284905_0    conda-forge
fenics-libdolfinx         0.6.0              h67f7cd0_104    conda-forge
fenics-ufcx               0.6.0                h56297ac_0    conda-forge
fenics-ufl                2023.1.1           pyhd8ed1ab_1    conda-forge
gmsh                      4.11.1               h28bb747_2    conda-forge
mpi                       1.0                     openmpi    conda-forge
mpi4py                    3.1.4           py310h6075a6b_0    conda-forge
python                    3.10.11         he550d4f_0_cpython    conda-forge
python-gmsh               4.11.1               h57928b3_2    conda-forge

The minimal working example is:

import gmsh
from dolfinx.io import gmshio
from mpi4py import MPI

# meshing example taken from https://jsdokken.com/dolfinx-tutorial/chapter1/membrane_code.html
gmsh.initialize()
membrane = gmsh.model.occ.addDisk(0, 0, 0, 1, 1)
gmsh.model.occ.synchronize()
gdim = 2
gmsh.model.addPhysicalGroup(gdim, [membrane], 1)
gmsh.model.mesh.generate(gdim)

gmsh_model_rank = 0
mesh_comm = MPI.COMM_WORLD
domain, cell_markers, facet_markers = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank, gdim=2)
gmsh.finalize()

I get the following error:

Traceback (most recent call last):
  File "/home/giulio/paraffinator/meshingTest.py", line 15, in <module>
    domain, cell_markers, facet_markers = gmshio.model_to_mesh(model=gmsh.model, comm=mesh_comm, rank=gmsh_model_rank, gdim=2)
  File "/home/giulio/miniconda3/envs/new-env/lib/python3.10/site-packages/dolfinx/io/gmshio.py", line 250, in model_to_mesh
    mesh = create_mesh(comm, cells, x[:, :gdim], ufl_domain, partitioner)
  File "/home/giulio/miniconda3/envs/new-env/lib/python3.10/site-packages/dolfinx/mesh.py", line 177, in create_mesh
    cmap = _cpp.fem.CoordinateElement(_uflcell_to_dolfinxcell[cell_shape], cell_degree, variant)
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int)
    2. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int, variant: basix::element::lagrange_variant)

Invoked with: <CellType.triangle: 3>, 1, <LagrangeVariant.equispaced: 0>

Pylance also displays the error on gmsh.model:

Argument of type "Type[model]" cannot be assigned to parameter "model" of type "model" in function "model_to_mesh"
  "Type[type]" is incompatible with "Type[model]"

I’m new to python and dolfinx, so I apologize in advance if it’s a really stupid mistake

Could you add the exact conda commands you used to install the library, as I cannot reproduce this with the 0.6.0 release through docker.

I’ve installed everything again in a new environment, and the error is still the same. Here are the commands I used:

conda install -c conda-forge fenics-dolfinx
conda install -c conda-forge gmsh python-gmsh

Could you try installing Gmsh prior to installing dolfinx?

The gmsh install went fine, but when it came to DOLFINx compatibility problems came up:

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - fenics-dolfinx -> python[version='2.7.*|3.5.*|3.6.*|3.6.12|3.6.12|3.7.10|3.7.10|3.7.12|3.8.12|3.8.16|3.9.16|>=3.11,<3.12.0a0|3.9.10|>=3.6,<3.7.0a0|3.7.9|3.6.9|3.6.9|3.6.9|>=2.7,<2.8.0a0|3.6.9|>=3.5,<3.6.0a0|3.4.*|>=3.7|3.9.*|3.10.*|3.8.*|3.7.*',build='0_73_pypy|1_73_pypy|2_73_pypy|3_73_pypy|4_73_pypy|5_73_pypy|5_73_pypy|0_73_pypy|0_73_pypy|1_73_pypy']
  - fenics-dolfinx -> python[version='>=3.10,<3.11.0a0|>=3.9,<3.10.0a0|>=3.8,<3.9.0a0|>=3.7,<3.8.0a0']

Your python: python=3.11

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__glibc==2.35=0
  - feature:|@/linux-64::__glibc==2.35=0

Your installed version is: 2.35

I guess I’ll use docker containers to avoid this or other compatibilty issues, unless there’s another simpler solution.
Thank you in any case!

If you’re running it on an ubuntu system then why not use the ubuntu packages?

I can reproduce the issue with conda.
I’m not sure what happens there, seems like DOLFINx is not recognizing the Basix data-type

This solves the problem indeed. Thank you all!
It’s not as optimal as keeping environments but it’s enough for my use case.

I tracked it down to the pybind11 ABI changing when the compiler version changes, so dolfinx must be compiled with the same compiler version as basix, and dolfinx build 102 upgraded to gcc 12, while basix has not yet been rebuilt with gcc 12. I’m still not really sure why no tests had failed, but gmsh in particular is not exercised in the dolfinx package.

So for now you can select fenics-dolfinx=0.6.0=*_101 to choose the build that works.

I’ll upload fixed builds of basix and dolfinx to conda-forge soon.

2 Likes

I am using linux and I install dolfinx use conda but it also give the same issue. I did the following:
./mamba install -n fenicsx-env -c conda-forge fenics-dolfinx mpich pyvista gmsh python-gmsh

How to make sure they are compatible? Thank you

As stated by Min above, you should call
mamba install -n fenicsx-env -c conda-forge fenics-dolfinx=0.6.0=*_101
(With your additional dependencies after this).

I tried the thing you recommended, still not working.

Here is what I did:
./mamba install -n fenicsx-env -c conda-forge fenics-dolfinx=0.6.0=*_101 mpich pyvista gmsh python-gmsh pip adios2 numba
then I go to the virtual environment I created then the bin:
./pip install git+https://github.com/jorgensd/adios4dolfinx@v0.1.0

The error is:
Traceback (most recent call last):
File “write_checking.py”, line 16, in
adx.write_mesh(domain, mesh_checkpoint_file, engine=“BP4”)
File “miniconda3/envs/fenicsx-env-new/lib/python3.10/site-packages/adios4dolfinx/checkpointing.py”, line 53, in write_mesh
io.DefineAttribute(“LagrangeVariant”, np.array([mesh.geometry.cmap.variant], dtype=np.int32))
TypeError: Unable to convert function return value to a Python type! The signature was
(arg0: dolfinx.cpp.fem.CoordinateElement) → basix::element::lagrange_variant

My old dolfinx 0.6 installed on my laptop works well for the mesh and adios, I believe there is some change of newer dolfinx 0.6. I couldn’t run my code on my laptop because I am running a three D test, need more power, so I have to make sure everything is working on my virtual environment. Could you please help em with that?
Thank you so much!