Skip to content

test_xdmf.py::test_xdmf_function fails with complex numbers #22

@drew-parsons

Description

@drew-parsons

test_xdmf_function in test_xdmf.py fails with dolfinx built with complex numbers

$ PETSC_DIR=/usr/lib/petscdir/petsc-complex pytest-3 -v test_xdmf.py 
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.13.12, pytest-9.0.2, pluggy-1.6.0 -- /usr/bin/python3
cachedir: .pytest_cache
Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>
benchmark: 5.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
hypothesis profile 'default'
rootdir: /projects/fenics/build/io4dolfinx
configfile: pyproject.toml
plugins: rerunfailures-16.1, remotedata-0.4.1, anyio-4.11.0, cov-5.0.0, arraydiff-0.6.1, xdist-3.8.0, mock-3.15.1, filter-subpackage-0.2.0, timeout-2.4.0, typeguard-4.4.4, xvfb-3.0.0, astropy-0.11.0, random-order-0.0.0, openfiles-0.6.0, flaky-3.8.1, benchmark-5.2.3, mpi-0.6, asyncio-1.3.0, astropy-header-0.2.2, hypothesis-6.151.5, doctestplus-1.7.1
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 2 items                                                                                                                                                                                                 

test_xdmf.py::test_xdmf_mesh PASSED                                                                                                                                                                         [ 50%]
test_xdmf.py::test_xdmf_function FAILED                                                                                                                                                                     [100%]

==================================================================================================== FAILURES =====================================================================================================
_______________________________________________________________________________________________ test_xdmf_function ________________________________________________________________________________________________

tmp_path = PosixPath('/tmp/pytest-of-me/pytest-40/test_xdmf_function0')

    def test_xdmf_function(tmp_path):
        tmp_path = MPI.COMM_WORLD.bcast(tmp_path, root=0)
        mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 8, 10)
    
        def f(x):
            return (x[0], x[1], -2 * x[1], 3 * x[0])
    
        V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1, (4,)))
        u = dolfinx.fem.Function(V, name="u")
        u.interpolate(f)
    
        tmp_file = tmp_path / "function.xdmf"
        with dolfinx.io.XDMFFile(MPI.COMM_WORLD, tmp_file, "w") as xdmf:
            xdmf.write_mesh(mesh)
            xdmf.write_function(u)
    
        MPI.COMM_WORLD.barrier()
    
        in_grid = io4dolfinx.read_mesh(tmp_file, MPI.COMM_WORLD, backend="xdmf")
        names = io4dolfinx.read_function_names(
            tmp_file, MPI.COMM_WORLD, backend_args={}, backend="xdmf"
        )
        assert len(names) == 1
        assert names[0] == "u"
    
>       u = io4dolfinx.read_point_data(tmp_file, "u", in_grid, backend="xdmf")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

test_xdmf.py:64: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/io4dolfinx/readers.py:402: in read_point_data
    dataset, local_range_start = backend_cls.read_point_data(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

filename = PosixPath('/tmp/pytest-of-me/pytest-40/test_xdmf_function0/function.xdmf'), name = 'u', comm = <mpi4py.MPI.Intracomm object at 0x7fb87a440540>, time = None, backend_args = {}

    def read_point_data(
        filename: Path | str,
        name: str,
        comm: MPI.Intracomm,
        time: float | str | None,
        backend_args: dict[str, Any] | None,
    ) -> tuple[np.ndarray, int]:
        """Read data from the nodes of a mesh.
    
        Args:
            filename: Path to file
            name: Name of point data
            comm: Communicator to launch IO on.
            time: The time stamp
            backend_args: The backend arguments
    
        Returns:
           Data local to process (contiguous, no mpi comm) and local start range
        """
        # Find function with name u in xml tree
        check_file_exists(filename)
        filename = Path(filename)
    
        tree = ElementTree.parse(filename)
        root = tree.getroot()
        backend_args = get_default_backend_args(backend_args)
        if time is not None:
            time_steps = root.findall(f".//Grid[@Name='{name}']")
            time_found = False
            for time_node in time_steps:
                step_node = time_node.find(".//Time")
                assert isinstance(step_node, ElementTree.Element)
                if step_node.attrib["Value"] == time:
                    time_found = True
                    break
            func_node = time_node.find(f".//Attribute[@Name='{name}']")
            if not time_found:
                raise RuntimeError(f"Function {name} at time={time} not found in {filename}")
        else:
            func_node = root.find(f".//Attribute[@Name='{name}']")
>       assert isinstance(func_node, ElementTree.Element)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       AssertionError

/usr/lib/python3/dist-packages/io4dolfinx/backends/xdmf/backend.py:134: AssertionError
============================================================================================= short test summary info =============================================================================================
FAILED test_xdmf.py::test_xdmf_function - AssertionError
=========================================================================================== 1 failed, 1 passed in 0.27s ===========================================================================================

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions