meshmode icon indicating copy to clipboard operation
meshmode copied to clipboard

DOF tagging

Open nchristensen opened this issue 4 years ago • 8 comments

Needs https://github.com/inducer/loopy/pull/156

  • [ ] point requirements.txt at master for loopy, pytools, and firedrake ci

nchristensen avatar Nov 10 '20 08:11 nchristensen

Odd, it cannot find mpi4py or firedrake. Any ideas what is wrong here @inducer?

SKIPPED [1] test_firedrake_interop.py:52: could not import 'firedrake': No module named 'firedrake'
SKIPPED [2] test_chained.py:114: implementation detail
SKIPPED [2] test_chained.py:143: implementation detail
SKIPPED [4] test_partition.py:514: could not import 'mpi4py': No module named 'mpi4py'

nchristensen avatar Nov 16 '20 19:11 nchristensen

Those are not the failures it's complaining about, though.

inducer avatar Nov 16 '20 20:11 inducer

@inducer, currently the context factory only works with a PyOpenCLArrayContext which is a problem in Grudge because Grudge needs a GrudgeArrayContext. Should the context factory be modified to accept a context type as an argument or do we expect every array context subclass to have its own version of this? https://github.com/nchristensen/meshmode/blob/1849c35a2d2fadf04da05ed71937e839930e9d87/meshmode/array_context.py#L604

nchristensen avatar Jan 02 '21 00:01 nchristensen

currently the context factory only works with a PyOpenCLArrayContext

What's a context factory? Sorry if I'm being dense.

inducer avatar Jan 02 '21 05:01 inducer

What's a context factory? Sorry if I'm being dense.

Sorry, I should have been more clear. It is the ArrayContextFactory defined in this chunk of code. The difficulty is PyOpenCLArrayContext is currently hardcoded into the class. When Grudge calls this function in the tests it this means a PyOpenCLArrayContext is created instead of a GrudgeArrayContext.

def pytest_generate_tests_for_pyopencl_array_context(metafunc):
    """Parametrize tests for pytest to use a :mod:`pyopencl` array context.
    Performs device enumeration analogously to
    :func:`pyopencl.tools.pytest_generate_tests_for_pyopencl`.
    Using the line:
    .. code-block:: python
       from meshmode.array_context import pytest_generate_tests_for_pyopencl \
            as pytest_generate_tests
    in your pytest test scripts allows you to use the arguments ctx_factory,
    device, or platform in your test functions, and they will automatically be
    run for each OpenCL device/platform in the system, as appropriate.
    It also allows you to specify the ``PYOPENCL_TEST`` environment variable
    for device selection.
    """

    import pyopencl as cl
    from pyopencl.tools import _ContextFactory

    class ArrayContextFactory(_ContextFactory):
        def __call__(self):
            ctx = super().__call__()
            return PyOpenCLArrayContext(cl.CommandQueue(ctx))

        def __str__(self):
            return ("<array context factory for <pyopencl.Device '%s' on '%s'>" %
                    (self.device.name.strip(),
                     self.device.platform.name.strip()))

    import pyopencl.tools as cl_tools
    arg_names = cl_tools.get_pyopencl_fixture_arg_names(
            metafunc, extra_arg_names=["actx_factory"])

    if not arg_names:
        return

    arg_values, ids = cl_tools.get_pyopencl_fixture_arg_values()
    if "actx_factory" in arg_names:
        if "ctx_factory" in arg_names or "ctx_getter" in arg_names:
            raise RuntimeError("Cannot use both an 'actx_factory' and a "
                    "'ctx_factory' / 'ctx_getter' as arguments.")

        for arg_dict in arg_values:
            arg_dict["actx_factory"] = ArrayContextFactory(arg_dict["device"])

    arg_values = [
            tuple(arg_dict[name] for name in arg_names)
            for arg_dict in arg_values
            ]

    metafunc.parametrize(arg_names, arg_values, ids=ids)

nchristensen avatar Jan 02 '21 07:01 nchristensen

We could potentially parametrize that, like so:

from functools import partial

def pytest_generate_tests_for_cl_array_context(context_from_cl_device, metafunc):

pytest_generate_tests_for_pyopencl_array_context = partial(pytest_generate_tests_for_cl_array_context, ArrayContextFactory)

Also, there's no need to copy-paste whole chunks of code. Github lets you link to code chunks at specific versions pretty easily. (I'll show you how next meeting.)

inducer avatar Jan 03 '21 01:01 inducer

pytest_generate_tests_for_pyopencl_array_context = partial(pytest_generate_tests_for_cl_array_context, ArrayContextFactory)

partial seems to interfere with pytest.

 from meshmode.array_context import (  # noqa
          pytest_generate_tests_for_pyopencl_array_context
          as pytest_generate_tests)
  from meshmode.array_context import PyOpenCLArrayContext
  from functools import partial
  pytest_generate_tests = partial(pytest_generate_tests, PyOpenCLArrayContext)

fails with

E   TypeError: pytest_generate_tests_for_pyopencl_array_context() missing 1 required positional argument: 'metafunc'

I see Metafunc.config gives access to the configuration values. Could the context be passed through there? https://docs.pytest.org/en/stable/reference.html?highlight=config#pytest.python.Metafunc.config

nchristensen avatar Jan 04 '21 05:01 nchristensen

@inducer Could you approve the workflows here?

nchristensen avatar Jan 30 '22 22:01 nchristensen