From 2c566458d00806eaeba0fcc6febbac23a7aad7f5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Sep 2017 11:56:43 -0500 Subject: [PATCH 1/4] Fix SymEngine code generation. Closes #24. * replaces mat / scalar with mat * scalar**-1. * replace list argument to subs with a dict (Although there are pending changes to SymEngine for the above two issues, they aren't released in a version yet.) * Removed deep as a kwarg to expand(). It doesn't do what we want anyway. * Disabled caching for tests in test_kernels. This exercises SymEngine code generation every time the tests run. The execution time for these tests without caching is about 6 minutes for me, so the overhead is acceptable. --- sumpy/expansion/local.py | 4 ++-- sumpy/expansion/multipole.py | 4 ++-- sumpy/symbolic.py | 2 +- test/test_kernels.py | 10 ++++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sumpy/expansion/local.py b/sumpy/expansion/local.py index 9e891a2d..483bc0eb 100644 --- a/sumpy/expansion/local.py +++ b/sumpy/expansion/local.py @@ -130,7 +130,7 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): evaluated_coeffs = ( self.derivative_wrangler.get_full_kernel_derivatives_from_stored( coeffs, rscale)) - bvec = bvec / rscale + bvec = bvec * rscale**-1 result = sum( coeff * mi_power(bvec, mi) @@ -195,7 +195,7 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): # canceling "rscales" closer to each other in the hope of helping # with that. result = [ - (taker.diff(mi) * tgt_rscale**sum(mi)).expand(deep=False) + (taker.diff(mi) * tgt_rscale**sum(mi)).expand() for mi in self.get_coefficient_identifiers()] logger.info("building translation operator: done") diff --git a/sumpy/expansion/multipole.py b/sumpy/expansion/multipole.py index 4db9250b..0ddbb428 100644 --- a/sumpy/expansion/multipole.py +++ b/sumpy/expansion/multipole.py @@ -88,7 +88,7 @@ class VolumeTaylorMultipoleExpansionBase(MultipoleExpansionBase): for i, mi in enumerate(coeff_identifiers): result[i] /= (mi_factorial(mi) * rscale ** sum(mi)) else: - avec = avec/rscale + avec = avec * rscale**-1 result = [ mi_power(avec, mi) / mi_factorial(mi) @@ -107,7 +107,7 @@ class VolumeTaylorMultipoleExpansionBase(MultipoleExpansionBase): self.kernel.adjust_for_kernel_scaling( vector_subs( expr, - bvec, bvec/rscale), + bvec, bvec * rscale**-1), rscale, nderivatives) / rscale ** (nderivatives - nderivatives_for_scaling)) else: diff --git a/sumpy/symbolic.py b/sumpy/symbolic.py index 55f91284..665aff9d 100644 --- a/sumpy/symbolic.py +++ b/sumpy/symbolic.py @@ -199,7 +199,7 @@ def vector_subs(expr, from_vec, to_vec): for icol in range(from_vec.cols): subs_pairs.append((from_vec[irow, icol], to_vec[irow, icol])) - return expr.subs(subs_pairs) + return expr.subs(dict(subs_pairs)) def find_power_of(base, prod): diff --git a/test/test_kernels.py b/test/test_kernels.py index 65295e29..a0cf8ae7 100644 --- a/test/test_kernels.py +++ b/test/test_kernels.py @@ -141,6 +141,9 @@ def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): from sympy.core.cache import clear_cache clear_cache() + from sumpy import set_caching_enabled + set_caching_enabled(False) + ctx = ctx_getter() queue = cl.CommandQueue(ctx) @@ -331,6 +334,8 @@ def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): slack += 0.3 grad_slack += 0.3 + set_caching_enabled(True) + assert eoc_rec_pot.order_estimate() > tgt_order - slack assert eoc_rec_grad_x.order_estimate() > tgt_order_grad - grad_slack @@ -350,6 +355,9 @@ def test_translations(ctx_getter, knl, local_expn_class, mpole_expn_class): from sympy.core.cache import clear_cache clear_cache() + from sumpy import set_caching_enabled + set_caching_enabled(False) + ctx = ctx_getter() queue = cl.CommandQueue(ctx) @@ -597,6 +605,8 @@ def test_translations(ctx_getter, knl, local_expn_class, mpole_expn_class): pconv_verifier_full.add_data_point(order, err) + set_caching_enabled(True) + for name, verifier in [ ("p2m2p", pconv_verifier_p2m2p), ("p2m2m2p", pconv_verifier_p2m2m2p), -- GitLab From 0e892ed3b4588deeebb2f04fb4c76d889bc6e37a Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Sep 2017 12:26:12 -0500 Subject: [PATCH 2/4] Revert caching changes and set env var to force symengine usage. --- .gitlab-ci.yml | 1 + test/test_kernels.py | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c49ab232..007753e4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -70,6 +70,7 @@ Python 3.6 POCL: Python 3.5 Conda: script: - export SUMPY_NO_CACHE=1 + - export SUMPY_FORCE_SYMBOLIC_BACKEND=symengine - CONDA_ENVIRONMENT=.test-conda-env-py3.yml - REQUIREMENTS_TXT=.test-conda-env-py3-requirements.txt - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh diff --git a/test/test_kernels.py b/test/test_kernels.py index a0cf8ae7..65295e29 100644 --- a/test/test_kernels.py +++ b/test/test_kernels.py @@ -141,9 +141,6 @@ def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): from sympy.core.cache import clear_cache clear_cache() - from sumpy import set_caching_enabled - set_caching_enabled(False) - ctx = ctx_getter() queue = cl.CommandQueue(ctx) @@ -334,8 +331,6 @@ def test_p2e2p(ctx_getter, base_knl, expn_class, order, with_source_derivative): slack += 0.3 grad_slack += 0.3 - set_caching_enabled(True) - assert eoc_rec_pot.order_estimate() > tgt_order - slack assert eoc_rec_grad_x.order_estimate() > tgt_order_grad - grad_slack @@ -355,9 +350,6 @@ def test_translations(ctx_getter, knl, local_expn_class, mpole_expn_class): from sympy.core.cache import clear_cache clear_cache() - from sumpy import set_caching_enabled - set_caching_enabled(False) - ctx = ctx_getter() queue = cl.CommandQueue(ctx) @@ -605,8 +597,6 @@ def test_translations(ctx_getter, knl, local_expn_class, mpole_expn_class): pconv_verifier_full.add_data_point(order, err) - set_caching_enabled(True) - for name, verifier in [ ("p2m2p", pconv_verifier_p2m2p), ("p2m2m2p", pconv_verifier_p2m2m2p), -- GitLab From 1728ab08740df20aa2580f314bf1290aa497624c Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Sep 2017 17:08:39 -0500 Subject: [PATCH 3/4] Fix SymEngine channel and change SUMPY_FORCE_SYMBOLIC_BACKEND to error out if it doesn't find the appropriate backend. --- .test-conda-env-py3.yml | 3 ++- sumpy/symbolic.py | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.test-conda-env-py3.yml b/.test-conda-env-py3.yml index a53d2c22..d5e01ead 100644 --- a/.test-conda-env-py3.yml +++ b/.test-conda-env-py3.yml @@ -12,5 +12,6 @@ dependencies: - islpy - pyopencl - python=3.5 -- python-symengine=0.3.0 +- symengine::symengine=0.3.0 +- symengine::python-symengine=0.3.0 # things not in here: loopy boxtree pymbolic pyfmmlib diff --git a/sumpy/symbolic.py b/sumpy/symbolic.py index 665aff9d..49fa4059 100644 --- a/sumpy/symbolic.py +++ b/sumpy/symbolic.py @@ -42,8 +42,9 @@ def _find_symbolic_backend(): try: import symengine # noqa symengine_found = True - except ImportError: + except ImportError as import_error: symengine_found = False + symengine_error = import_error ALLOWED_BACKENDS = ("sympy", "symengine") # noqa BACKEND_ENV_VAR = "SUMPY_FORCE_SYMBOLIC_BACKEND" # noqa @@ -60,11 +61,9 @@ def _find_symbolic_backend(): ", ".join("'%s'" % val for val in ALLOWED_BACKENDS))) if backend == "symengine" and not symengine_found: - from warnings import warn - warn("%s=symengine was specified, but could not find symengine. " - "Using sympy." % BACKEND_ENV_VAR, RuntimeWarning) + raise RuntimeError("could not find SymEngine: %s" % symengine_error) - USE_SYMENGINE = backend == "symengine" and symengine_found + USE_SYMENGINE = True else: USE_SYMENGINE = symengine_found -- GitLab From 9397eafa18a87a665acb9a118c7779fd13c5d2a1 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 6 Sep 2017 17:56:34 -0500 Subject: [PATCH 4/4] Add comment about why caching is disabled. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 007753e4..946ff3b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -69,6 +69,7 @@ Python 3.6 POCL: Python 3.5 Conda: script: + # Disable caching to ensure SymEngine code generation is exercised. - export SUMPY_NO_CACHE=1 - export SUMPY_FORCE_SYMBOLIC_BACKEND=symengine - CONDA_ENVIRONMENT=.test-conda-env-py3.yml -- GitLab