From c974957282ade120a1094f78c3b37929b275fc90 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 18 Oct 2023 13:50:32 -0700 Subject: [PATCH] Cleaning --- src/amrex/ArrayOfStructs.py | 5 ----- src/amrex/StructOfArrays.py | 4 ---- src/amrex/space1d/__init__.py | 4 ++-- src/amrex/space2d/__init__.py | 4 ++-- src/amrex/space3d/__init__.py | 4 ++-- tests/conftest.py | 3 ++- tests/test_aos.py | 4 +++- tests/test_array4.py | 6 ++++-- tests/test_basefab.py | 2 +- tests/test_coordsys.py | 3 --- tests/test_dim3.py | 1 - tests/test_farraybox.py | 4 ++-- tests/test_geometry.py | 2 +- tests/test_multifab.py | 10 +++++----- tests/test_particleContainer.py | 2 +- tests/test_particleTile.py | 2 +- tests/test_periodicity.py | 5 ++--- tests/test_podvector.py | 3 --- tests/test_realbox.py | 3 --- tests/test_soa.py | 1 - 20 files changed, 28 insertions(+), 44 deletions(-) diff --git a/src/amrex/ArrayOfStructs.py b/src/amrex/ArrayOfStructs.py index ff2ed4fd..3c2d3791 100644 --- a/src/amrex/ArrayOfStructs.py +++ b/src/amrex/ArrayOfStructs.py @@ -5,7 +5,6 @@ Authors: Axel Huebl License: BSD-3-Clause-LBNL """ -from collections import namedtuple def aos_to_numpy(self, copy=False): @@ -65,10 +64,6 @@ def aos_to_cupy(self, copy=False): """ import cupy as cp - SoA_cp = namedtuple(type(self).__name__ + "_cp", ["real", "int"]) - - soa_view = SoA_cp([], []) - if self.size() == 0: raise ValueError("AoS is empty.") diff --git a/src/amrex/StructOfArrays.py b/src/amrex/StructOfArrays.py index e906732b..f007909c 100644 --- a/src/amrex/StructOfArrays.py +++ b/src/amrex/StructOfArrays.py @@ -25,8 +25,6 @@ def soa_to_numpy(self, copy=False): A tuple with real and int components that are each lists of 1D numpy arrays. """ - import numpy as np - SoA_np = namedtuple(type(self).__name__ + "_np", ["real", "int"]) soa_view = SoA_np([], []) @@ -65,8 +63,6 @@ def soa_to_cupy(self, copy=False): ImportError Raises an exception if cupy is not installed """ - import cupy as cp - SoA_cp = namedtuple(type(self).__name__ + "_cp", ["real", "int"]) soa_view = SoA_cp([], []) diff --git a/src/amrex/space1d/__init__.py b/src/amrex/space1d/__init__.py index d752c667..060a451d 100644 --- a/src/amrex/space1d/__init__.py +++ b/src/amrex/space1d/__init__.py @@ -37,10 +37,10 @@ def d_decl(x, y, z): def Print(*args, **kwargs): """Wrap amrex::Print() - only the IO processor writes""" - if not initialized(): + if not initialized(): # noqa print("warning: Print all - AMReX not initialized") print(*args, **kwargs) - elif ParallelDescriptor.IOProcessor(): + elif ParallelDescriptor.IOProcessor(): # noqa print(*args, **kwargs) diff --git a/src/amrex/space2d/__init__.py b/src/amrex/space2d/__init__.py index d0933662..6c654c52 100644 --- a/src/amrex/space2d/__init__.py +++ b/src/amrex/space2d/__init__.py @@ -37,10 +37,10 @@ def d_decl(x, y, z): def Print(*args, **kwargs): """Wrap amrex::Print() - only the IO processor writes""" - if not initialized(): + if not initialized(): # noqa print("warning: Print all - AMReX not initialized") print(*args, **kwargs) - elif ParallelDescriptor.IOProcessor(): + elif ParallelDescriptor.IOProcessor(): # noqa print(*args, **kwargs) diff --git a/src/amrex/space3d/__init__.py b/src/amrex/space3d/__init__.py index 269b8112..baa757e7 100644 --- a/src/amrex/space3d/__init__.py +++ b/src/amrex/space3d/__init__.py @@ -37,10 +37,10 @@ def d_decl(x, y, z): def Print(*args, **kwargs): """Wrap amrex::Print() - only the IO processor writes""" - if not initialized(): + if not initialized(): # noqa print("warning: Print all - AMReX not initialized") print(*args, **kwargs) - elif ParallelDescriptor.IOProcessor(): + elif ParallelDescriptor.IOProcessor(): # noqa print(*args, **kwargs) diff --git a/tests/conftest.py b/tests/conftest.py index c120fb75..c62f076d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,8 +16,9 @@ except ImportError: raise ImportError("AMReX: No 1D, 2D or 3D module found!") +# Import calls MPI_Initialize, if not called already if amr.Config.have_mpi: - from mpi4py import MPI + from mpi4py import MPI # noqa # base path for input files basepath = os.getcwd() diff --git a/tests/test_aos.py b/tests/test_aos.py index 139cda0b..54d6a188 100644 --- a/tests/test_aos.py +++ b/tests/test_aos.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import numpy as np -import pytest import amrex.space3d as amr @@ -85,6 +84,9 @@ def test_array_interface(): print(arr) print(aos[0], aos[1]) print("-------") + aos[0] = p4 + assert aos[0].x == 0 + assert aos[0].y == -5 aos[0] = p3 print("array:", arr) print("aos[0]:", aos[0], "aos[1]:", aos[1]) diff --git a/tests/test_array4.py b/tests/test_array4.py index 19fabf8a..99c37d12 100644 --- a/tests/test_array4.py +++ b/tests/test_array4.py @@ -87,8 +87,10 @@ def test_array4_numba(): ) # type: numpy.ndarray # host-to-device copy - x_numba = cuda.to_device(x) # type: numba.cuda.cudadrv.devicearray.DeviceNDArray - # x_cupy = cupy.asarray(x_numba) # type: cupy.ndarray + x_numba = cuda.to_device(x) # noqa + # type is numba.cuda.cudadrv.devicearray.DeviceNDArray + # x_cupy = cupy.asarray(x_numba) + # type is cupy.ndarray # TODO: Implement __cuda_array_interface__ or DLPack in Array4 constructor # x_arr = amr.Array4_double(x_numba) # type: amr.Array4_double diff --git a/tests/test_basefab.py b/tests/test_basefab.py index 3fcb871f..28c54bd3 100644 --- a/tests/test_basefab.py +++ b/tests/test_basefab.py @@ -6,7 +6,7 @@ def test_basefab(): - bf = amr.BaseFab_Real() + bf = amr.BaseFab_Real() # noqa def test_basefab_to_host(): diff --git a/tests/test_coordsys.py b/tests/test_coordsys.py index 50ca3d77..676e1a41 100644 --- a/tests/test_coordsys.py +++ b/tests/test_coordsys.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np -import pytest - import amrex.space3d as amr # import amrex.space3d as amr.CoordSys.CoordType as CoordType diff --git a/tests/test_dim3.py b/tests/test_dim3.py index a38e5248..b2a6fdd0 100644 --- a/tests/test_dim3.py +++ b/tests/test_dim3.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import numpy as np -import pytest import amrex.space3d as amr diff --git a/tests/test_farraybox.py b/tests/test_farraybox.py index 3ec028d8..05391d68 100644 --- a/tests/test_farraybox.py +++ b/tests/test_farraybox.py @@ -4,11 +4,11 @@ def test_farraybox(): - fab = amr.FArrayBox() + fab = amr.FArrayBox() # noqa def test_farraybox_io(): - fab = amr.FArrayBox() + fab = amr.FArrayBox() # noqa # https://docs.python.org/3/library/io.html # https://gist.github.com/asford/544323a5da7dddad2c9174490eb5ed06#file-test_ostream_example-py diff --git a/tests/test_geometry.py b/tests/test_geometry.py index f4798a45..16c51625 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -115,7 +115,7 @@ def test_periodic_queries(box, real_box): is_periodic = [0, 0, 1] gm = Gm(box, real_box, coord, is_periodic) - pdcity = gm.periodicity() + pdcity = gm.periodicity() # noqa assert gm.isAnyPeriodic() assert not gm.isPeriodic(0) and not gm.isPeriodic(1) and gm.isPeriodic(2) diff --git a/tests/test_multifab.py b/tests/test_multifab.py index 61e304dd..e6e2020f 100644 --- a/tests/test_multifab.py +++ b/tests/test_multifab.py @@ -175,7 +175,7 @@ def set_to_three(array): # assign 3: loop through boxes and launch kernels for mfi in mfab_device: - bx = mfi.tilebox().grow(ngv) + bx = mfi.tilebox().grow(ngv) # noqa marr = mfab_device.array(mfi) marr_numba = cuda.as_cuda_array(marr) @@ -208,7 +208,7 @@ def test_mfab_ops_cuda_cupy(make_mfab_device): # assign 3 with cupyx.profiler.time_range("assign 3 [()]", color_id=0): for mfi in mfab_device: - bx = mfi.tilebox().grow(ngv) + bx = mfi.tilebox().grow(ngv) # noqa marr_cupy = mfab_device.array(mfi).to_cupy(order="C") # print(marr_cupy.shape) # 1, 32, 32, 32 # print(marr_cupy.dtype) # float64 @@ -243,7 +243,7 @@ def set_to_five(mm): return mm for mfi in mfab_device: - bx = mfi.tilebox().grow(ngv) + bx = mfi.tilebox().grow(ngv) # noqa marr_cupy = mfab_device.array(mfi).to_cupy(order="F") # print(marr_cupy.shape) # 32, 32, 32, 1 # print(marr_cupy.dtype) # float64 @@ -268,7 +268,7 @@ def set_to_seven(x): x[...] = 7.0 for mfi in mfab_device: - bx = mfi.tilebox().grow(ngv) + bx = mfi.tilebox().grow(ngv) # noqa marr_cupy = mfab_device.array(mfi).to_cupy(order="C") # write and read into the marr_cupy @@ -306,7 +306,7 @@ def test_mfab_ops_cuda_pytorch(make_mfab_device): amr.Config.gpu_backend != "CUDA", reason="Requires AMReX_GPU_BACKEND=CUDA" ) def test_mfab_ops_cuda_cuml(make_mfab_device): - mfab_device = make_mfab_device() + mfab_device = make_mfab_device() # noqa # https://github.com/rapidsai/cuml # https://github.com/rapidsai/cudf # maybe better for particles as a dataframe test diff --git a/tests/test_particleContainer.py b/tests/test_particleContainer.py index 43e722e2..b00725c0 100644 --- a/tests/test_particleContainer.py +++ b/tests/test_particleContainer.py @@ -121,7 +121,7 @@ def test_pc_init(): assert pc.TotalNumberOfParticles() == pc.NumberOfParticlesAtLevel(0) == npart assert pc.OK() - print(f"Finest level = ", pc.finest_level) + print(f"Finest level = {pc.finest_level}") print("Iterate particle boxes & set values") # lvl = 0 diff --git a/tests/test_particleTile.py b/tests/test_particleTile.py index 2a1bdcf2..08aae860 100644 --- a/tests/test_particleTile.py +++ b/tests/test_particleTile.py @@ -119,7 +119,7 @@ def test_ptile_soa(): @pytest.mark.skipif(amr.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3") -def test_ptile_aos(): +def test_ptile_aos_3d(): pt = amr.ParticleTile_1_1_2_1_default() p1 = amr.Particle_1_1() p2 = amr.Particle_1_1() diff --git a/tests/test_periodicity.py b/tests/test_periodicity.py index d5819545..1af1c4fe 100644 --- a/tests/test_periodicity.py +++ b/tests/test_periodicity.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np import pytest import amrex.space3d as amr @@ -19,7 +18,7 @@ def test_periodicity(): assert obj == non_periodic -@pytest.mark.skipif(amr.Config.spacedim == 3, reason="Requires AMREX_SPACEDIM = 3") +@pytest.mark.skipif(amr.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3") def test_periodicity_3d(): iv = amr.IntVect(1, 0, 1) obj = amr.Periodicity(iv) @@ -32,5 +31,5 @@ def test_periodicity_3d(): bx = obj.domain print(bx) - v_iv = ob.shift_IntVect + v_iv = obj.shift_IntVect print(v_iv) diff --git a/tests/test_podvector.py b/tests/test_podvector.py index 3b3233f8..a3be9926 100644 --- a/tests/test_podvector.py +++ b/tests/test_podvector.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np -import pytest - import amrex.space3d as amr diff --git a/tests/test_realbox.py b/tests/test_realbox.py index 9d0b659c..8e80d924 100644 --- a/tests/test_realbox.py +++ b/tests/test_realbox.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -import numpy as np -import pytest - import amrex.space3d as amr from amrex.space3d import RealVect as RV from amrex.space3d import XDim3 diff --git a/tests/test_soa.py b/tests/test_soa.py index 373ac4f1..24c6911f 100644 --- a/tests/test_soa.py +++ b/tests/test_soa.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import numpy as np -import pytest import amrex.space3d as amr