Major problem ImportError FFCX

Dear Community,

Since yesterday I have an import error of FFCX each time I try to use form(). Here is the MWE and the bug associated. But before, for the record : I’m using apple silicon M3 and my architecture was based on conda, and I deeply need the complex value architecture of FEniCSx

MWE :

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

from ufl import (TestFunction, TrialFunction,
                 Measure,
                 FacetNormal,
                 inner, grad, div,
                 Dn)
from basix.ufl import element
from dolfinx.fem import functionspace, form, petsc

def generate_cube_gmshio(side_length=1.0, filename="cube.msh"):
    """
    Generate a cube with side length `side_length`,
    export the mesh to `filename`, and
    return (final_mesh, cell_tags, facet_tags).
    """
    # Initialize the Gmsh API
    gmsh.initialize()

    # Retrieve the MPI communicator and rank
    comm = MPI.COMM_WORLD
    model_rank = 0

    # Reference the Gmsh model
    model = gmsh.model
    model.add("cube")

    # Create the cube with the OpenCASCADE kernel
    # (x, y, z, dx, dy, dz)
    box_tag = model.occ.addBox(0, 0, 0, side_length, side_length, side_length)

    # Synchronize the geometry
    model.occ.synchronize()

    # (Optional) add a physical group for the volume (tag=1)
    model.addPhysicalGroup(3, [box_tag], tag=1)

    # Generate the 3D mesh with second-order elements
    gmsh.option.setNumber("Mesh.ElementOrder", 2)
    gmsh.option.setNumber("Mesh.HighOrderOptimize", 2)
    model.mesh.generate(3)

    # Save the mesh to a .msh file
    gmsh.write(filename)

    # Convert the Gmsh mesh into a FEniCSx mesh
    final_mesh, cell_tags, facet_tags = gmshio.model_to_mesh(
        model, comm, model_rank
    )

    # Finalize Gmsh
    gmsh.finalize()

    # Return the objects describing the mesh in FEniCSx
    return final_mesh, cell_tags, facet_tags

# Example usage:
if __name__ == "__main__":
    # Generate a cube mesh and retrieve mesh data
    final_mesh, cell_tags, facet_tags = generate_cube_gmshio(1.0, "cube.msh")

    # Define volume (dx) and surface (ds) measures
    dx = Measure("dx", domain=final_mesh)

    # Define a Lagrange element of degree 3
    P1 = element("Lagrange", final_mesh.basix_cell(), 2)
    P = functionspace(final_mesh, P1)

    # Define trial and test functions
    p, v = TrialFunction(P), TestFunction(P)

    # Define the volumetric bilinear form
    k = inner(p, v) * dx

    # Assemble the total form
    A = form(k)
    

The error :

Traceback (most recent call last):
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 97, in get_cached_module
    with open(c_filename, "x"):
FileExistsError: [Errno 17] File exists: '/Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.c'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pierremariotti/Documents/PhD/FEniCSx/new_try2/root/ABC_FEniCSx_classical/mwe_FEniCSx.py", line 78, in <module>
    A = form(k)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 337, in form
    return _create_form(form)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 331, in _create_form
    return _form(form)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 254, in _form
    ufcx_form, module, code = jit.ffcx_jit(
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/jit.py", line 62, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/jit.py", line 212, in ffcx_jit
    r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 188, in compile_forms
    obj, mod = get_cached_module(module_name, form_names, cache_dir, timeout)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 114, in get_cached_module
    compiled_module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1176, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: dlopen(/Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.cpython-310-darwin.so, 0x0002): tried: '/Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.cpython-310-darwin.so' (duplicate LC_RPATH '/opt/anaconda3/envs/env3-10-complex/lib'), '/System/Volumes/Preboot/Cryptexes/OS/Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.cpython-310-darwin.so' (no such file), '/Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.cpython-310-darwin.so' (duplicate LC_RPATH '/opt/anaconda3/envs/env3-10-complex/lib')

And all I tried was removing the cache with

rm -rf ~/.cache/fenics

Thanks for the support,
I’m supposed to submit my article very soon and I need to recover some results..

Dear @pierremrtt,
What error message do you get when removing the “cached” form file at:

Looking further at your error message, it looks related to:

See the suggested resolution in the post:

I’m not sure what happened so I’m going to give it line by line :

I firstly removed the file quoted using

rm -rf /Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.c

which didn’t gave any error or message.
I re-run my script and the following error appeared :

ld: warning: duplicate -rpath '/opt/anaconda3/envs/env3-10-complex/lib' ignored
ld: warning: duplicate -rpath '/opt/anaconda3/envs/env3-10-complex/lib' ignored
ld: warning: duplicate -rpath '/opt/anaconda3/envs/env3-10-complex/lib' ignored
ld: warning: duplicate -rpath '/opt/anaconda3/envs/env3-10-complex/lib' ignored
Traceback (most recent call last):
  File "/Users/pierremariotti/Documents/PhD/FEniCSx/new_try2/root/ABC_FEniCSx_classical/mwe_FEniCSx.py", line 79, in <module>
    A = form(k)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 337, in form
    return _create_form(form)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 331, in _create_form
    return _form(form)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 254, in _form
    ufcx_form, module, code = jit.ffcx_jit(
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/jit.py", line 62, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/jit.py", line 212, in ffcx_jit
    r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 225, in compile_forms
    raise e
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 205, in compile_forms
    impl = _compile_objects(
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 390, in _compile_objects
    fd = open(ready_name, "x")
FileExistsError: [Errno 17] File exists: '/Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.c.cached'

So I removed the “cached” file, the same one but with “.cached” added at the end :

rm -rf /Users/pierremariotti/.cache/fenics/libffcx_forms_8ff3a977f949229519a3cca1fb86ddf3d3d6c342.c.cached

Still no message out of this command.

Then I re-re-run the code and now it works. As I receated a conda env now I have to re install all lib like matplotlib and so on but it looks like it worked. And you are right @dokken , the topic is exactly related. If I face again the error, I’ll go to check.

I’ve built again all the libraries I need and the problem is back

Traceback (most recent call last):
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 97, in get_cached_module
    with open(c_filename, "x"):
FileExistsError: [Errno 17] File exists: '/Users/pierremariotti/.cache/fenics/libffcx_forms_9b983cebf9ff7ad90e3f6922a3beee48e45114fa.c'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pierremariotti/Documents/PhD/FEniCSx/new_try2/root/ABC_FEniCSx_classical/test_oldABCnewVn.py", line 72, in <module>
    ope     = B2p(mesh_)
  File "/Users/pierremariotti/Documents/PhD/FEniCSx/new_try2/root/ABC_FEniCSx_classical/operators_POO.py", line 1029, in __init__
    self.list_D = self.b2p_newVersion()
  File "/Users/pierremariotti/Documents/PhD/FEniCSx/new_try2/root/ABC_FEniCSx_classical/operators_POO.py", line 1081, in b2p_newVersion
    K = form(k)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 337, in form
    return _create_form(form)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 331, in _create_form
    return _form(form)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/fem/forms.py", line 254, in _form
    ufcx_form, module, code = jit.ffcx_jit(
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/jit.py", line 62, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/dolfinx/jit.py", line 212, in ffcx_jit
    r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 188, in compile_forms
    obj, mod = get_cached_module(module_name, form_names, cache_dir, timeout)
  File "/opt/anaconda3/envs/env3-10-complex/lib/python3.10/site-packages/ffcx/codegeneration/jit.py", line 114, in get_cached_module
    compiled_module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1176, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: dlopen(/Users/pierremariotti/.cache/fenics/libffcx_forms_9b983cebf9ff7ad90e3f6922a3beee48e45114fa.cpython-310-darwin.so, 0x0002): tried: '/Users/pierremariotti/.cache/fenics/libffcx_forms_9b983cebf9ff7ad90e3f6922a3beee48e45114fa.cpython-310-darwin.so' (duplicate LC_RPATH '/opt/anaconda3/envs/env3-10-complex/lib'), '/System/Volumes/Preboot/Cryptexes/OS/Users/pierremariotti/.cache/fenics/libffcx_forms_9b983cebf9ff7ad90e3f6922a3beee48e45114fa.cpython-310-darwin.so' (no such file), '/Users/pierremariotti/.cache/fenics/libffcx_forms_9b983cebf9ff7ad90e3f6922a3beee48e45114fa.cpython-310-darwin.so' (duplicate LC_RPATH '/opt/anaconda3/envs/env3-10-complex/lib')

I’m going to check in the post you shared.
Thanks