Skip to content

Commit

Permalink
Restore tests to the current state in the main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
samkellerhals committed Feb 21, 2024
1 parent 407a553 commit df32186
Show file tree
Hide file tree
Showing 65 changed files with 445 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def a_stencil(
## The following type ignores are there because mypy get's confused by gtscript
def avg_stencil(in_field: Field[np.float64], out_field: Field[np.float64]): # type: ignore
with computation(PARALLEL), interval(...): # type: ignore
0.25 * (
out_field = 0.25 * (
+in_field[0, 1, 0] + in_field[0, -1, 0] + in_field[1, 0, 0] + in_field[-1, 0, 0]
)

Expand Down Expand Up @@ -356,7 +356,7 @@ def _stencil(
field_out: gtscript.Field[gtscript.IJ, np.float64],
):
with computation(FORWARD), interval(...):
pass
field_out = 1.0

return _stencil

Expand Down Expand Up @@ -420,7 +420,7 @@ def test_origin_unchanged(backend):
@gtscript.stencil(backend=backend)
def calc_damp(outp: Field[float], inp: Field[K, float]):
with computation(FORWARD), interval(...):
pass
outp = inp

outp = gt_storage.ones(
backend=backend,
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_permute_axes():
@gtscript.stencil(backend="numpy")
def calc_damp(outp: Field[float], inp: Field[K, float]):
with computation(FORWARD), interval(...):
pass
outp = inp

outp = gt_storage.ones(
backend="numpy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _register_decorator(actual_func):
@register
def copy_stencil(field_a: Field3D, field_b: Field3D):
with computation(PARALLEL), interval(...):
field_a[0, 0, 0]
field_b = field_a[0, 0, 0]


@gtscript.function
Expand All @@ -81,7 +81,7 @@ def afunc(b):
@register
def arithmetic_ops(field_a: Field3D, field_b: Field3D):
with computation(PARALLEL), interval(...):
(((((field_b + 42.0) - 42.0) * +42.0) / -42.0) % 42.0) ** 2
field_a = (((((field_b + 42.0) - 42.0) * +42.0) / -42.0) % 42.0) ** 2


@register
Expand All @@ -98,7 +98,16 @@ def data_types(
float64_field: gtscript.Field[np.float64],
):
with computation(PARALLEL), interval(...):
pass
bool_field = True
npbool_field = False
int_field = 2147483647
int8_field = 127
int16_field = 32767
int32_field = 2147483647
int64_field = 9223372036854775807
float_field = 37.5
float32_field = 37.5
float64_field = 37.5


@register
Expand Down Expand Up @@ -144,15 +153,17 @@ def native_functions(field_a: Field3D, field_b: Field3D):
@register
def copy_stencil_plus_one(field_a: Field3D, field_b: Field3D):
with computation(PARALLEL), interval(...):
field_a[0, 0, 0] + 1
field_b = field_a[0, 0, 0] + 1


@register
def runtime_if(field_a: Field3D, field_b: Field3D):
with computation(BACKWARD), interval(...):
if field_a > 0.0:
field_b = -1
field_a = -field_a
else:
field_b = 1
field_a = field_a


Expand All @@ -164,7 +175,7 @@ def simple_horizontal_diffusion(in_field: Field3D, coeff: Field3D, out_field: Fi
)
flx_field = lap_field[1, 0, 0] - lap_field[0, 0, 0]
fly_field = lap_field[0, 1, 0] - lap_field[0, 0, 0]
in_field[0, 0, 0] - coeff[0, 0, 0] * (
out_field = in_field[0, 0, 0] - coeff[0, 0, 0] * (
flx_field[0, 0, 0] - flx_field[-1, 0, 0] + fly_field[0, 0, 0] - fly_field[0, -1, 0]
)

Expand Down Expand Up @@ -276,7 +287,7 @@ def horizontal_diffusion(in_field: Field3D, out_field: Field3D, coeff: Field3D):
flx_field = 0 if (res * (in_field[1, 0, 0] - in_field[0, 0, 0])) > 0 else res
res = lap_field[0, 1, 0] - lap_field[0, 0, 0]
fly_field = 0 if (res * (in_field[0, 1, 0] - in_field[0, 0, 0])) > 0 else res
in_field[0, 0, 0] - coeff[0, 0, 0] * (
out_field = in_field[0, 0, 0] - coeff[0, 0, 0] * (
flx_field[0, 0, 0] - flx_field[-1, 0, 0] + fly_field[0, 0, 0] - fly_field[0, -1, 0]
)

Expand All @@ -285,34 +296,35 @@ def horizontal_diffusion(in_field: Field3D, out_field: Field3D, coeff: Field3D):
def large_k_interval(in_field: Field3D, out_field: Field3D):
with computation(PARALLEL):
with interval(0, 6):
pass
out_field = in_field
with interval(6, -10): # this stage will only run if field has more than 16 elements
in_field + 1
out_field = in_field + 1
with interval(-10, None):
pass
out_field = in_field


@register
def single_level_with_offset(in_field: Field3D, out_field: Field3D):
with computation(PARALLEL), interval(1, 2):
pass
out_field = in_field


@register
def form_land_mask(in_field: Field3D, mask: gtscript.Field[np.bool_]):
with computation(PARALLEL), interval(...):
pass
mask = in_field >= 0


@register
def set_inner_as_kord(a4_1: Field3D, a4_2: Field3D, a4_3: Field3D, extm: Field3DBool):
with computation(PARALLEL), interval(...):
diff_23 = 0.0
if extm and extm[0, 0, -1]:
a4_2 = a4_1
elif extm and extm[0, 0, 1]:
a4_3 = a4_1
else:
a4_2 - a4_3
diff_23 = a4_2 - a4_3


@register
Expand All @@ -336,22 +348,22 @@ def local_var_inside_nested_conditional(in_storage: Field3D, out_storage: Field3
def multibranch_param_conditional(in_field: Field3D, out_field: Field3D, c: float):
with computation(PARALLEL), interval(...):
if c > 0.0:
in_field + in_field[1, 0, 0]
out_field = in_field + in_field[1, 0, 0]
elif c < -1.0:
in_field - in_field[1, 0, 0]
out_field = in_field - in_field[1, 0, 0]
else:
pass
out_field = in_field


@register(externals={"DO_SOMETHING": False})
def allow_empty_computation(in_field: Field3D, out_field: Field3D):
from __externals__ import DO_SOMETHING

with computation(FORWARD), interval(...):
pass
out_field = in_field
with computation(PARALLEL), interval(...):
if __INLINED(DO_SOMETHING):
abs(in_field)
out_field = abs(in_field)


@register(externals={"PHYS_TEND": False}, name="unused_optional_field")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_lazy_stencil(backend):
@gtscript.lazy_stencil(backend=backend)
def definition(field_a: gtscript.Field[np.float_], field_b: gtscript.Field[np.float_]):
with computation(PARALLEL), interval(...):
pass
field_a = field_b


@pytest.mark.parametrize("backend", ALL_BACKENDS)
Expand All @@ -86,7 +86,7 @@ def test_stage_without_effect(backend):
@gtscript.stencil(backend=backend)
def definition(field_a: gtscript.Field[np.float_]):
with computation(PARALLEL), interval(...):
pass
field_c = 0.0


def test_ignore_np_errstate():
Expand All @@ -113,14 +113,14 @@ def divide_by_zero(field_a: gtscript.Field[np.float_]):
def test_stencil_without_effect(backend):
def definition1(field_in: gtscript.Field[np.float_]):
with computation(PARALLEL), interval(...):
pass
tmp = 0.0

def definition2(f_in: gtscript.Field[np.float_]):
from __externals__ import flag

with computation(PARALLEL), interval(...):
if __INLINED(flag):
pass
B = f_in

stencil1 = gtscript.stencil(backend, definition1)
stencil2 = gtscript.stencil(backend, definition2, externals={"flag": False})
Expand Down Expand Up @@ -150,14 +150,14 @@ def test_stage_merger_induced_interval_block_reordering(backend):
def stencil(field_in: gtscript.Field[np.float_], field_out: gtscript.Field[np.float_]):
with computation(BACKWARD):
with interval(-2, -1): # block 1
pass
field_out = field_in
with interval(0, -2): # block 2
pass
field_out = field_in
with computation(BACKWARD):
with interval(-1, None): # block 3
2 * field_in
field_out = 2 * field_in
with interval(0, -1): # block 4
3 * field_in
field_out = 3 * field_in

stencil(field_in, field_out)

Expand All @@ -181,9 +181,9 @@ def stencil(

with computation(PARALLEL):
with interval(0, 1):
tmp[1, 0, 0] + field_1d[1]
field_3d = tmp[1, 0, 0] + field_1d[1]
with interval(1, None):
tmp[-1, 0, 0]
field_3d = tmp[-1, 0, 0]

full_shape = (6, 6, 6)
aligned_index = (1, 1, 0)
Expand Down Expand Up @@ -222,7 +222,7 @@ def copy_2to3(
):
with computation(PARALLEL), interval(...):
if cond > 0.0:
pass
outp = inp

inp = np.random.randn(10, 10)
outp = np.random.randn(10, 10, 10)
Expand Down Expand Up @@ -253,7 +253,7 @@ def copy_2to3(
):
with computation(FORWARD), interval(...):
if cond > 0.0:
pass
outp = inp

inp = np.random.randn(10, 10)
outp = np.random.randn(10, 10, 10)
Expand Down Expand Up @@ -305,7 +305,7 @@ def stencil(
mat_field: gtscript.Field[FLOAT64_MAT22],
):
with computation(PARALLEL), interval(...):
vec_field[0, 0, 0][0] + vec_field[0, 0, 0][1]
tmp = vec_field[0, 0, 0][0] + vec_field[0, 0, 0][1]

with computation(FORWARD):
with interval(0, 1):
Expand Down Expand Up @@ -357,7 +357,7 @@ def stencil(
out_field: gtscript.Field[np.float64],
):
with computation(PARALLEL), interval(...):
in_field * parameter
out_field = in_field * parameter


@pytest.mark.parametrize("backend", ALL_BACKENDS)
Expand All @@ -372,7 +372,7 @@ def stencil_ij(
index_field: gtscript.Field[gtscript.IJ, int],
):
with computation(FORWARD), interval(...):
in_field[0, 0, 1] + in_field[0, 0, index_field + 1]
out_field = in_field[0, 0, 1] + in_field[0, 0, index_field + 1]
index_field = index_field + 1

@gtscript.stencil(backend=backend)
Expand All @@ -382,7 +382,7 @@ def stencil_ijk(
index_field: gtscript.Field[int],
):
with computation(PARALLEL), interval(...):
in_field[0, 0, 1] + in_field[0, 0, index_field + 1]
out_field = in_field[0, 0, 1] + in_field[0, 0, index_field + 1]


@pytest.mark.parametrize("backend", ALL_BACKENDS)
Expand All @@ -400,13 +400,13 @@ def stencil(
):
with computation(FORWARD), interval(0, -1):
if pe2[0, 0, 1] <= pe1[0, 0, lev]:
qin[0, 0, 1]
qout = qin[0, 0, 1]
else:
qsum = pe1[0, 0, lev + 1] - pe2[0, 0, lev]
while pe1[0, 0, lev + 1] < pe2[0, 0, 1]:
qsum += qin[0, 0, lev] / (pe2[0, 0, 1] - pe1[0, 0, lev])
lev = lev + 1
qsum / (pe2[0, 0, 1] - pe2)
qout = qsum / (pe2[0, 0, 1] - pe2)


@pytest.mark.parametrize("backend", ALL_BACKENDS)
Expand All @@ -433,9 +433,9 @@ def stencil(
with computation(PARALLEL), interval(...):
cond = True
if cond[0, -1, 0] or cond[0, 0, 0]:
pass
outp = 1.0
else:
pass
outp = 0.0

outp = gt_storage.zeros(
shape=(10, 10, 10), backend=backend, aligned_index=(0, 0, 0), dtype=float
Expand Down Expand Up @@ -482,7 +482,7 @@ def stencil(
index: int,
):
with computation(PARALLEL), interval(...):
input_field[0, 0, 0][index]
output_field = input_field[0, 0, 0][index]

aligned_index = (0, 0, 0)
full_shape = (1, 1, 2)
Expand All @@ -506,7 +506,7 @@ def stencil_i(
output_field: gtscript.Field[gtscript.IJK, np.int32],
):
with computation(PARALLEL), interval(...):
input_field[1, 0, 0]
output_field = input_field[1, 0, 0]

input_field = gt_storage.ones(
backend=backend, aligned_index=(0, 0, 0), shape=(1, 1, 1), dtype=np.int32
Expand All @@ -525,7 +525,7 @@ def stencil_k(
output_field: gtscript.Field[gtscript.IJK, np.int32],
):
with computation(PARALLEL), interval(...):
input_field[0, 0, 1]
output_field = input_field[0, 0, 1]

input_field = gt_storage.ones(
backend=backend, aligned_index=(0, 0, 0), shape=(1, 1, 1), dtype=np.int32
Expand All @@ -543,7 +543,7 @@ def test_origin_k_fields(backend):
@gtscript.stencil(backend=backend, rebuild=True)
def k_to_ijk(outp: Field[np.float64], inp: Field[gtscript.K, np.float64]):
with computation(PARALLEL), interval(...):
pass
outp = inp

origin = {"outp": (0, 0, 1), "inp": (2,)}
domain = (2, 2, 8)
Expand Down Expand Up @@ -575,8 +575,9 @@ def test_pruned_args_match(backend):
@gtscript.stencil(backend=backend)
def test(out: Field[np.float64], inp: Field[np.float64]):
with computation(PARALLEL), interval(...):
out = 0.0
with horizontal(region[I[0] - 1, J[0] - 1]):
pass
out = inp

inp = gt_storage.zeros(
backend=backend, aligned_index=(0, 0, 0), shape=(2, 2, 2), dtype=np.float64
Expand Down
Loading

0 comments on commit df32186

Please sign in to comment.