meshmode
meshmode copied to clipboard
DOF tagging
Needs https://github.com/inducer/loopy/pull/156
- [ ] point requirements.txt at master for loopy, pytools, and firedrake ci
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'
Those are not the failures it's complaining about, though.
@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
currently the context factory only works with a PyOpenCLArrayContext
What's a context factory? Sorry if I'm being dense.
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)
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.)
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
@inducer Could you approve the workflows here?