Question about tutorial on lagrange multiplier interface

after installing with the command
conda install -c conda-forge fenics-dolfinx=0.9 nanobind
I again ran the code and got an error here in the tutorial

# Define restrictions
dofs_V1_Omega1 = dolfinx.fem.locate_dofs_topological(V1, subdomains.dim, cells_Omega1)
dofs_V2_Omega2 = dolfinx.fem.locate_dofs_topological(V2, subdomains.dim, cells_Omega2)
dofs_M_Gamma = dolfinx.fem.locate_dofs_topological(M, boundaries_and_interfaces.dim, facets_Gamma)
restriction_V1_Omega1 = multiphenicsx.fem.DofMapRestriction(V1.dofmap, dofs_V1_Omega1)
restriction_V2_Omega2 = multiphenicsx.fem.DofMapRestriction(V2.dofmap, dofs_V2_Omega2)
restriction_M_Gamma = multiphenicsx.fem.DofMapRestriction(M.dofmap, dofs_M_Gamma)
restriction = [restriction_V1_Omega1, restriction_V2_Omega2, restriction_M_Gamma]

here is the error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[60], line 5
      3 dofs_V2_Omega2 = dolfinx.fem.locate_dofs_topological(V2, subdomains.dim, cells_Omega2)
      4 dofs_M_Gamma = dolfinx.fem.locate_dofs_topological(M, boundaries_and_interfaces.dim, facets_Gamma)
----> 5 restriction_V1_Omega1 = multiphenicsx.fem.DofMapRestriction(V1.dofmap, dofs_V1_Omega1)
      6 restriction_V2_Omega2 = multiphenicsx.fem.DofMapRestriction(V2.dofmap, dofs_V2_Omega2)
      7 restriction_M_Gamma = multiphenicsx.fem.DofMapRestriction(M.dofmap, dofs_M_Gamma)

File ~/anaconda3/envs/fenicsx9/lib/python3.13/site-packages/multiphenicsx/fem/dofmap_restriction.py:31, in DofMapRestriction.__init__(self, dofmap, restriction)
     29 except AttributeError:  # pragma: no cover
     30     _dofmap = dofmap
---> 31 super().__init__(_dofmap, restriction)

TypeError: __init__(): incompatible function arguments. The following argument types are supported:
    1. __init__(self, dofmap: dolfinx::fem::DofMap, restriction: collections.abc.Sequence[int]) -> None

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

I am now running with nanobind 2.1

Running the code again is not enough, you must reinstall multiphenicsx as well.

It is not clear to me how to reinstall multiphenicsx. Following the instructions from

I try the command
DOLFINX_VERSION=$(python3 -c ‘import dolfinx; print(dolfinx.version)’)
and I get the response

(fenicsx9) dannyb@dannyslaptop:~/multiphenicsx$ DOLFINX_VERSION=$(python3 -c 'import dolfinx; print(dolfinx.__version__)')
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import dolfinx; print(dolfinx.__version__)
    ^^^^^^^^^^^^^^
  File "/home/dannyb/anaconda3/envs/fenicsx9/lib/python3.13/site-packages/dolfinx/__init__.py", line 30, in <module>
    from dolfinx import common
  File "/home/dannyb/anaconda3/envs/fenicsx9/lib/python3.13/site-packages/dolfinx/common.py", line 11, in <module>
    from dolfinx import cpp as _cpp
ImportError: libfmt.so.11: cannot open shared object file: No such file or directory

The part with DOLFINX_VERSION is just to get the right branch from the repo. I assume you have already done that earlier today (when you installed for the first time), so you can directly jump to the pip install line.

Still, having a library libfmt.so.11 that suddenly disappeared from your environment is not a good sign. You may want to reinstall it using similar instructions to the one that you were suggested above: try to find which conda package ships libfmt.so, double check if you have it already or not, and if not install it again.

Referring to the website
https://fmt.dev/11.0/get-started/
I used the command
conda install -c conda-forge fmt
in an attempt top install the missing libfmt.so.11. I don’t know if this helped, but on reinstalling mutilphenicsx …

Successfully built multiphenicsx
Installing collected packages: multiphenicsx
  Attempting uninstall: multiphenicsx
    Found existing installation: multiphenicsx 0.3.dev1
    Uninstalling multiphenicsx-0.3.dev1:
      Successfully uninstalled multiphenicsx-0.3.dev1
Successfully installed multiphenicsx-0.3.dev1

I still get the same diagnostic listed above

Are you sure you got rid of the old nanobind 2.2 installation?
Can you try from scratch in a new (temporary) FEniCS 0.9 environment?

I thought I had reinstalled nanobind 2.1, but apparently not. Here is what I am now getting

(fenicsx9) dannyb@dannyslaptop:~/multiphenicsx$ conda install -c conda-forge fenics-dolfinx=0.9 nanobind
Channels:
 - conda-forge
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

# All requested packages already installed.

(fenicsx9) dannyb@dannyslaptop:~/multiphenicsx$ conda list nanobind
# packages in environment at /home/dannyb/anaconda3/envs/fenicsx9:
#
# Name                    Version                   Build  Channel
fenics-basix-nanobind-abi 0.2.1.13             hacda0c5_1    conda-forge
nanobind                  2.2.0                    pypi_0    pypi

How can I uninstall 2.2 and reinstall 2.1?

We are happy to help, but some of these questions are so basic that a simple search online would have given you the answer without waiting for us. Run pip uninstall nanobind.

My apologies. I realize that this is taking way too long. I suspect that one of the commands that was suggested above uninstalled 2.1 and reinstalled 2.2, but that is conjecture on my part. I will google some more and see if I can resolve this. It seems that there are some (to me arcane) rules about when to use pip and when to use conda, but I realize that ultimately it will be up to me to work through this stuff.

Suggestion would be: start from scratch on a clean environment, and check if it works there.

I appreciate your help, but there are some things I am not understanding that I fear will replicate themselves even if I start in a new environment. In particular

(fenicsx9) dannyb@dannyslaptop:~/multiphenicsx$ conda list nanobind
# packages in environment at /home/dannyb/anaconda3/envs/fenicsx9:
#
# Name                    Version                   Build  Channel
fenics-basix-nanobind-abi 0.2.1.13             hacda0c5_1    conda-forge
nanobind                  2.2.0                    pypi_0    pypi
(fenicsx9) dannyb@dannyslaptop:~/multiphenicsx$ pip uninstall nanobind
Found existing installation: nanobind 2.1.0
Uninstalling nanobind-2.1.0:
  Would remove:
    /home/dannyb/anaconda3/envs/fenicsx9/lib/python3.13/site-packages/nanobind-2.1.0.dist-info/*
    /home/dannyb/anaconda3/envs/fenicsx9/lib/python3.13/site-packages/nanobind/*
  Would not remove (might be manually added):
    /home/dannyb/anaconda3/envs/fenicsx9/lib/python3.13/site-packages/nanobind/include/nanobind/stl/detail/nb_optional.h
Proceed (Y/n)? n

The above command
conda list nanobind
tells me I have installed version 2.2, yet when I write
pip uninstall nanobind
it asks me if I want to uninstall ver. 2.1. (I said no.)

Any help is appreciated. My apologies for being so dense.

I installed in a clean environment, here are the commands I used

conda create -n fenicsx9-env
conda activate fenicsx9-env
conda install -c conda-forge fenics-dolfinx mpich pyvista
cd multiphenicsx
DOLFINX_VERSION=$(python3 -c 'import dolfinx; print(dolfinx.__version__)')   
git checkout dolfinx-v${DOLFINX_VERSION}
if [ -f setup.cfg ]; then                                                                                                              
    python3 -m pip install '.[tutorials]'                                                                                                                                                  
else                                                                                                                                                                                       
    python3 -m pip install --check-build-dependencies --no-build-isolation '.[tutorials]'                                                                                                  
fi                                                        

Here is what I get

Processing /home/dannyb/multiphenicsx                                                                                                                                                      
ERROR: Some build dependencies for file:///home/dannyb/multiphenicsx are missing: 'nanobind >= 2.1.0', 'scikit-build-core[pyproject]'.

This is precisely what happened in the original environment. There must be something wrong with the command chain that I am using.

To chime in this running conversation, I just did a clean install as follows:

  1. sudo apt-get install build-essential
  2. In a new conda environment:
    mamba install -c conda-forge fenics-dolfinx mpich pyvista nanobind scikit-build-core cmake wheel gmsh python-gmsh ninja gcc ipykernel
  3. Install viskex
  4. Deactivate then reactivate the environment and install multiphenicsx which goes fine
  5. Running tutorial 3 leads me to the same error reported above
  6. mamba list nanobind gives the following:

This is what I ran on a clear condaforge/miniforge3 docker image

conda create -n fenicsx-env
conda activate fenicsx-env
conda install -c conda-forge fenics-dolfinx mpich pyvista
conda install -c conda-forge nanobind scikit-build-core cmake wheel ninja gxx python-gmsh

git clone https://github.com/multiphenics/multiphenicsx.git
cd multiphenicsx
git checkout dolfinx-v0.9.0
python3 -m pip install --check-build-dependencies --no-build-isolation '.[tutorials]'

and I get no errors. I’ll try to update the website in the next few days with these details, since it seems to be a common problem. Maybe I’ll add jupyterlab as well in the dependencies.

Don’t get scared by the question “do you want to uninstall?”. You really want to uninstall 2.1, as you must get rid of nanobind 2.1!

That’s correct. You are in the same situation as yesterday. But now do the right thing: install those two missing packages using conda rather than using pip!

I am prepared to bet that since you only installed gcc (the C compiler) but not gxx (the C++ compiler), your installation of multiphenicsx used the system wide compiler (provided by ubuntu) which may possibly be different from the one used by conda. nanobind is very picky in that respect, and any mismatch (library version, compiler version) may result in the error that you both are seeing.

1 Like

I am glad I did not bet against it :wink:

While installing, I kept adding things to the conda install list but at some point thought the process was never ending and went for the build-essential package from Ubuntu. It helped but not in a way it should.

To sum up, here is how it should hopefully work for users operating out of a WSL environment:

mamba install -c conda-forge fenics-dolfinx mpich pyvista nanobind scikit-build-core cmake wheel gmsh python-gmsh ninja gcc ipykernel gxx

Thanks a lot for the magic advice!

This works for me! Thanks to both of you for your patience and your help!

Hi, I encountered the same issue, and this worked for me on my Windows laptop with WSL. However, now I’m trying to install multiphenicsx in the same way, but I ran into a new issue on macOS:

Building wheels for collected packages: multiphenicsx, viskex
  Building wheel for multiphenicsx (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for multiphenicsx (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [51 lines of output]
      *** scikit-build-core 0.10.7 using CMake 3.28.3 (wheel)
      *** Configuring CMake...
      2025-01-27 17:04:43,875 - scikit_build_core - WARNING - Unsupported CMAKE_ARGS ignored: -DCMAKE_BUILD_TYPE=Release
      2025-01-27 17:04:49,662 - scikit_build_core - WARNING - Unsupported CMAKE_ARGS ignored: -DCMAKE_BUILD_TYPE=Release
      loading initial cache file /var/folders/cd/x63sv1sd6b5fgz5j1fz4pp300000gp/T/tmpb3f8loyr/build/CMakeInit.txt
      -- The C compiler identification is Clang 18.1.8
      -- The CXX compiler identification is Clang 18.1.8
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/x86_64-apple-darwin13.4.0-clang - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - failed
      -- Check for working CXX compiler: /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/clang++
      -- Check for working CXX compiler: /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/clang++ - broken
      CMake Error at /Users/saragazzoni/anaconda3/envs/multiphenicsx/share/cmake-3.28/Modules/CMakeTestCXXCompiler.cmake:60 (message):
        The C++ compiler
      
          "/Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/clang++"
      
        is not able to compile a simple test program.
      
        It fails with the following output:
      
          Change Dir: '/var/folders/cd/x63sv1sd6b5fgz5j1fz4pp300000gp/T/tmpb3f8loyr/build/CMakeFiles/CMakeScratch/TryCompile-wo8J1F'
      
          Run Build Command(s): /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/ninja -v cmTC_4ff8f
          [1/2] /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/clang++   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -MD -MT CMakeFiles/cmTC_4ff8f.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_4ff8f.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_4ff8f.dir/testCXXCompiler.cxx.o -c /var/folders/cd/x63sv1sd6b5fgz5j1fz4pp300000gp/T/tmpb3f8loyr/build/CMakeFiles/CMakeScratch/TryCompile-wo8J1F/testCXXCompiler.cxx
          [2/2] : && /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/clang++ -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/saragazzoni/anaconda3/envs/multiphenicsx/lib -L/Users/saragazzoni/anaconda3/envs/multiphenicsx/lib CMakeFiles/cmTC_4ff8f.dir/testCXXCompiler.cxx.o -o cmTC_4ff8f   && :
          FAILED: cmTC_4ff8f
          : && /Users/saragazzoni/anaconda3/envs/multiphenicsx/bin/clang++ -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/saragazzoni/anaconda3/envs/multiphenicsx/lib -L/Users/saragazzoni/anaconda3/envs/multiphenicsx/lib CMakeFiles/cmTC_4ff8f.dir/testCXXCompiler.cxx.o -o cmTC_4ff8f   && :
          dyld[4740]: Symbol not found: __ZNK4tapi2v119LinkerInterfaceFile28getPlatformsAndMinDeploymentEv
            Referenced from: <9F0E4558-C058-3205-A28C-32E28755B708> /Library/Developer/CommandLineTools/usr/bin/ld
            Expected in:     <9918D37F-F19F-30B9-B311-13829B79C3B0> /Users/saragazzoni/anaconda3/envs/multiphenicsx/lib/libtapi.dylib
          clang++: error: unable to execute command: Abort trap: 6
          clang++: error: linker command failed due to signal (use -v to see invocation)
          ninja: build stopped: subcommand failed.
      
      
      
      
      
        CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
        CMakeLists.txt:3 (project)
      
      
      -- Configuring incomplete, errors occurred!
      
      *** CMake configuration failed
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for multiphenicsx

Do you have any idea how to solve this?