From deb9ab6ae17353b0b07a06238fe0928d6065df06 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 16 Mar 2018 14:33:08 -0500 Subject: [PATCH] Flake8 fixes, part 2 --- examples/build_nearfield_table.py | 15 +++++++----- setup.py | 2 +- test/test_cahn_hilliard.py | 3 ++- volumential/__init__.py | 12 ++++++--- volumential/expansion_wrangler_fpnd.py | 24 ++++++++++-------- volumential/nearfield_potential_table.py | 31 +++++++++++++++--------- volumential/table_manager.py | 27 ++++++++++++--------- volumential/volume_fmm.py | 4 +-- 8 files changed, 71 insertions(+), 47 deletions(-) diff --git a/examples/build_nearfield_table.py b/examples/build_nearfield_table.py index 1a55006..9441e97 100644 --- a/examples/build_nearfield_table.py +++ b/examples/build_nearfield_table.py @@ -24,12 +24,13 @@ THE SOFTWARE. """ import logging -logger = logging.getLogger(__name__) +logger = logging.getLogger(__name__) + import numpy as np import pyopencl as cl -import boxtree as bt -import sumpy as sp -import volumential as vm +import boxtree as bt # noqa: F401 +import sumpy as sp # noqa: F401 +import volumential as vm # noqa: F401 from volumential.table_manager import NearFieldInteractionTableManager @@ -79,7 +80,8 @@ for i in range(1, 7): print("Brick quad order =", order1) tm1 = NearFieldInteractionTableManager("nft_brick.hdf5", root_extent=root_extent) - table1, rec_flag = tm1.get_table(2, "Laplace", q_order=i, source_box_level=sl, + table1, rec_flag = tm1.get_table(2, "Laplace", q_order=i, + source_box_level=sl, force_recompute=False, compute_method="DrosteSum", queue=queue, n_brick_quad_points=order1, adaptive_level=False, alpha=alpha, n_levels=n_levels1) @@ -104,7 +106,8 @@ for i in range(1, 7): table_level_tol=1e-15, table_quad_tol=diff) last_diff = diff - diff = np.max(np.abs(table1.data - table2.data)) / np.max(np.abs(table2.data)) + diff = np.max( + np.abs(table1.data - table2.data)) / np.max(np.abs(table2.data)) print("diff =", diff) tm1 = tm2 diff --git a/setup.py b/setup.py index 4c7ab44..9c1b88d 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,7 @@ def main(): "multiprocess>=0.70", "h5py>=2.7", "pyevtk>=1.1.0", - "scipy>=1.0", + "scipy>=0.19", "sumpy>=2016.1b1" ], include_package_data=True diff --git a/test/test_cahn_hilliard.py b/test/test_cahn_hilliard.py index a9e1326..8ffe5e1 100644 --- a/test/test_cahn_hilliard.py +++ b/test/test_cahn_hilliard.py @@ -37,9 +37,11 @@ theta_y = 60. / 180. * np.pi b = s / (epsilon**2) c = 1. / (epsilon * delta_t) + def make_patch(center, size): return CalculusPatch(center=center, h=size, order=patch_order) + def test_patch_cahn_hilliard(): rep = 3 @@ -150,4 +152,3 @@ if __name__ == "__main__": else: from py.test.cmdline import main main([__file__]) - diff --git a/volumential/__init__.py b/volumential/__init__.py index 9e08381..9cf1f9a 100644 --- a/volumential/__init__.py +++ b/volumential/__init__.py @@ -24,17 +24,21 @@ THE SOFTWARE. from volumential.singular_integral_2d import box_quad from volumential.version import VERSION_TEXT as volumential_version -from volumential.table_manager import NearFieldInteractionTableManager -from volumential.nearfield_potential_table import NearFieldInteractionTable +from volumential.table_manager import NearFieldInteractionTableManager # noqa: F401 +from volumential.nearfield_potential_table import ( # noqa: F401 + NearFieldInteractionTable) + __all__ = ["volumential_version", "box_quad", "nearfield_potential_table"] try: - import volumential.meshgen as meshgen + import volumential.meshgen as meshgen # noqa: F401 __all__.append("meshgen") except ImportError: - print("Mesh generation interface setup unsussessful.") + raise ImportError("Could not import volumential._meshgen. " + "You need to run 'build.sh' in " + "volumential/contrib/meshgen11_dealii") __doc__ = """ diff --git a/volumential/expansion_wrangler_fpnd.py b/volumential/expansion_wrangler_fpnd.py index fa6194f..fc27e86 100644 --- a/volumential/expansion_wrangler_fpnd.py +++ b/volumential/expansion_wrangler_fpnd.py @@ -60,6 +60,7 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): """ # {{{ constructor + def __init__(self, code_container, queue, @@ -85,12 +86,14 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): self.near_field_table = {} if isinstance(near_field_table, list): assert len(self.code.out_kernels) == 1 - self.near_field_table[self.code.out_kernels[0].__repr__()] = near_field_table + self.near_field_table[self.code.out_kernels[0].__repr__()] = \ + near_field_table self.n_tables = len(near_field_table) elif isinstance(near_field_table, NearFieldInteractionTable): assert len(self.code.out_kernels) == 1 - self.near_field_table[self.code.out_kernels[0].__repr__()] = [near_field_table] + self.near_field_table[self.code.out_kernels[0].__repr__()] = \ + [near_field_table] self.n_tables = 1 elif isinstance(near_field_table, dict): @@ -126,8 +129,8 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): if not table.is_built: raise RuntimeError( - "Near field interaction table needs to be built prior to being used" - ) + "Near field interaction table needs to be built " + "prior to being used") table_root_extent = table.source_box_extent * 2**lev assert abs(self.root_table_source_box_extent - @@ -141,8 +144,8 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): int(self.tree.root_extent / table_root_extent) * table_root_extent - self.tree.root_extent) < 1e-15: raise RuntimeError("Incompatible list of tables: the " - "source_box_extent of the root table must divide the " - "bounding box's extent by an integer.") + "source_box_extent of the root table must " + "divide the bounding box's extent by an integer.") if self.n_tables > 1: # this checks that the boxes at the highest level are covered @@ -153,7 +156,8 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): + str(tree.nlevels) + " are not covered.") # the check that the boxes at the coarsest level are covered is - # deferred until trav.target_boxes is passed when invoking eval_direct + # deferred until trav.target_boxes is passed when invoking + # eval_direct self.dtype = dtype @@ -269,7 +273,6 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): self.near_field_table[kname][0].case_indices) # table.data - from pytools.obj_array import make_obj_array table_data_combined = np.zeros( (len(self.near_field_table[kname]), len(self.near_field_table[kname][0].data))) @@ -277,8 +280,9 @@ class FPNDExpansionWrangler(ExpansionWranglerInterface, SumpyExpansionWrangler): (len(self.near_field_table[kname]), len(self.near_field_table[kname][0].mode_normalizers))) for lev in range(len(self.near_field_table[kname])): - table_data_combined[lev,:] = self.near_field_table[kname][lev].data - mode_nmlz_combined[lev,:] = self.near_field_table[kname][lev].mode_normalizers + table_data_combined[lev, :] = self.near_field_table[kname][lev].data + mode_nmlz_combined[lev, :] = \ + self.near_field_table[kname][lev].mode_normalizers logger.debug("Table data congregated") diff --git a/volumential/nearfield_potential_table.py b/volumential/nearfield_potential_table.py index 8fdc8a3..411d246 100644 --- a/volumential/nearfield_potential_table.py +++ b/volumential/nearfield_potential_table.py @@ -56,7 +56,6 @@ def _self_tp(vec, tpd=2): raise NotImplementedError - def _orthonormal(n, i): eb = np.zeros(n) eb[i] = 1 @@ -150,8 +149,11 @@ def get_cahn_hilliard(dim, b=0, c=0, approx_at_origin=False): return cahn_hilliard + def get_cahn_hilliard_laplacian(dim, b=0, c=0): - raise NotImplementedError("Transform method under construction, use DrosteSum instead") + raise NotImplementedError("Transform method under construction, " + "use DrosteSum instead") + def sumpy_kernel_to_lambda(sknl): from sympy import Symbol, symbols, lambdify @@ -490,6 +492,7 @@ class NearFieldInteractionTable(object): basis_set = np.array([ b1.reshape([cheb_order, 1]) * b2.reshape([1, cheb_order]) for b1, b2 in product([basis_1d for d in range(self.dim)]) + ]) elif self.dim == 3: basis_set = np.array([ @@ -497,6 +500,7 @@ class NearFieldInteractionTable(object): b2.reshape([1, cheb_order, 1]) * b3.reshape([1, 1, cheb_order]) for b1, b2, b3 in product([basis_1d for d in range(self.dim)]) + ]) mode_cheb_coeffs = np.array([ np.sum(mvals * basis) for basis in basis_set @@ -954,9 +958,10 @@ class NearFieldInteractionTable(object): if self.dim == 1: resknl = resknl.replace("TPLTGT_ASSIGNMENT", """target_nodes[t0]""") - resknl = resknl.replace("QUAD_PT_ASSIGNMENT", """quadrature_nodes[q0]""") + resknl = resknl.replace("QUAD_PT_ASSIGNMENT", + """quadrature_nodes[q0]""") resknl = resknl.replace("DENSITY_VAL_ASSIGNMENT", - """basis_eval0""" + """basis_eval0""") resknl = resknl.replace("PREPARE_BASIS_VALS", "\n".join([self.codegen_basis_eval(i) for i in self.dim]) + """ @@ -969,12 +974,12 @@ class NearFieldInteractionTable(object): resknl = resknl.replace("QUAD_PT_ASSIGNMENT", """if(iaxis == 0, quadrature_nodes[q0], quadrature_nodes[q1])""") resknl = resknl.replace("DENSITY_VAL_ASSIGNMENT", - """basis_eval0 * basis_eval1""" + """basis_eval0 * basis_eval1""") resknl = resknl.replace("PREPARE_BASIS_VALS", "\n".join([self.codegen_basis_eval(i) for i in self.dim]) + """ ... nop {id=basis_evals,dep=basis0:basis1} - """ + """) elif self.dim == 3: resknl = resknl.replace("TPLTGT_ASSIGNMENT", @@ -982,14 +987,14 @@ class NearFieldInteractionTable(object): iaxis == 1, target_nodes[t1], target_nodes[t2]))""") resknl = resknl.replace("QUAD_PT_ASSIGNMENT", """if(iaxis == 0, quadrature_nodes[q0], if( - iaxis == 1, quadrature_nodes[q1], quadrature_nodes[q2]))""") + iaxis == 1, quadrature_nodes[q1], quadrature_nodes[q2]))""") resknl = resknl.replace("DENSITY_VAL_ASSIGNMENT", - """basis_eval0 * basis_eval1 * basis_eval2""" + """basis_eval0 * basis_eval1 * basis_eval2""") resknl = resknl.replace("PREPARE_BASIS_VALS", "\n".join([self.codegen_basis_eval(i) for i in self.dim]) + """ ... nop {id=basis_evals,dep=basis0:basis1:basis2} - """ + """) else: raise NotImplementedError @@ -1018,7 +1023,8 @@ class NearFieldInteractionTable(object): # Targets outside projected onto the boundary for iaxis - <> template_target[iaxis] = TPLTGT_ASSIGNMENT {id=tplt_tgt_pre,dup=iaxis} + <> template_target[iaxis] = TPLTGT_ASSIGNMENT \ + {id=tplt_tgt_pre,dup=iaxis} end # True targets are used for kernel evaluation @@ -1125,7 +1131,7 @@ class NearFieldInteractionTable(object): # Debug output #mapped_points[ilevel, ibrick_axis, - # ibrick_side, TGT_VARS, icase, iaxis, QUAD_VARS] = \ + # ibrick_side, TGT_VARS, icase, iaxis, QUAD_VARS] = \ # mapped_point_tmp[iaxis] {dep=mpoint} #mapped_target[TGT_VARS, icase, iaxis] = target[iaxis] end @@ -1157,7 +1163,8 @@ class NearFieldInteractionTable(object): PREPARE_BASIS_VALS - <> density_val = DENSITY_VAL_ASSIGNMENT {id=density,dep=basis_evals} + <> density_val = DENSITY_VAL_ASSIGNMENT \ + {id=density,dep=basis_evals} end end diff --git a/volumential/table_manager.py b/volumential/table_manager.py index 1659ccc..ec98539 100644 --- a/volumential/table_manager.py +++ b/volumential/table_manager.py @@ -1,3 +1,5 @@ +from __future__ import division, absolute_import, print_function + __copyright__ = "Copyright (C) 2017 - 2018 Xiaoyu Wei" __license__ = """ @@ -52,7 +54,7 @@ class NearFieldInteractionTableManager( root_extent=1, dtype=np.float64 ): - self.dtype=dtype + self.dtype = dtype self.filename = dataset_filename self.root_extent = root_extent @@ -127,7 +129,6 @@ class NearFieldInteractionTableManager( grp = grp["Order_" + str(q_order)] - if "Level_" + str(source_box_level) not in grp: logger.info("Table cache missing. Invoking fresh computation.") is_recomputed = True @@ -187,8 +188,8 @@ class NearFieldInteractionTableManager( "(int, float, complex, str) " "are stored in the cache. " "Also, some parameters related to method for " - "table building are not critical for consistency." - ) + "table building are not critical for " + "consistency.") print(e) return table, is_recomputed @@ -234,8 +235,8 @@ class NearFieldInteractionTableManager( source_box_extent=self.root_extent * (2**(-source_box_level)) ) - assert abs(table.source_box_extent - grp.attrs["source_box_extent"] - ) < 1e-15 + assert abs( + table.source_box_extent - grp.attrs["source_box_extent"]) < 1e-15 assert source_box_level == grp.attrs["source_box_level"] # Load data @@ -319,7 +320,8 @@ class NearFieldInteractionTableManager( return FactorizedBiharmonicKernel(dim) elif kernel_type == "Cahn-Hilliard-Laplacian": - from sumpy.kernel import FactorizedBiharmonicKernel, LaplacianTargetDerivative + from sumpy.kernel import FactorizedBiharmonicKernel, \ + LaplacianTargetDerivative return LaplacianTargetDerivative(FactorizedBiharmonicKernel(dim)) elif kernel_type == "Cahn-Hilliard-Dx": @@ -327,13 +329,15 @@ class NearFieldInteractionTableManager( return AxisTargetDerivative(0, FactorizedBiharmonicKernel(dim)) elif kernel_type == "Cahn-Hilliard-Laplacian-Dx": - from sumpy.kernel import FactorizedBiharmonicKernel, LaplacianTargetDerivative + from sumpy.kernel import FactorizedBiharmonicKernel, \ + LaplacianTargetDerivative from sumpy.kernel import AxisTargetDerivative return AxisTargetDerivative(0, LaplacianTargetDerivative(FactorizedBiharmonicKernel(dim))) elif kernel_type == "Cahn-Hilliard-Laplacian-Dy": - from sumpy.kernel import FactorizedBiharmonicKernel, LaplacianTargetDerivative + from sumpy.kernel import FactorizedBiharmonicKernel, \ + LaplacianTargetDerivative from sumpy.kernel import AxisTargetDerivative return AxisTargetDerivative(1, LaplacianTargetDerivative(FactorizedBiharmonicKernel(dim))) @@ -412,7 +416,7 @@ class NearFieldInteractionTableManager( assert (q_order >= 1) assert str(dim) + "D" in self.datafile - assert kernel_type in self.datafile[str(dim) +"D"] + assert kernel_type in self.datafile[str(dim) + "D"] assert "Order_" + str(q_order) in self.datafile[str(dim) + "D"][kernel_type] if compute_method == "Transform": @@ -462,7 +466,8 @@ class NearFieldInteractionTableManager( self.update_dataset(grp, "q_points", table.q_points) self.update_dataset(grp, "data", table.data) self.update_dataset(grp, "mode_normalizers", table.mode_normalizers) - self.update_dataset(grp, "interaction_case_vecs", table.interaction_case_vecs) + self.update_dataset(grp, "interaction_case_vecs", + table.interaction_case_vecs) self.update_dataset(grp, "case_indices", table.case_indices) distinct_numbers = set() diff --git a/volumential/volume_fmm.py b/volumential/volume_fmm.py index 81e4ed3..fc671db 100644 --- a/volumential/volume_fmm.py +++ b/volumential/volume_fmm.py @@ -300,8 +300,8 @@ def interpolate_volume_potential(target_points, traversal, wrangler, potential, import pyopencl as cl # Set this number small enough so that all points found # are inside the box - target_radii = cl.array.to_device(queue, - np.ones(n_points, dtype=coord_dtype) * 1e-32) + target_radii = cl.array.to_device( + queue, np.ones(n_points, dtype=coord_dtype) * 1e-32) lbl_lookup, evt = lookup_builder(queue, tree, target_points, target_radii) -- GitLab