Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Tests & Includes #211

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
) # 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

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable x_numba is not used.
# 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

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable bf is not used.


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

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable fab is not used.


def test_farraybox_io():
fab = amr.FArrayBox()
fab = amr.FArrayBox() # noqa

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable fab is not used.

# 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 @@
is_periodic = [0, 0, 1]
gm = Gm(box, real_box, coord, is_periodic)

pdcity = gm.periodicity()
pdcity = gm.periodicity() # noqa

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable pdcity is not used.

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 @@

# assign 3: loop through boxes and launch kernels
for mfi in mfab_device:
bx = mfi.tilebox().grow(ngv)
bx = mfi.tilebox().grow(ngv) # noqa

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable bx is not used.
marr = mfab_device.array(mfi)
marr_numba = cuda.as_cuda_array(marr)

Expand Down Expand Up @@ -208,7 +208,7 @@
# 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

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning test

This assignment to 'bx' is unnecessary as it is
redefined
before this value is used.
This assignment to 'bx' is unnecessary as it is
redefined
before this value is used.
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 @@
return mm

for mfi in mfab_device:
bx = mfi.tilebox().grow(ngv)
bx = mfi.tilebox().grow(ngv) # noqa

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning test

This assignment to 'bx' is unnecessary as it is
redefined
before this value is used.
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 @@
x[...] = 7.0

for mfi in mfab_device:
bx = mfi.tilebox().grow(ngv)
bx = mfi.tilebox().grow(ngv) # noqa

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable bx is not used.
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 @@
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

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable mfab_device is not used.
# 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_parmparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def test_parmparse():
dt = pp_param.get_real("dt")
dopml = pp_param.get_bool("do_pml")

assert dopml == True
assert dopml
assert dt == 1.0e-5
assert ncell == 100
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
17 changes: 8 additions & 9 deletions tests/test_periodicity.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

import amrex.space3d as amr


def test_periodicity():
obj = amr.Periodicity()
assert obj.is_any_periodic == False
assert obj.is_all_periodic == False
assert obj.is_periodic(0) == False
assert obj[0] == False
assert not obj.is_any_periodic
assert not obj.is_all_periodic
assert not obj.is_periodic(0)
assert not obj[0]
# with pytest.raises(IndexError):
# obj[3]

Expand All @@ -24,13 +23,13 @@ def test_periodicity_3d():
iv = amr.IntVect(1, 0, 1)
obj = amr.Periodicity(iv)
assert obj.is_any_periodic
assert obj.is_all_periodic == False
assert not obj.is_all_periodic
assert obj.is_periodic(0)
assert obj.is_periodic(1) == False
assert not obj.is_periodic(1)
assert obj.is_periodic(2)
assert obj.is_periodic[2]
assert obj[2]

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