Skip to content

Commit

Permalink
Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Oct 18, 2023
1 parent 755dc01 commit c974957
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 44 deletions.
5 changes: 0 additions & 5 deletions src/amrex/ArrayOfStructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Authors: Axel Huebl
License: BSD-3-Clause-LBNL
"""
from collections import namedtuple


def aos_to_numpy(self, copy=False):
Expand Down Expand Up @@ -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.")

Expand Down
4 changes: 0 additions & 4 deletions src/amrex/StructOfArrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([], [])
Expand Down Expand Up @@ -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([], [])
Expand Down
4 changes: 2 additions & 2 deletions src/amrex/space1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions src/amrex/space2d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions src/amrex/space3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_aos.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr

Expand Down Expand Up @@ -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])
Expand Down
6 changes: 4 additions & 2 deletions tests/test_array4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basefab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_basefab():
bf = amr.BaseFab_Real()
bf = amr.BaseFab_Real() # noqa


def test_basefab_to_host():
Expand Down
3 changes: 0 additions & 3 deletions tests/test_coordsys.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/test_dim3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr

Expand Down
4 changes: 2 additions & 2 deletions tests/test_farraybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_multifab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_particleContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_particleTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions tests/test_periodicity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr
Expand All @@ -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)
Expand All @@ -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)
3 changes: 0 additions & 3 deletions tests/test_podvector.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr


Expand Down
3 changes: 0 additions & 3 deletions tests/test_realbox.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/test_soa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr

Expand Down

0 comments on commit c974957

Please sign in to comment.