I’m trying to solve a complex eigenvalue problem. I’ve installed anaconda using homebrew, and created an environment with conda create -n fenicsx-cmplx-env -c conda-forge fenics-dolfinx "petsc==complex" "petsc4py==complex mpich pyvista. The platform is macOS 26.5.2.
The ImportError manifests when I get to the stage of translating a UFL form to discrete FE, Here is a MWE:
# 2.5D wave propagation on rectangular bar, hacked from example in fenicsx primer
# Problem parameters
Lx = 0.8
Ly = 0.6
rho = 1.0
mu = 1.0;
lam = 2.0;
k = 1.0;
from mpi4py import MPI
from dolfinx import mesh
import numpy as np
# Mesh size
nx = 40
ny = 30
domain = mesh.create_rectangle(MPI.COMM_WORLD, [np.array([0,0]), np.array([Lx,Ly])], [nx,ny], mesh.CellType.quadrilateral)
from dolfinx import fem
from dolfinx.fem import petsc
from basix.ufl import element, mixed_element
V = fem.functionspace(domain, ("Lagrange", 2))
from ufl import (
TestFunctions,
TrialFunctions,
conj,
div,
dx,
grad,
inner,
transpose,
)
# 1. Elements and Function Spaces
# In-plane component (2D vector element) and out-of-plane component (scalar element)
vector_el = element("Lagrange", domain.basix_cell(), 2, shape=(2,))
scalar_el = element("Lagrange", domain.basix_cell(), 2)
mixed_el = mixed_element([vector_el, scalar_el])
V = fem.functionspace(domain, mixed_el)
# Trial functions (u12, u3) and Test functions (v12, v3)
u12, u3 = TrialFunctions(V)
v12, v3 = TestFunctions(V)
# 3. Weak Form Construction (using integration by parts)
# Note: inner(a, b) automatically handles complex conjugate for b in UFL complex mode.
# --- Equation 1: In-plane components (u12) ---
# Weak form terms after integrating (grad(div(u12)) + div(grad(u12))) by parts:
a_in_plane = (
lam * (div(u12) - 1j*k*u3) * div(conj(v12)) * dx
+ mu * inner(grad(u12)+transpose(grad(u12)), grad(v12)) * dx
+ mu * 1j * k * inner((grad(u3) - 1j*k*u12), v12) * dx
)
m_in_plane = rho * inner(u12, v12) * dx
# --- Equation 2: Out-of-plane component (u3) ---
# Weak form terms after integrating div(grad(u3)) by parts:
a_out_plane = (
mu * inner((grad(u3) - 1j*k*u12), grad(v3)) * dx
+ lam * 1j * k * (div(u12) - 1j*k*u3) * conj(v3) * dx
+ 2 * mu * (k**2) * u3 * conj(v3) * dx
)
m_out_plane = rho * u3 * conj(v3) * dx
# Total Bilinear Form and mass matrix
a = a_in_plane + a_out_plane
m = m_in_plane + m_out_plane
# Assemble forms into PETSc Matrices: A * x = omega^2 * M * x
a_form = fem.form(a,dtype=np.complex128)
I’m aware of previous threads involving ImportErrors and libffcx* files in the fenics cache, but I believe my installation is more recent than the ones causing those problems. Here is the error trace:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[6], line 2
1 # Assemble forms into PETSc Matrices: A * x = omega^2 * M * x
----> 2 a_form = fem.form(a,dtype=np.complex128)
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/fem/forms.py:337, in form(form, dtype, form_compiler_options, jit_options, entity_maps)
334 else:
335 return form
--> 337 return _create_form(form)
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/fem/forms.py:331, in form.<locals>._create_form(form)
329 return None
330 else:
--> 331 return _form(form)
332 elif isinstance(form, collections.abc.Iterable):
333 return list(map(lambda sub_form: _create_form(sub_form), form))
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/fem/forms.py:254, in form.<locals>._form(form)
252 if mesh is None:
253 raise RuntimeError("Expecting to find a Mesh in the form.")
--> 254 ufcx_form, module, code = jit.ffcx_jit(
255 mesh.comm, form, form_compiler_options=form_compiler_options, jit_options=jit_options
256 )
258 # For each argument in form extract its function space
259 V = [arg.ufl_function_space()._cpp_object for arg in form.arguments()]
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/jit.py:62, in mpi_jit_decorator.<locals>.mpi_jit(comm, *args, **kwargs)
58 @functools.wraps(local_jit)
59 def mpi_jit(comm, *args, **kwargs):
60 # Just call JIT compiler when running in serial
61 if comm.size == 1:
---> 62 return local_jit(*args, **kwargs)
64 # Default status (0 == ok, 1 == fail)
65 status = 0
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/dolfinx/jit.py:212, in ffcx_jit(ufl_object, form_compiler_options, jit_options)
210 # Switch on type and compile, returning cffi object
211 if isinstance(ufl_object, ufl.Form):
--> 212 r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
213 elif isinstance(ufl_object, ufl.Mesh):
214 r = ffcx.codegeneration.jit.compile_coordinate_maps([ufl_object], options=p_ffcx, **p_jit)
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/ffcx/codegeneration/jit.py:227, in compile_forms(forms, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
224 pass
225 raise e
--> 227 obj, module = _load_objects(cache_dir, module_name, form_names)
228 return obj, module, (decl, impl)
File /opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib/python3.12/site-packages/ffcx/codegeneration/jit.py:416, in _load_objects(cache_dir, module_name, object_names)
413 raise ModuleNotFoundError("Unable to find JIT module.")
415 # Load module
--> 416 compiled_module = importlib.util.module_from_spec(spec)
417 spec.loader.exec_module(compiled_module)
419 compiled_objects = []
File <frozen importlib._bootstrap>:813, in module_from_spec(spec)
File <frozen importlib._bootstrap_external>:1293, in ExtensionFileLoader.create_module(self, spec)
1291 'Could not get source, probably due dynamically evaluated source code.'
File <frozen importlib._bootstrap>:488, in _call_with_frames_removed(f, *args, **kwds)
ImportError: dlopen(/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so, 0x0002): tried: '/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so' (duplicate LC_RPATH '/opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib'), '/System/Volumes/Preboot/Cryptexes/OS/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so' (no such file), '/Users/wrg11/.cache/fenics/libffcx_forms_41aa2780b858b7716b72c819d34f0dcdd597494b.cpython-312-darwin.so' (duplicate LC_RPATH '/opt/homebrew/Caskroom/miniforge/base/envs/fenicsx-cmplx-env/lib')