Can't define Expression through c++; returns fatal error: ufc.h: No such file or directory

Hi,
I’m trying to define this simple expression:

import fenics
ccode = "x[0] < 64 ? 1 : 0"
expression = fenics.Expression(ccode, degree=1)

But I get this error:

------------------- Start compiler output ------------------------
In file included from /tmp/tmpv9qss5eb/dolfin_expression_daaaa038f9fbf86571aa796b263f0180.cpp:13:
/usr/local/include/dolfin/function/Expression.h:25:10: fatal error: ufc.h: No such file or directory
   25 | #include <ufc.h>
      |          ^~~~~~~
compilation terminated.

-------------------  End compiler output  ------------------------

It looks like it misses a header file, but it’s weird because I defined Expressions in this way many times already and I never had issues. Might this be due to a recent software update?
Thank you in advance.

I cannot reproduce using a docker container:

docker run -ti -v $(pwd):/root/shared -w /root/shared --rm quay.io/fenicsproject/dev

It seems that dolfin didn’t find ffc correctly. How did you install it?

2 Likes

Dear Igor,
Thank you for your time.
I installed FEniCS thorugh apt-get following the procedure on the FEniCS project page, so I did:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt-get update
sudo apt-get install --no-install-recommends fenics

And it used to work perfectly, at least a couple of weeks ago. Don’t know what is happening now.

Could you try to reinstall the fenics package?
Also what linux distribution are you using?
Maybe @dparsons has any ideas of what is going on.

@fpradelli , your error message refers to /usr/local/include/dolfin/, which is a local installation, not the installation provided through apt.

1 Like

Dear dokken and dparsons,
Thank you for your time. I will answer you in the following:

My Linux distribution is Ubuntu Mate 20.04.
I tried to repeat the procedure but it didn’t fix the problem. Actually, what I get is that FEniCS is up to date:

$ sudo apt-get install software-properties-common
...
$ sudo add-apt-repository ppa:fenics-packages/fenics
...
$ sudo apt-get update
...
$ sudo apt-get install --no-install-recommends fenics
Reading package lists... Done
Building dependency tree       
Reading state information... Done
fenics is already the newest version (1:2019.2.0.5~ppa1~focal1).
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.

However, I have to say that I’m not an experienced Linux user so I might have done something wrong. For instance, should I uninstall FEniCS before repating the procedure as I did?

Actually I am pretty sure of having used the apt installation. However, I remember that I played a bit with PipEnv once on this machine and I tried to create a virtual environment for FEniCS (unsuccessfully) and to do so I partially followed the instruction given to build the software from source. Maybe this is why I have a local installation too?

That’s probably it. Try uninstalling your pipenv (I’m not sure if pip3 uninstall dolfin will do it or not). If necessary you could delete manually (rm -r /usr/local/include/dolfin/) , but then you would want to take care that you removed all the locally installed bits (e.g. under /usr/local/lib, and other subdirectories). Of course wiping the filesystem and reinstalling Ubuntu would also clear it up.

Dear @dparsons ,
I tried to remove all the files related to FEniCS in the usr/local folder but, unfortunately, the problem persists.
At least, in the error message now the folder changed from usr/local/include/dolfin/ to /usr/include/dolfin :

------------------- Start compiler output ------------------------
In file included from /tmp/tmpatp8ubfw/dolfin_expression_e8cadffda6c83113f8e006b97f0c13b5.cpp:13:
/usr/include/dolfin/function/Expression.h:25:10: fatal error: ufc.h: No such file or directory
   25 | #include <ufc.h>
      |          ^~~~~~~
compilation terminated.

-------------------  End compiler output  ------------------------

Do you have maybe another idea?

Can your report your installed versions,

dpkg -l *ffc* *dolfin* | cat

Report also the path provided by

python3 -c "import ffc; print(ffc.get_include_path())"

and confirm the contents of that path,

ls -l `python3 -c "import ffc; print(ffc.get_include_path())"`/ufc.h
1 Like

Here’s what I get from dpkg -l *ffc* *dolfin* | cat:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                  Version                                    Architecture Description
+++-=====================-==========================================-============-========================================================
ii  dolfin-bin            2019.2.0~git20201207.b495043-4~ppa1~focal5 all          Executable scripts for DOLFIN
ii  dolfin-doc            2019.2.0~git20201207.b495043-4~ppa1~focal5 all          Documentation and demo programs for DOLFIN
ii  libdolfin-dev:amd64   2019.2.0~git20201207.b495043-4~ppa1~focal5 amd64        Shared links and development files for DOLFIN
ii  libdolfin-dev-common  2019.2.0~git20201207.b495043-4~ppa1~focal5 all          Common header files for DOLFIN
un  libdolfin0-dev        <none>                                     <none>       (no description available)
un  libdolfin1.0-dev      <none>                                     <none>       (no description available)
un  libdolfin1.1-dev      <none>                                     <none>       (no description available)
un  libdolfin1.2-dev      <none>                                     <none>       (no description available)
un  libdolfin1.3-dev      <none>                                     <none>       (no description available)
un  libdolfin1.4-dev      <none>                                     <none>       (no description available)
ii  libdolfin2019.2:amd64 2019.2.0~git20201207.b495043-4~ppa1~focal5 amd64        Shared libraries for DOLFIN
un  python-ffc            <none>                                     <none>       (no description available)
ii  python3-dolfin        2019.2.0~git20201207.b495043-4~ppa1~focal5 amd64        Base Python interface for DOLFIN (Python 3)
ii  python3-dolfin-real   2019.2.0~git20201207.b495043-4~ppa1~focal5 amd64        Python interface for DOLFIN
un  python3-dolfin64-real <none>                                     <none>       (no description available)
ii  python3-ffc           2019.2.0~git20210115.cb26c91-1~ppa1~focal2 all          compiler for finite element variational forms (Python 3)
un  troffcvt              <none>                                     <none>       (no description available)

Here’s what I get from python3 -c "import ffc; print(ffc.get_include_path())":

/usr/lib/python3/dist-packages/ffc/backends/ufc

And here’s what I get from ls -l `python3 -c "import ffc; print(ffc.get_include_path())"`/ufc.h:

-rw-r--r-- 1 root root 37152 gen 25 16:02 /usr/lib/python3/dist-packages/ffc/backends/ufc/ufc.h

It looks like your packages are properly installed. It must be some other interference from your local installation.

What do you get from

python3 -c "import fenics; print(fenics.__path__)"
python3 -c "import dolfin; print(dolfin.__path__)"
python3 -c "import ffc; print(ffc.__path__)"
ls -ld /usr/lib/petsc
ls -ld /etc/alternatives/petsc
1 Like

Here’s what i get:

$ python3 -c "import fenics; print(fenics.__path__)"
['/usr/lib/python3/dist-packages/fenics']

$ python3 -c "import dolfin; print(dolfin.__path__)"
['/usr/lib/petsc/lib/python3/dist-packages/dolfin']

$ python3 -c "import ffc; print(ffc.__path__)"
['/usr/lib/python3/dist-packages/ffc']

$ ls -ld /usr/lib/petsc
lrwxrwxrwx 1 root root 23 feb  4 17:17 /usr/lib/petsc -> /etc/alternatives/petsc

$ ls -ld /etc/alternatives/petsc
lrwxrwxrwx 1 root root 49 feb  4 17:17 /etc/alternatives/petsc -> /usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real

No obvious problems there.

What is the output of

python3 -c "import fenics; ccode = 'x[0] < 64 ? 1 : 0'; expression = fenics.Expression(ccode, degree=1); print(expression)"

Unfortunately, I still get the error I already reported. I provide all the error text this time, maybe can be helpful:

$ python3 -c "import fenics; ccode = 'x[0] < 64 ? 1 : 0'; expression = fenics.Expression(ccode, degree=1); print(expression)"
------------------- Start compiler output ------------------------
In file included from /tmp/tmpb30qm3pe/dolfin_expression_daaaa038f9fbf86571aa796b263f0180.cpp:13:
/usr/include/dolfin/function/Expression.h:25:10: fatal error: ufc.h: No such file or directory
   25 | #include <ufc.h>
      |          ^~~~~~~
compilation terminated.

-------------------  End compiler output  ------------------------
Compilation failed! Sources, command, and errors have been written to: /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180
Traceback (most recent call last):
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 168, in compile_class
    module, signature = dijitso_jit(cpp_data, module_name, params,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 50, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 106, in dijitso_jit
    return dijitso.jit(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/dijitso/jit.py", line 216, in jit
    raise DijitsoError("Dijitso JIT compilation failed, see '%s' for details"
dijitso.jit.DijitsoError: Dijitso JIT compilation failed, see '/home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180' for details

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/expression.py", line 400, in __init__
    self._cpp_object = jit.compile_expression(cpp_code, params)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/jit.py", line 158, in compile_expression
    expression = compile_class(cpp_data, mpi_comm=mpi_comm)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 173, in compile_class
    raise RuntimeError("Unable to compile C++ code with dijitso")
RuntimeError: Unable to compile C++ code with dijitso

But that’s a different error. No reference to ufc.h.
(unless there is more detail in /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180)

Possibly it’s the cache. Double check the version dpkg -l *dijitso* | cat (it’s probably fine), then dijitso clean (or rm -r ~/.cache/dijitso/ if you want to be drastic).

1 Like

Are you sure? It looks the same to me. Both in here and in here the complier complains for ufc.h. Maybe there’s something else I didn’t notice?


I checked and unfortunately it is not (If I did everything properly). The output for dpkg -l *dijitso* | cat is the folowing (I guess it’s fine):

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name               Version                                    Architecture Description
+++-==================-==========================================-============-================================================================
un  python-dijitso     <none>                                     <none>       (no description available)
un  python-dijitso-doc <none>                                     <none>       (no description available)
ii  python3-dijitso    2019.2.0~git20190418.c92dcb0-2~ppa1~focal1 all          distributed just-in-time building of shared libraries (Python 3)

Then I ran both dijitso clean and rm -r ~/.cache/dijitso/ and re-tried. I still get the same error:

$ python3 -c "import fenics; ccode = 'x[0] < 64 ? 1 : 0'; expression = fenics.Expression(ccode, degree=1); print(expression)"
Moving new file over differing existing file:
src: /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180/error.log.340b7bbb37384917a3859fa877b91c1a
dst: /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180/error.log
backup: /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180/error.log.old
Backup file exists, overwriting.
------------------- Start compiler output ------------------------
In file included from /tmp/tmpba9yag3m/dolfin_expression_daaaa038f9fbf86571aa796b263f0180.cpp:13:
/usr/include/dolfin/function/Expression.h:25:10: fatal error: ufc.h: No such file or directory
   25 | #include <ufc.h>
      |          ^~~~~~~
compilation terminated.

-------------------  End compiler output  ------------------------
Compilation failed! Sources, command, and errors have been written to: /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180
Traceback (most recent call last):
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 168, in compile_class
    module, signature = dijitso_jit(cpp_data, module_name, params,
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 50, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 106, in dijitso_jit
    return dijitso.jit(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/dijitso/jit.py", line 216, in jit
    raise DijitsoError("Dijitso JIT compilation failed, see '%s' for details"
dijitso.jit.DijitsoError: Dijitso JIT compilation failed, see '/home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180' for details

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/expression.py", line 400, in __init__
    self._cpp_object = jit.compile_expression(cpp_code, params)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/jit.py", line 158, in compile_expression
    expression = compile_class(cpp_data, mpi_comm=mpi_comm)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 173, in compile_class
    raise RuntimeError("Unable to compile C++ code with dijitso")
RuntimeError: Unable to compile C++ code with dijitso

You are right, the scroll bar was hiding the ufc.h reference from me. Does the dijitso error log file give any clues?

It’s behaving as if the local installation has affected the system configuration, altering paths in way which persists even after you removed the files from /usr/local. An Ubuntu reinstallation might be the surest way to fix it.

Before going to that extreme, run a full update (dist-upgrade, not upgrade), and reboot after the upgrade (sometimes the Microsoft methods work for Linux)

sudo apt-get update
sudo apt-get dist-upgrade

Don’t worry at all, I just wanted to be sure I was not missing something.

Unfortunately, it does not. Just the same complaint about ufc.h. For the sake of completeness, I report here the content of error.log:

In file included from /tmp/tmpba9yag3m/dolfin_expression_daaaa038f9fbf86571aa796b263f0180.cpp:13:
/usr/include/dolfin/function/Expression.h:25:10: fatal error: ufc.h: No such file or directory
   25 | #include <ufc.h>
      |          ^~~~~~~
compilation terminated.

I hope I do not have to reinstall Ubuntu :dizzy_face:
I try with apt-get and I tell you how it worked out.

Unfortunately, it didn’t work out. I guess I have to reinstall Ubuntu.

Just one last question: I noticed that my PATH includes the local folder (or at least usr/local/bin and user/local/sbin). Do you think removing them from the path might be a solution?

It shouldn’t hurt to try removing the local elements from your path (might want to add them back after testing) but I don’t think it will help.

The problem seems to be in the include path for ufc.h rather than the executable. At the point of C++ compilation the path should be provided via ffc.get_include_path(), resulting in c++ -I/usr/lib/python3/dist-packages/ffc/backends/ufc

Are you sure there is not more information in the dijitso log files? Did you give the entire contents of /home/francop/PycharmProjects/castro-fenics/jitfailure-dolfin_expression_daaaa038f9fbf86571aa796b263f0180 and related log files? Is there nothing in ~/.cache/dijitso/log/ ?

Can you confirm there are no python modules locally installed in ~/.local/lib/python3*/site-packages/ ?

1 Like