dolfinx_mpc icon indicating copy to clipboard operation
dolfinx_mpc copied to clipboard

fails to build with with GCC-15

Open drew-parsons opened this issue 9 months ago • 6 comments

A debian bug at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1096535 reports that dolfinx_mpc fails to build (fails tests) with gcc-15: Build log at http://qa-logs.debian.net/2025/02/16/amd64exp/dolfinx-mpc_0.9.0-2_unstable_gccexp.log.gz

There is a gcc-15 porting guide at http://gcc.gnu.org/gcc-15/porting_to.html

The report is for v0.9.0. I haven't tested independently, I don't know if it's fixed in 0.9.1.

sample error:

_________________________ test_cube_contact[True-C++] __________________________

generate_hex_boxes = (<dolfinx.mesh.Mesh object at 0x7f3c6595ae40>, <dolfinx.mesh.MeshTags object at 0x7f3c7748cb90>)
nonslip = True
get_assemblers = (<function assemble_matrix at 0x7f3c5d5e9d00>, <function assemble_vector at 0x7f3c5d5eb7e0>)

    @pytest.mark.parametrize("get_assemblers", ["C++"], indirect=True)
    @pytest.mark.parametrize("nonslip", [True, False])
    def test_cube_contact(generate_hex_boxes, nonslip, get_assemblers):  # noqa: F811
        assemble_matrix, assemble_vector = get_assemblers
        comm = MPI.COMM_WORLD
        root = 0
        # Generate mesh
        mesh_data = generate_hex_boxes
        mesh, mt = mesh_data
        fdim = mesh.topology.dim - 1
        # Create functionspaces
        V = fem.functionspace(mesh, ("Lagrange", 1, (mesh.geometry.dim,)))
    
        # Helper for orienting traction
    
        # Bottom boundary is fixed in all directions
        u_bc = fem.Function(V)
        with u_bc.x.petsc_vec.localForm() as u_local:
            u_local.set(0.0)
        u_bc.x.petsc_vec.destroy()
    
        bottom_dofs = fem.locate_dofs_topological(V, fdim, mt.find(5))
        bc_bottom = fem.dirichletbc(u_bc, bottom_dofs)
    
        g_vec = [0, 0, -4.25e-1]
        if not nonslip:
            # Helper for orienting traction
            r_matrix = dolfinx_mpc.utils.rotation_matrix([1 / np.sqrt(2), 1 / np.sqrt(2), 0], -theta)
    
            # Top boundary has a given deformation normal to the interface
            g_vec = np.dot(r_matrix, [0, 0, -4.25e-1])
    
        # Top boundary has a given deformation normal to the interface
        def top_v(x):
            values = np.empty((3, x.shape[1]))
            values[0] = g_vec[0]
            values[1] = g_vec[1]
            values[2] = g_vec[2]
            return values
    
        u_top = fem.Function(V)
        u_top.interpolate(top_v)
    
        top_dofs = fem.locate_dofs_topological(V, fdim, mt.find(3))
        bc_top = fem.dirichletbc(u_top, top_dofs)
    
        bcs = [bc_bottom, bc_top]
    
        # Elasticity parameters
        E = 1.0e3
        nu = 0
        mu = fem.Constant(mesh, default_scalar_type(E / (2.0 * (1.0 + nu))))
        lmbda = fem.Constant(mesh, default_scalar_type(E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu))))
    
        # Stress computation
        def sigma(v):
            return 2.0 * mu * ufl.sym(ufl.grad(v)) + lmbda * ufl.tr(ufl.sym(ufl.grad(v))) * ufl.Identity(len(v))
    
        # Define variational problem
        u = ufl.TrialFunction(V)
        v = ufl.TestFunction(V)
        a = ufl.inner(sigma(u), ufl.grad(v)) * ufl.dx
        rhs = ufl.inner(fem.Constant(mesh, default_scalar_type((0, 0, 0))), v) * ufl.dx
        bilinear_form = fem.form(a)
    
        linear_form = fem.form(rhs)
    
        # Create LU solver
        solver = PETSc.KSP().create(comm)
        solver.setType("preonly")
        solver.setTolerances(rtol=1.0e-14)
        solver.getPC().setType("lu")
    
        # Create MPC contact condition and assemble matrices
        mpc = dolfinx_mpc.MultiPointConstraint(V)
        if nonslip:
            with Timer("~Contact: Create non-elastic constraint"):
>               mpc.create_contact_inelastic_condition(mt, 4, 9, eps2=500 * np.finfo(default_scalar_type).resolution)

test_cube_contact.py:242: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <dolfinx_mpc.multipointconstraint.MultiPointConstraint object at 0x7f3c775fece0>
meshtags = <dolfinx.mesh.MeshTags object at 0x7f3c7748cb90>, slave_marker = 4
master_marker = 9, eps2 = 5e-13

    def create_contact_inelastic_condition(
        self,
        meshtags: _cpp.mesh.MeshTags_int32,
        slave_marker: int,
        master_marker: int,
        eps2: float = 1e-20,
    ):
        """
        Create a contact inelastic condition between two sets of facets marker with individual markers.
        The interfaces should be within machine precision of eachother, but the vertices does not need to align.
        The condition created is :math:`u_s = u_m` where `s` is the restriction to the
        slave facets, `m` to the master facets.
    
        Args:
            meshtags: The meshtags of the set of facets to tie together
            slave_marker: The marker of the slave facets
            master_marker: The marker of the master facets
            eps2: The tolerance for the squared distance between cells to be considered as a collision
        """
        if isinstance(eps2, numpy.generic):  # nanobind conversion of numpy dtypes to general Python types
            eps2 = eps2.item()  # type: ignore
>       mpc_data = dolfinx_mpc.cpp.mpc.create_contact_inelastic_condition(
            self.V._cpp_object, meshtags._cpp_object, slave_marker, master_marker, eps2
        )
E       TypeError: create_contact_inelastic_condition(): incompatible function arguments. The following argument types are supported:
E           1. create_contact_inelastic_condition(arg0: dolfinx::fem::FunctionSpace<float>, arg1: dolfinx::mesh::MeshTags<int>, arg2: int, arg3: int, arg4: float, /) -> dolfinx_mpc.cpp.mpc.mpc_data_float
E           2. create_contact_inelastic_condition(arg0: dolfinx::fem::FunctionSpace<float>, arg1: dolfinx::mesh::MeshTags<int>, arg2: int, arg3: int, arg4: float, /) -> dolfinx_mpc.cpp.mpc.mpc_data_complex_float
E           3. create_contact_inelastic_condition(arg0: dolfinx::fem::FunctionSpace<double>, arg1: dolfinx::mesh::MeshTags<int>, arg2: int, arg3: int, arg4: float, /) -> dolfinx_mpc.cpp.mpc.mpc_data_double
E           4. create_contact_inelastic_condition(arg0: dolfinx::fem::FunctionSpace<double>, arg1: dolfinx::mesh::MeshTags<int>, arg2: int, arg3: int, arg4: float, /) -> dolfinx_mpc.cpp.mpc.mpc_data_complex_double
E       
E       Invoked with types: dolfinx.cpp.fem.FunctionSpace_float64, dolfinx.cpp.mesh.MeshTags_int32, int, int, float

../../debian/python3-dolfinx-mpc/usr/lib/python3.13/dist-packages/dolfinx_mpc/multipointconstraint.py:461: TypeError
---------------------------- Captured stdout setup -----------------------------
Info    : Clearing all models and views...
Info    : Done clearing all models and views

drew-parsons avatar Mar 10 '25 20:03 drew-parsons

at first glance, this looks like an issue with using different compilers for dolfinx and dolfimx_mpc, on the nanobind/python interface level. I can’t download the logs on my phone, but is dolfinx built with same compiler, same nanobind version?

jorgensd avatar Mar 10 '25 20:03 jorgensd

Good question, that may well be the issue, not gcc-15 itself. I'll keep monitoring it.

The versions in the reported log are: gcc-15 15-20250213-1 nanobind 2.5.0-1 dolfinx 1:0.9.0-6+b2 python 3.13.2-1

dolfinx 1:0.9.0-6+b2 was built against nanobind 2.4.0-1 and python3 3.13.1-3.

So likely you're right, it's the mismatch between nanobind 2.4.0 and 2.5.0.

drew-parsons avatar Mar 10 '25 23:03 drew-parsons

The debian package dependency mechanism expects incompatibility only with the major version, not the minor version. Perhaps that needs to be tightened up, if the problem really is nanobind 2.4 vs 2.5.

drew-parsons avatar Mar 11 '25 00:03 drew-parsons

The debian package dependency mechanism expects incompatibility only with the major version, not the minor version. Perhaps that needs to be tightened up, if the problem really is nanobind 2.4 vs 2.5.

Nanobind is very strict with the versions: https://nanobind.readthedocs.io/en/latest/faq.html#how-can-i-avoid-conflicts-with-other-projects-using-nanobind

use the same nanobind ABI version (see the Changelog for details). use the same compiler (extensions built with GCC and Clang are isolated from each other). use ABI-compatible versions of the C++ library. use the stable ABI interface consistently (stable and unstable builds are isolated from each other). use debug/release mode consistently (debug and release builds are isolated from each other).

Allthough the ABI version is the same between 2.4 and 2.5 https://nanobind.readthedocs.io/en/latest/changelog.html#version-2-2-0-october-3-2024

jorgensd avatar Mar 11 '25 04:03 jorgensd

@drew-parsons is there anything I can do to guide you further?

jorgensd avatar Mar 13 '25 07:03 jorgensd

I guess the only thing to do at this point is check if dolfinx_mpc generally builds successfully with gcc-15. Is it easy to configure docker to use gcc-15?

drew-parsons avatar Mar 13 '25 09:03 drew-parsons