Problem running demo_poisson.py

Hello,

I have recently installed dolfinx 0.9.0 from source under ubuntu 24.04 and python 3.12. I am having difficulty running the file demo_poisson.py using the command

% mpirun -n 1 python demo_poisson.py

The output I get is:

(py312env) peter:demo % mpirun -n 1 python demo_poisson.py
Traceback (most recent call last):
  File "/home/peter/fromnet/fenicsx9/dolfinx-0.9.0.post1/python/demo/demo_poisson.py", line 107, in <module>
    V = fem.functionspace(msh, ("Lagrange", 1))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/peter/py312env/lib/python3.12/site-packages/dolfinx/fem/function.py", line 628, in functionspace
    cpp_element = _create_dolfinx_element(mesh.comm, mesh.topology.cell_type, ufl_e, dtype)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/peter/py312env/lib/python3.12/site-packages/dolfinx/fem/function.py", line 586, in _create_dolfinx_element
    return CppElement(basix_e, ufl_e.block_size, ufl_e.is_symmetric)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
    1. __init__(self, element: basix::FiniteElement<double>, block_size: int, symmetric: bool) -> None
    2. __init__(self, elements: collections.abc.Sequence[dolfinx.cpp.fem.FiniteElement_float64]) -> None
    3. __init__(self, cell_type: dolfinx.cpp.mesh.CellType, points: numpy.ndarray[dtype=float64, shape=(*, *)], block_size: int, symmetry: bool) -> None

Invoked with types: dolfinx.cpp.fem.FiniteElement_float64, basix._basixcpp.FiniteElement_float64, int, bool
--------------------------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpirun detected that one or more processes exited with non-zero status, thus causing
the job to be terminated. The first process to do so was:

  Process name: [[51653,1],0]
  Exit code:    1
--------------------------------------------------------------------------

I am not sure what other information I can give. Any advice would be much appreciated.

Thank you,

Peter.

That typically means that you have built basix and dolfinx with two different versions of the c++ compiler and/or nanobind.

Thanks for your reply.

In that case I really don’t understand the installation process under ubuntu. I began with

sudo apt install fenicsx

I then ran

pip install fenics-basix
pip install fenics-ufl
pip install fenics-ffcx

The only thing I could see to then was to build dolfinx from source and install as outlined.

Have I missed something? I don’t want to use conda or docker.

Thanks again,

Peter.

You shouldn’t need to run the pip install commands when installing from apt. Please uninstall those packages with pip uninstall and then check if the «original» apt installed packages are still around/or reinstall it.

Thanks for your ideas, dokken.

I uninstalled the three fenics associated files with pip uninstall. I then removed all of fenicsx with sudo apt remove fenicsx and sudo apt autoremove. As best as I can tell this removed fenicsx from my system. I then reinstalled fenicsx with sudo apt install fenicsx as before (something like 83 pacakges). This has left me with the following fenics related packages:

dpkg -l | grep fenics
ii  fenicsx                                        2:0.9.0.1~ppa1~noble1                    all          Automated Solution of Differential Equations

dpkg -l | grep basix 
ii  basix-doc                                        0.9.0-2~ppa1~noble1                      all          Finite Element Basis Function Definition Runtime Library (docs)
ii  libbasix-dev:amd64                               0.9.0-2~ppa1~noble1                      amd64        Finite Element Basis Function Definition Runtime Library (development headers)
ii  libbasix0.9:amd64                                0.9.0-2~ppa1~noble1                      amd64        Finite Element Basis Function Definition Runtime Library (Python 3)
ii  python3-basix                                    0.9.0-2~ppa1~noble1                      amd64        Finite Element Basis Function Definition Runtime Library (Python 3)

dpkg -l | grep ufl  
ii  python-ufl-doc                                   2024.2.0-2~ppa1~noble1                   all          documentation and demos for UFL
ii  python3-ufl                                      2024.2.0-2~ppa1~noble1                   all          unified language for form-compilers (Python 3)

dpkg -l | grep ffcx
ii  python3-ffcx                                     1:0.9.0-2~ppa1~noble1                    all          next-gen compiler for finite element variational forms (Python 3)

dpkg -l | grep dolfinx
ii  dolfinx-doc                                      1:0.9.0-7~ppa1~noble3                    all          Documentation and demo programs for DOLFIN
ii  libdolfinx-dev:amd64                             1:0.9.0-7~ppa1~noble3                    amd64        Shared links and header files for DOLFIN
ii  libdolfinx-real-dev:amd64                        1:0.9.0-7~ppa1~noble3                    amd64        Shared links and header files for DOLFIN (real numbers)
ii  libdolfinx-real0.9:amd64                         1:0.9.0-7~ppa1~noble3                    amd64        Shared libraries for DOLFIN
ii  python3-dolfinx:amd64                            1:0.9.0-7~ppa1~noble3                    amd64        Python interface for DOLFIN (Python 3)
ii  python3-dolfinx-real                             1:0.9.0-7~ppa1~noble3                    amd64        Python interface for DOLFIN (Python 3)

The command pip list shows no fenics related packages.

Is this the expected arrangement?

I am just not sure what to do next or how to invoke fenics and/or dolfinx?

Thanks again,

Peter.

what happens if you run python3 -c 'import dolfinx; print(dolfinx.__file__)'?

As you can see:

you have the python interface of DOLFINx installed.
Now it should be possible to just call something along the lines of python3 -c "import dolfinx" to check that the package has been installed.

Thanks Dokken,

Yes you are right. I finally managed to work out that I can use this installation of fenicsx provided that I use the system wide install of python3. Unfortunately, recent versions of python encourage the use of user-specific environments (which I don’t like) and I cannot figure out how to merge fenicsx into my python environment. Even more unfortunately, some packages come in different versions depending on whether they are installed under apt or pip (eg for petsc apt installs version 3.19 whereas pip installs version 3.22). I don’t know what all this means in the bigger picture.

If you have any further insights, that would be great. Thank you so much for your help so far.

Regards,

Peter.

This is why we provide several other solutions for installation, alongside apt:

  • conda: probably the way that is closest to a Python venv
  • spack: alternative to conda, mainly used on HPC systems
  • docker: images that contain prebuilt fenics installations
  • Src-build: it is more work, as one has to install the dependencies. We refer to: dolfinx/docker/Dockerfile.test-env at main · FEniCS/dolfinx · GitHub for how to get all dependencies on Ubuntu

Thanks for all your input.

Peter.