Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message: UFLException: Expecting a FunctionSpace or FiniteElement. #23

Open
andreerhardt opened this issue Apr 25, 2024 · 6 comments

Comments

@andreerhardt
Copy link

Dear Cécile, dear Henrik,

I am very interested in using fenics-beat. I have already experience with cbc-beat, but an older version by Marie, later launched by you both on github, is running on my M1. Now, I would like to use fenics-beat, but unfortunately, I get an error message when running the monodomain examples. I think something went wrong during the installation. However, I can't find the error.

I am using an iMac M1 with Anaconda and have installed FEniCS and fenics-beat as follows:
################################
conda create -n fenicsenv python=3.11
conda activate fenicsenv
conda install -c conda-forge spyder
conda install -c conda-forge fenics
conda install -c conda-forge matplotlib

conda install conda-forge::pytest
conda install conda-forge::h5py
conda install conda-forge::fenics-ufl-legacy

python3 -m pip install fenics-beat
python3 -m pip install cardiac-geometries
python3 -m pip install gotranx

pip install ldrb
################################

The error message is the following:

Expecting a FunctionSpace or FiniteElement.
Traceback (most recent call last):

File /opt/anaconda3/envs/fenicsenv/lib/python3.11/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)

File ~/Documents/Computational Physiology Python/fenics-beat-main/demos/endocardial_stimulation.py:328
main()

File ~/Documents/Computational Physiology Python/fenics-beat-main/demos/endocardial_stimulation.py:227 in main
arr = beat.utils.expand_layer(

File /opt/anaconda3/envs/fenicsenv/lib/python3.11/site-packages/beat/utils.py:57 in expand_layer
u = ufl.TrialFunction(V)

File /opt/anaconda3/envs/fenicsenv/lib/python3.11/site-packages/ufl_legacy/argument.py:157 in TrialFunction
return Argument(function_space, 1, part)

File /opt/anaconda3/envs/fenicsenv/lib/python3.11/site-packages/ufl_legacy/argument.py:51 in init
error("Expecting a FunctionSpace or FiniteElement.")

File /opt/anaconda3/envs/fenicsenv/lib/python3.11/site-packages/ufl_legacy/log.py:158 in error
raise self._exception_type(self._format_raw(*message))

UFLException: Expecting a FunctionSpace or FiniteElement.

Do you have any idea what I did wrong? I have the impression it might be related with ufl_legacy or its installation. The cbc-beat version 2019.1.2 (28.02.2022) which is running does not use ufl_legacy and with python 3.9. For fenics-beat the conda environment has the FEniCS version 2019.1.0, ufl_legacy (2022.3.0) and python 3.11.

Best,

André

@finsberg
Copy link
Owner

Hi André
I am very happy to hear that you think this project is interesting. My hope is that it can be a good replacement for cbcbeat, and I also plan to develop a FEniCSx version it, which will have more or less the same design.

Regarding your issue, I think the problem might be that the version of FEniCS you are using does not use ufl-legacy, which was introduced not so long ago (https://fenicsproject.discourse.group/t/announcement-ufl-legacy-and-legacy-dolfin/11583) but which is currently only used for the development version of legacy FEniCS. I think you might resolve the issue if you just skip installing ufl-legacy.

On that note, I would also like to mention that we maintain docker images with the development version of FEniCS here: https://github.com/scientificcomputing/packages/pkgs/container/fenics
as well as one package with also contains gmsh here:
https://github.com/scientificcomputing/packages/pkgs/container/fenics-gmsh
These images are also built for ARM, so they should work on you M1 mac as well. This is the way I usually run FEniCS locally.

@andreerhardt
Copy link
Author

Hi Henrik,

thank you very much for your reply and suggestions. I tried it without ufl_legacy, however fenics-beat requires ufl_legacy and gives me an error without installing it.

The first issue was that I usually use python 3.9 since it is included in Xcode. I got the message:

TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Therefore, I created a new environment with python 3.11, python 3.10 is at least required, but python 3.12 yields an error with ldrb. Then, the error that ufl_legacy is not known/installed appeared. That was the reason why in installed everything in the qay I mentioned above.

But, I see I may have to go with docker images, which I use on my MacBook Pro M3 :-) I will try to get fenics-beat running there :-)

Thank you very much. I am looking forward seeing fenicsx-beat in the future. As far as I can see, fenics-beat is writing already quite close to FEniCSx :-)

Many thanks again :-)

Best,

André

@finsberg
Copy link
Owner

I have made and update now (see #24) so I belive it should work both with ufl and ufl-legacy. I also fixed the type annotations so it should also work on python version 3.8 and above.

@andreerhardt
Copy link
Author

Great. Thank you very much! It works now with python 3.9 and ufl, but a new error appears, which seems to be within dolfin (2019.1.0):

File /opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/form.py:51 in init
function_spaces = [func.function_space()._cpp_object for func in form.arguments()]

File /opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/form.py:51 in
function_spaces = [func.function_space()._cpp_object for func in form.arguments()]

AttributeError: 'Argument' object has no attribute 'function_space'

Sorry to keep bothering you! I try to figure out what is going wrong here.

@finsberg
Copy link
Owner

Yes, I can reproduce the error here: https://github.com/finsberg/fenics-beat/actions/runs/8846006693/job/24291024007. Not really sure why it happens, but it seems to not be a problem if you use the docker image.

@andreerhardt
Copy link
Author

Many thanks, then I will try the docker image :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants