FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
731 stars 177 forks source link

Tons of ufl warnings using basix.ufl.element #2773

Closed jorgensd closed 11 months ago

jorgensd commented 12 months ago

How to reproduce the bug

Using a mixed element created with basix creates a stack of warnings

Minimal Example (Python)

import dolfinx
import basix.ufl
from mpi4py import MPI

def test():
    N = 4
    mesh = dolfinx.mesh.create_unit_square(
        MPI.COMM_WORLD, N, N)

    cellname = mesh.ufl_cell().cellname()
    Ve = basix.ufl.element(basix.ElementFamily.P, cellname, 2, shape=(mesh.geometry.dim,))
    Qe = basix.ufl.element(basix.ElementFamily.P, cellname, 1)

    W = dolfinx.fem.functionspace(mesh, Ve * Qe)

Output (Python)

root@de6570103be1:~/shared# python3 -m pytest mixed_warning.py 
============================================================================== test session starts ==============================================================================
platform linux -- Python 3.10.6, pytest-7.4.0, pluggy-1.2.0
rootdir: /root/shared
plugins: xdist-3.3.1
collected 1 item                                                                                                                                                                

mixed_warning.py .                                                                                                                                                        [100%]

=============================================================================== warnings summary ================================================================================
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
../../usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54
  /usr/local/lib/python3.10/dist-packages/ufl/core/ufl_type.py:54: DeprecationWarning: attach_operators_from_hash_data deprecated, please use UFLObject instead.
    warnings.warn("attach_operators_from_hash_data deprecated, please use UFLObject instead.", DeprecationWarning)

mixed_warning.py::test
mixed_warning.py::test
mixed_warning.py::test
  /usr/local/lib/python3.10/dist-packages/ffcx/element_interface.py:23: DeprecationWarning: Use of elements created by UFL is deprecated. You should create elements directly using Basix.
    warnings.warn(

mixed_warning.py::test
mixed_warning.py::test
mixed_warning.py::test
  /usr/local/lib/python3.10/dist-packages/ffcx/element_interface.py:26: DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead
    return basix.ufl.convert_ufl_element(element)

mixed_warning.py::test
mixed_warning.py::test
mixed_warning.py::test
mixed_warning.py::test
mixed_warning.py::test
mixed_warning.py::test
  /usr/local/lib/python3.10/dist-packages/basix/ufl.py:1961: DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead
    return _MixedElement([convert_ufl_element(e) for e in ufl_element.sub_elements()])

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================== 1 passed, 20 warnings in 0.41s =========================================================================

Version

main branch

DOLFINx git commit

ee86abd93f957ce1a899fd8ec2c5a2f40b34301f

Installation

Using the nightly docker images (also verified when building from source).

Additional information

No response

mscroggs commented 12 months ago

Replacing Ve * Qe with basix.ufl.mixed_element([Ve, Qe]) will get rid of most of these warnings. For the others, I'm working on changes in UFL to get rid of them.

garth-wells commented 11 months ago

@mscroggs can we close this now?

mscroggs commented 11 months ago

I think these warnings are all gone now. @jorgensd can you check and close this if so?

jorgensd commented 11 months ago

Adapted test passes with:

import dolfinx
import basix.ufl
from mpi4py import MPI

def test():
    N = 4
    mesh = dolfinx.mesh.create_unit_square(
        MPI.COMM_WORLD, N, N)
    print(dolfinx.common.git_commit_hash)
    cellname = mesh.ufl_cell().cellname()
    Ve = basix.ufl.element(basix.ElementFamily.P, cellname, 2, shape=(mesh.geometry.dim,))
    Qe = basix.ufl.element(basix.ElementFamily.P, cellname, 1)

    W = dolfinx.fem.functionspace(mesh, basix.ufl.mixed_element([Ve, Qe]))

yielding:

root@xxyyzz:~/shared# python3 -m pytest -xsv test_112.py -W error
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.2, pluggy-1.3.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /root/shared
plugins: xdist-3.3.1
collected 1 item                                                               

test.py::test fed77865d61895ba1c5ddaaa843cb1c3e90686a7
PASSED
RemDelaporteMathurin commented 8 months ago

Hi all, I still receive tons of ufl warnings even when using basix.ufl.mixed_element

I ran the code @jorgensd posted and obtained:

$ python3 -m pytest -xsv mwe.py
=============================================================================== test session starts ===============================================================================
platform linux -- Python 3.12.1, pytest-7.4.4, pluggy-1.3.0 -- /opt/conda/envs/fenicsx/bin/python3
cachedir: .pytest_cache
rootdir: /workspaces/FESTIM
collected 1 item                                                                                                                                                                  

mwe.py::test 4604094c8c3e6dbf6034b25df5ee3ccd1ec2d3b3
PASSED

================================================================================ warnings summary =================================================================================
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
  /opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56: DeprecationWarning: attach_operators_from_hash_data deprecated, please use UFLObject instead.
    warnings.warn("attach_operators_from_hash_data deprecated, please use UFLObject instead.", DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================== 1 passed, 8 warnings in 0.51s ==========================================================================
jorgensd commented 8 months ago

Hi all, I still receive tons of ufl warnings even when using basix.ufl.mixed_element

I ran the code @jorgensd posted and obtained:

$ python3 -m pytest -xsv mwe.py
=============================================================================== test session starts ===============================================================================
platform linux -- Python 3.12.1, pytest-7.4.4, pluggy-1.3.0 -- /opt/conda/envs/fenicsx/bin/python3
cachedir: .pytest_cache
rootdir: /workspaces/FESTIM
collected 1 item                                                                                                                                                                  

mwe.py::test 4604094c8c3e6dbf6034b25df5ee3ccd1ec2d3b3
PASSED

================================================================================ warnings summary =================================================================================
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
../../opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56
  /opt/conda/envs/fenicsx/lib/python3.12/site-packages/ufl/core/ufl_type.py:56: DeprecationWarning: attach_operators_from_hash_data deprecated, please use UFLObject instead.
    warnings.warn("attach_operators_from_hash_data deprecated, please use UFLObject instead.", DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================== 1 passed, 8 warnings in 0.51s ==========================================================================

It doesn't seem like you have an up to date image of dolfinx, as the test refers to

mwe.py::test 4604094c8c3e6dbf6034b25df5ee3ccd1ec2d3b3

which is a commit from october: https://github.com/FEniCS/dolfinx/commit/fed77865d61895ba1c5ddaaa843cb1c3e90686a7

RemDelaporteMathurin commented 8 months ago

It doesn't seem like you have an up to date image of dolfinx, as the test refers to

I installed it with conda conda install -c conda-forge fenics-dolfinx mpich pyvista

I've recently been trying to reduce the number of warnings: https://github.com/festim-dev/FESTIM/pull/683 and noticed that the changes introduced by this commit haven't been released yet.

Should the conda environment use the dev version of ufl?

RemDelaporteMathurin commented 8 months ago

I checked and confirm I'm using dolfinx 0.7.2 but the release notes of 0.7.3 state there's no need to upgrade

jorgensd commented 8 months ago

I checked and confirm I'm using dolfinx 0.7.2 but the release notes of 0.7.3 state there's no need to upgrade

Ah, sorry, I took the wrong git hash. It is correct that you are using a newer version: https://github.com/conda-forge/fenics-dolfinx-feedstock/commit/4604094c8c3e6dbf6034b25df5ee3ccd1ec2d3b3 The "error"/"warning" is present in ghcr.io/fenics/dolfinx/dolfinx:v0.7.2 and ghcr.io/fenics/dolfinx/dolfinx:v0.7.3 but does not exist on nightly. There I get a rather strange warning: with python3 -m pytest -xvs mwe_1.py -Wd

import dolfinx
import basix.ufl
from mpi4py import MPI

def test():
    N = 4
    mesh = dolfinx.mesh.create_unit_square(
        MPI.COMM_WORLD, N, N)
    cellname = mesh.ufl_cell().cellname()
    Ve = basix.ufl.element(basix.ElementFamily.P, cellname,
                           2, shape=(mesh.geometry.dim,))
    Qe = basix.ufl.element(basix.ElementFamily.P, cellname, 1)

    W = dolfinx.fem.functionspace(mesh, basix.ufl.mixed_element([Ve, Qe]))
mwe_1.py::test
  /usr/local/lib/python3.10/dist-packages/ffcx/codegeneration/jit.py:69: ResourceWarning: unclosed file <_io.TextIOWrapper name='/root/.cache/fenics/libffcx_elements_1f01ab63c5abaab6255c0fdd2e80237ed970cf33.c' mode='x' encoding='UTF-8'>
    open(c_filename, "x")
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
jorgensd commented 8 months ago

@RemDelaporteMathurin The last strange error message has been resolved in https://github.com/FEniCS/ffcx/pull/654