Multiphenicsx DofMapRestriction not behaving as previously

I just updated dolfinx and multiphenicsx today and it seems multiphenicsx.fem.DofMapRestriction no longer works for me as it used to. I use the same construction as in the Lagrange multiplier interface tutorial. In fact, I get the same error running the above tutorial on my installation (I ommitted the viskex lines as I don’t have OpenGL on the cluster where dolfinx is installed). It is as follows

Traceback (most recent call last):
  File "/tmp_user/sator/hmmak/fenicsx-scripts/reordered_3D/test_mphx.py", line 60, in <module>
    restriction_V1_Omega1 = multiphenicsx.fem.DofMapRestriction(V1.dofmap, dofs_V1_Omega1)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp_user/sator/hmmak/spack/var/spack/environments/rlfx/.spack-env/view/lib/python3.11/site-packages/multiphenicsx/fem/dofmap_restriction.py", line 31, in __init__
    super().__init__(_dofmap, restriction)
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
    1. __init__(self, dofmap: dolfinx::fem::DofMap, restriction: list[int]) -> None

Invoked with types: multiphenicsx.fem.dofmap_restriction.DofMapRestriction, dolfinx.cpp.fem.DofMap, ndarray

Did the use of DofMapRestriction change completely without an edit of this tutorial? If so, how do I achieve what this tutorial does?

Which version of dolfinx are you using? Since you installed via spack, it’s probably to the development version. Please double check that you are using a compatible multiphenicsx version, see Installation — multiphenicsx

The errors is complaining about a list vs np.array, which is one of the changes that were required when dolfinx (and thus multiphenicsx) moved from pybind11 to nanobind. If you installed a 0.7.x dolfinx release but are using multiphenicsx from main, errors like that one would probably pop up in serveral places.

As you mentioned I installed via spack with dolfinx@main. I followed the instructions here for the development version of multiphenicsx. I even tried explicitly making the second input into a list as multiphenicsx.fem.DofMapRestriction(V1.dofmap, list(dofs_V1_Omega1)) which gave the same error except now with

Invoked with types: multiphenicsx.fem.dofmap_restriction.DofMapRestriction, dolfinx.cpp.fem.DofMap, list

Nonetheless I uninstalled multiphenicsx and re-cloned a fresh multiphenicsx. I then re-installed as you suggested here, and it seems all is well. It seems the fact that I used different compilers to install dolfinx and multiphenicsx messed with the compatibility perhaps of dolfinx.cpp.fem.DofMap.

Oh yeah, that is risky business, especially when wrapping with pybind11 or nanobind :wink:

1 Like

Hello, I’m currently facing the same problem with multiphenicsx.fem.DofMapRestriction on the hpc running the tutorial in spack enviroment but it works with my computer using docker environment. The error is as follows:

Traceback (most recent call last):
  File "/data/horse/ws/jesa624b-Multiphenicsx1/multiphenicsx_tutorial_2.py", line 67, in <module>
    restriction_V1_Omega1 = multiphenicsx.fem.DofMapRestriction(V1.dofmap, dofs_V1_Omega1)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/h2/jesa624b/spack/var/spack/environments/fenicsx080-env/.spack-env/view/lib/python3.11/site-packages/multiphenicsx/fem/dofmap_restriction.py", line 31, in __init__
    super().__init__(_dofmap, restriction)
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
    1. __init__(self, dofmap: dolfinx::fem::DofMap, restriction: list[int]) -> None

Invoked with types: multiphenicsx.fem.dofmap_restriction.DofMapRestriction, dolfinx.cpp.fem.DofMap, ndarray
srun: error: n1629: task 0: Exited with exit code 1

I’ve checked the dolfinx version on both sides which is dolfinx-v0.8.0 and downloaded multiphenicsx-dolfinx-v0.8.0 using this link which is compatible with dolfinx-v0.8.0. I’ve also tried uninstalling and reinstalling multiphenicsx but still it doesn’t work. I’ve also realized that the multiphenicsx compatible with dolfinx-v0.8.0 is still multiphenicsx-0.3.dev1.

You may be affected by this TypeError: __init__(): incompatible function arguments. [...] - #6 by mnotazio

Hello,
I also have the problem using dolfinx@0.9.0. I installed dolfinx on the HPC via spack and used the GCC/13.2.0 compiler. Using the installation commands specified here also works - no error messages occur.
However, when running tutorial 3 (interphase problem), I got the same error as stated above.
Does anyone have any recommendations on what to check and why it doesn’t work?

In case you did not notice, this issue was discussed in another thread. While the problem was eventually fixed, the installation followed there is through conda. Perhaps you can adapt it to the installation process you are following.

Thank you for your answer!
I installed nanobind==2.1.0 via pip in spack after the installation of dolfinx@0.9.0. The compiler I am using are specified in the compilers.yaml file:

compilers:
- compiler:
    spec: gcc@=13.2.0
    paths:
      cc: /software/rapids/r24.04/GCCcore/13.2.0/bin/gcc
      cxx: /software/rapids/r24.04/GCCcore/13.2.0/bin/g++
      f77: /software/rapids/r24.04/GCCcore/13.2.0/bin/gfortran
      fc: /software/rapids/r24.04/GCCcore/13.2.0/bin/gfortran
    flags: {}
    operating_system: rhel8
    target: x86_64
    modules: []
    environment: {}
    extra_rpaths: []

So from my point of view, It is supposed to also use the g++ compiler and not only gxx.

It will definitely use the C++ compiler. The point is that both the compiler and the nanobind version must match exactly the ones that were used to build dolfinx.