From 81ac2f849f0c34443fa19ddf11d4fe0db7fda8a5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 2 Jul 2020 20:33:10 -0500 Subject: [PATCH 1/4] Fix deprecated calls to pytools.obj_array functions --- sumpy/fmm.py | 4 ++-- sumpy/tools.py | 8 ++++---- sumpy/visualization.py | 40 ++++++++++++++-------------------------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/sumpy/fmm.py b/sumpy/fmm.py index a2331756..9458401c 100644 --- a/sumpy/fmm.py +++ b/sumpy/fmm.py @@ -320,13 +320,13 @@ class SumpyExpansionWrangler(object): return source_array.with_queue(self.queue)[self.tree.user_source_ids] def reorder_potentials(self, potentials): - from pytools.obj_array import is_obj_array, with_object_array_or_scalar + from pytools.obj_array import is_obj_array, obj_array_vectorize assert is_obj_array(potentials) def reorder(x): return x.with_queue(self.queue)[self.tree.sorted_target_ids] - return with_object_array_or_scalar(reorder, potentials) + return obj_array_vectorize(reorder, potentials) # }}} diff --git a/sumpy/tools.py b/sumpy/tools.py index 353ca9da..959e2d45 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -181,18 +181,18 @@ def build_matrix(op, dtype=None, shape=None): def vector_to_device(queue, vec): - from pytools.obj_array import with_object_array_or_scalar + from pytools.obj_array import obj_array_vectorize from pyopencl.array import to_device def to_dev(ary): return to_device(queue, ary) - return with_object_array_or_scalar(to_dev, vec) + return obj_array_vectorize(to_dev, vec) def vector_from_device(queue, vec): - from pytools.obj_array import with_object_array_or_scalar + from pytools.obj_array import obj_array_vectorize def from_dev(ary): from numbers import Number @@ -202,7 +202,7 @@ def vector_from_device(queue, vec): return ary.get(queue=queue) - return with_object_array_or_scalar(from_dev, vec) + return obj_array_vectorize(from_dev, vec) def _merge_kernel_arguments(dictionary, arg): diff --git a/sumpy/visualization.py b/sumpy/visualization.py index bf5f016b..d1eee517 100644 --- a/sumpy/visualization.py +++ b/sumpy/visualization.py @@ -33,34 +33,22 @@ from six.moves import range def separate_by_real_and_imag(data, real_only): + from pytools.obj_array import obj_array_real_copy, obj_array_imag_copy + for name, field in data: - from pytools.obj_array import log_shape - ls = log_shape(field) - - if ls != () and ls[0] > 1: - assert len(ls) == 1 - from pytools.obj_array import ( - oarray_real_copy, oarray_imag_copy, - with_object_array_or_scalar) - - if field[0].dtype.kind == "c": - if real_only: - yield (name, - with_object_array_or_scalar(oarray_real_copy, field)) - else: - yield (name+"_r", - with_object_array_or_scalar(oarray_real_copy, field)) - yield (name+"_i", - with_object_array_or_scalar(oarray_imag_copy, field)) - else: - yield (name, field) + try: + # Look inside object arrays to get the entry dtype. + entry_dtype = field[0].dtype + except AttributeError: + entry_dtype = field.dtype + + assert entry_dtype.kind != "O" + + if real_only or entry_dtype.kind != "c": + yield (name, obj_array_real_copy(field)) else: - # ls == () - if field.dtype.kind == "c": - yield (name+"_r", field.real.copy()) - yield (name+"_i", field.imag.copy()) - else: - yield (name, field) + yield (name + "_r", obj_array_real_copy(field)) + yield (name + "_i", obj_array_imag_copy(field)) def make_field_plotter_from_bbox(bbox, h, extend_factor=0): -- GitLab From 0abcbe0ac4d0b287b437e1399e3c1af2ec197a47 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 2 Jul 2020 20:38:03 -0500 Subject: [PATCH 2/4] Fix another deprecated call --- sumpy/fmm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sumpy/fmm.py b/sumpy/fmm.py index 9458401c..668734fd 100644 --- a/sumpy/fmm.py +++ b/sumpy/fmm.py @@ -320,8 +320,11 @@ class SumpyExpansionWrangler(object): return source_array.with_queue(self.queue)[self.tree.user_source_ids] def reorder_potentials(self, potentials): - from pytools.obj_array import is_obj_array, obj_array_vectorize - assert is_obj_array(potentials) + from pytools.obj_array import obj_array_vectorize + import numpy as np + assert ( + isinstance(potentials, np.ndarray) + and potentials.dtype.char == "O") def reorder(x): return x.with_queue(self.queue)[self.tree.sorted_target_ids] -- GitLab From 262c61b82baadc1c7d3e1df7c033ca266754c2f5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 2 Jul 2020 21:43:28 -0500 Subject: [PATCH 3/4] Rename Conda CI job --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8173bd20..e1579ae8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,7 +50,7 @@ Python 3 Titan X: reports: junit: test/pytest.xml -Python 3.6 Conda: +Python 3 Conda: script: # Disable caching to ensure SymEngine code generation is exercised. - export SUMPY_NO_CACHE=1 -- GitLab From 56db0a2839f7a70119d6a2e754f158a5d97252cf Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 2 Jul 2020 22:11:12 -0500 Subject: [PATCH 4/4] Fix dsource_vec in tests; and fix deprecated use of ctx_getter --- test/test_fmm.py | 12 ++++++------ test/test_kernels.py | 12 ++++++------ test/test_matrixgen.py | 14 ++++++++------ test/test_misc.py | 4 ++-- test/test_qbx.py | 4 ++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/test/test_fmm.py b/test/test_fmm.py index 2bc6d69d..b4294566 100644 --- a/test/test_fmm.py +++ b/test/test_fmm.py @@ -72,10 +72,10 @@ else: HelmholtzConformingVolumeTaylorMultipoleExpansion), (YukawaKernel(2), Y2DLocalExpansion, Y2DMultipoleExpansion), ]) -def test_sumpy_fmm(ctx_getter, knl, local_expn_class, mpole_expn_class): +def test_sumpy_fmm(ctx_factory, knl, local_expn_class, mpole_expn_class): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 1000 @@ -201,10 +201,10 @@ def test_sumpy_fmm(ctx_getter, knl, local_expn_class, mpole_expn_class): pconv_verifier() -def test_sumpy_fmm_timing_data_collection(ctx_getter): +def test_sumpy_fmm_timing_data_collection(ctx_factory): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue( ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) @@ -257,10 +257,10 @@ def test_sumpy_fmm_timing_data_collection(ctx_getter): assert timing_data -def test_sumpy_fmm_exclude_self(ctx_getter): +def test_sumpy_fmm_exclude_self(ctx_factory): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 500 diff --git a/test/test_kernels.py b/test/test_kernels.py index 834d8233..caff694d 100644 --- a/test/test_kernels.py +++ b/test/test_kernels.py @@ -58,8 +58,8 @@ else: @pytest.mark.parametrize("exclude_self", (True, False)) -def test_p2p(ctx_getter, exclude_self): - ctx = ctx_getter() +def test_p2p(ctx_factory, exclude_self): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) dimensions = 3 @@ -140,13 +140,13 @@ def test_p2p(ctx_getter, exclude_self): True ]) # Sample: test_p2e2p(cl._csc, LaplaceKernel(2), VolumeTaylorLocalExpansion, 4, False) -def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): +def test_p2e2p(ctx_factory, base_knl, expn_class, order, with_source_derivative): #logging.basicConfig(level=logging.INFO) from sympy.core.cache import clear_cache clear_cache() - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) np.random.seed(17) @@ -353,13 +353,13 @@ def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): HelmholtzConformingVolumeTaylorMultipoleExpansion), (HelmholtzKernel(2), H2DLocalExpansion, H2DMultipoleExpansion) ]) -def test_translations(ctx_getter, knl, local_expn_class, mpole_expn_class): +def test_translations(ctx_factory, knl, local_expn_class, mpole_expn_class): logging.basicConfig(level=logging.INFO) from sympy.core.cache import clear_cache clear_cache() - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) np.random.seed(17) diff --git a/test/test_matrixgen.py b/test/test_matrixgen.py index 2c07b40a..463e7be6 100644 --- a/test/test_matrixgen.py +++ b/test/test_matrixgen.py @@ -98,10 +98,10 @@ def _build_block_index(queue, nnodes, nblks, factor): @pytest.mark.parametrize('factor', [1.0, 0.6]) @pytest.mark.parametrize('lpot_id', [1, 2]) -def test_qbx_direct(ctx_getter, factor, lpot_id): +def test_qbx_direct(ctx_factory, factor, lpot_id): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) ndim = 2 @@ -143,8 +143,9 @@ def test_qbx_direct(ctx_getter, factor, lpot_id): extra_kwargs = {} if lpot_id == 2: + from pytools.obj_array import make_obj_array extra_kwargs["dsource_vec"] = \ - vector_to_device(queue, np.ones((ndim, n))) + vector_to_device(queue, make_obj_array(np.ones((ndim, n)))) _, (result_lpot,) = lpot(queue, targets=targets, @@ -181,10 +182,10 @@ def test_qbx_direct(ctx_getter, factor, lpot_id): @pytest.mark.parametrize("exclude_self", [True, False]) @pytest.mark.parametrize("factor", [1.0, 0.6]) @pytest.mark.parametrize('lpot_id', [1, 2]) -def test_p2p_direct(ctx_getter, exclude_self, factor, lpot_id): +def test_p2p_direct(ctx_factory, exclude_self, factor, lpot_id): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) ndim = 2 @@ -225,8 +226,9 @@ def test_p2p_direct(ctx_getter, exclude_self, factor, lpot_id): extra_kwargs["target_to_source"] = \ cl.array.arange(queue, 0, n, dtype=np.int) if lpot_id == 2: + from pytools.obj_array import make_obj_array extra_kwargs["dsource_vec"] = \ - vector_to_device(queue, np.ones((ndim, n))) + vector_to_device(queue, make_obj_array(np.ones((ndim, n)))) _, (result_lpot,) = lpot(queue, targets=targets, diff --git a/test/test_misc.py b/test/test_misc.py index 77f887c1..d8aff52f 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -243,7 +243,7 @@ RTOL_P2E2E2P = 1e-2 @pytest.mark.parametrize("case", P2E2E2P_TEST_CASES) -def test_toy_p2e2e2p(ctx_getter, case): +def test_toy_p2e2e2p(ctx_factory, case): dim = case.dim src = case.source.reshape(dim, -1) @@ -256,7 +256,7 @@ def test_toy_p2e2e2p(ctx_getter, case): from sumpy.expansion.local import VolumeTaylorLocalExpansion from sumpy.expansion.multipole import VolumeTaylorMultipoleExpansion - cl_ctx = ctx_getter() + cl_ctx = ctx_factory() ctx = t.ToyContext(cl_ctx, LaplaceKernel(dim), VolumeTaylorMultipoleExpansion, diff --git a/test/test_qbx.py b/test/test_qbx.py index d408c4a4..8b73224c 100644 --- a/test/test_qbx.py +++ b/test/test_qbx.py @@ -41,11 +41,11 @@ else: faulthandler.enable() -def test_direct(ctx_getter): +def test_direct(ctx_factory): # This evaluates a single layer potential on a circle. logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from sumpy.kernel import LaplaceKernel -- GitLab