diff --git a/loki/transformations/parallel/tests/test_field_api.py b/loki/transformations/parallel/tests/test_field_api.py index 5e08f9c4c..267c43e91 100644 --- a/loki/transformations/parallel/tests/test_field_api.py +++ b/loki/transformations/parallel/tests/test_field_api.py @@ -7,14 +7,14 @@ import pytest -from loki import Subroutine, Module, Dimension +from loki import Subroutine, Dimension from loki.frontend import available_frontends, OMNI from loki.ir import nodes as ir, FindNodes from loki.expression import symbols as sym from loki.scope import Scope from loki.transformations.parallel import ( - remove_field_api_view_updates, add_field_api_view_updates, get_field_type, - field_get_device_data, FieldAPITransferType + remove_field_api_view_updates, add_field_api_view_updates, + get_field_type, field_get_device_data, FieldAPITransferType ) from loki.types import BasicType, SymbolAttributes from loki.logging import WARNING @@ -198,4 +198,3 @@ def test_field_get_device_data(): assert get_dev_data_call.name.parent == fptr with pytest.raises(TypeError): _ = field_get_device_data(fptr, dev_ptr, "none_transfer_type", scope) - diff --git a/loki/transformations/parallel/tests/test_openmp_region.py b/loki/transformations/parallel/tests/test_openmp_region.py index e9a05705b..7e30d4ac0 100644 --- a/loki/transformations/parallel/tests/test_openmp_region.py +++ b/loki/transformations/parallel/tests/test_openmp_region.py @@ -262,11 +262,11 @@ def test_remove_firstprivate_copies(frontend): @pytest.mark.parametrize('frontend', available_frontends( skip=[(OMNI, 'OMNI needs full type definitions for derived types')] )) -def test_add_firstprivate_copies(tmp_path, frontend): +def test_add_firstprivate_copies(frontend): """ A simple test for :any:`add_firstprivate_copies` """ - + fcode = """ subroutine test_add_openmp_loop(ydgeom, state, arr) use geom_mod, only: geom_type @@ -312,7 +312,7 @@ def test_add_firstprivate_copies(tmp_path, frontend): assert str(calls[0].name).startswith('state%') assert calls[1].arguments[0].parent == 'state' assert len(FindNodes(ir.Loop).visit(routine.body)) == 2 - + # Put the explicit firstprivate copies back in add_firstprivate_copies( routine=routine, fprivate_map=fprivate_map diff --git a/loki/transformations/sanitise/tests/test_associates.py b/loki/transformations/sanitise/tests/test_associates.py index 62b8085f9..d1e3ff7be 100644 --- a/loki/transformations/sanitise/tests/test_associates.py +++ b/loki/transformations/sanitise/tests/test_associates.py @@ -7,7 +7,7 @@ import pytest -from loki import BasicType, Subroutine, Module +from loki import BasicType, Subroutine from loki.expression import symbols as sym from loki.frontend import available_frontends, OMNI from loki.ir import nodes as ir, FindNodes @@ -447,7 +447,7 @@ def test_resolve_associates_stmt_func(frontend): Test scope management for stmt funcs, either as :any:`ProcedureSymbol` or :any:`DeferredTypeSymbol`. """ - fcode = f""" + fcode = """ subroutine test_associates_stmt_func(ydcst, a, b) use yomcst, only: tcst implicit none diff --git a/loki/transformations/single_column/tests/test_scc_vector.py b/loki/transformations/single_column/tests/test_scc_vector.py index 96378d869..6b95d7142 100644 --- a/loki/transformations/single_column/tests/test_scc_vector.py +++ b/loki/transformations/single_column/tests/test_scc_vector.py @@ -624,7 +624,7 @@ def test_scc_devector_section_special_case(frontend, horizontal, vertical, block # Check that all else-bodies have been wrapped else_bodies = conditional.else_bodies - assert(len(else_bodies) == 3) + assert len(else_bodies) == 3 for body in else_bodies: assert isinstance(body[0], ir.Comment) assert isinstance(body[1], ir.Loop) diff --git a/loki/transformations/tests/test_loop_blocking.py b/loki/transformations/tests/test_loop_blocking.py index 0ea3133a6..176893129 100644 --- a/loki/transformations/tests/test_loop_blocking.py +++ b/loki/transformations/tests/test_loop_blocking.py @@ -9,8 +9,15 @@ import pytest import numpy as np -from loki import available_frontends, Subroutine, pragmas_attached, find_driver_loops, Loop, fgen, \ - ir, FindNodes, jit_compile, clean_test, FindVariables, Array +from loki import Subroutine +from loki.build import jit_compile, clean_test +from loki.expression import Array +from loki.frontend import available_frontends +from loki.ir import ( + nodes as ir, FindNodes, FindVariables, pragmas_attached +) + +from loki.transformations.utilities import find_driver_loops from loki.transformations.loop_blocking import split_loop, block_loop_arrays @@ -43,16 +50,17 @@ def test_1d_splitting(tmp_path, frontend, block_size, n): loops = FindNodes(ir.Loop).visit(routine.ir) num_loops = len(loops) num_vars = len(routine.variable_map) - with pragmas_attached(routine, Loop): - loops = find_driver_loops(routine.body, - targets=None) - splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) + with pragmas_attached(routine, ir.Loop): + loops = find_driver_loops(routine.body, targets=None) + split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) filepath = tmp_path / (f'{routine.name}_{frontend}.f90') function = jit_compile(routine, filepath=filepath, objname=routine.name) @@ -93,16 +101,17 @@ def test_1d_splitting_multi_var(tmp_path, frontend, block_size, n): loops = FindNodes(ir.Loop).visit(routine.ir) num_loops = len(loops) num_vars = len(routine.variable_map) - with pragmas_attached(routine, Loop): - loops = find_driver_loops(routine.body, - targets=None) - splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) + with pragmas_attached(routine, ir.Loop): + loops = find_driver_loops(routine.body, targets=None) + split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) filepath = tmp_path / (f'{routine.name}_{frontend}.f90') function = jit_compile(routine, filepath=filepath, objname=routine.name) @@ -141,16 +150,17 @@ def test_2d_splitting(tmp_path, frontend, block_size, n): loops = FindNodes(ir.Loop).visit(routine.ir) num_loops = len(loops) num_vars = len(routine.variable_map) - with pragmas_attached(routine, Loop): - loops = find_driver_loops(routine.body, - targets=None) - splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) + with pragmas_attached(routine, ir.Loop): + loops = find_driver_loops(routine.body, targets=None) + split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) filepath = tmp_path / (f'{routine.name}_{frontend}.f90') function = jit_compile(routine, filepath=filepath, objname=routine.name) @@ -191,16 +201,17 @@ def test_3d_splitting(tmp_path, frontend, block_size, n): loops = FindNodes(ir.Loop).visit(routine.ir) num_loops = len(loops) num_vars = len(routine.variable_map) - with pragmas_attached(routine, Loop): - loops = find_driver_loops(routine.body, - targets=None) - splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) + with pragmas_attached(routine, ir.Loop): + loops = find_driver_loops(routine.body, targets=None) + split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) filepath = tmp_path / (f'{routine.name}_{frontend}.f90') function = jit_compile(routine, filepath=filepath, objname=routine.name) @@ -249,7 +260,7 @@ def test_1d_blocking(tmp_path, frontend, block_size, n): """ routine = Subroutine.from_source(fcode, frontend=frontend) loops = FindNodes(ir.Loop).visit(routine.ir) - with pragmas_attached(routine, Loop): + with pragmas_attached(routine, ir.Loop): loops = find_driver_loops(routine.body, targets=None) @@ -258,10 +269,12 @@ def test_1d_blocking(tmp_path, frontend, block_size, n): splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) num_vars = len(routine.variable_map) blocking_indices = ['i'] @@ -308,7 +321,7 @@ def test_1d_blocking_multi_intent(tmp_path, frontend, block_size, n): """ routine = Subroutine.from_source(fcode, frontend=frontend) loops = FindNodes(ir.Loop).visit(routine.ir) - with pragmas_attached(routine, Loop): + with pragmas_attached(routine, ir.Loop): loops = find_driver_loops(routine.body, targets=None) @@ -316,11 +329,12 @@ def test_1d_blocking_multi_intent(tmp_path, frontend, block_size, n): num_vars = len(routine.variable_map) splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" - + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) num_vars = len(routine.variable_map) blocking_indices = ['i'] @@ -371,16 +385,17 @@ def test_2d_blocking(tmp_path, frontend, block_size, n): loops = FindNodes(ir.Loop).visit(routine.ir) num_loops = len(loops) num_vars = len(routine.variable_map) - with pragmas_attached(routine, Loop): - loops = find_driver_loops(routine.body, - targets=None) + with pragmas_attached(routine, ir.Loop): + loops = find_driver_loops(routine.body, targets=None) splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) num_vars = len(routine.variable_map) blocking_indices = ['i'] @@ -406,7 +421,6 @@ def test_2d_blocking(tmp_path, frontend, block_size, n): clean_test(filepath) - @pytest.mark.parametrize('frontend', available_frontends()) @pytest.mark.parametrize('block_size', [117]) @pytest.mark.parametrize('n', [500]) @@ -431,16 +445,17 @@ def test_3d_blocking(tmp_path, frontend, block_size, n): loops = FindNodes(ir.Loop).visit(routine.ir) num_loops = len(loops) num_vars = len(routine.variable_map) - with pragmas_attached(routine, Loop): - loops = find_driver_loops(routine.body, - targets=None) + with pragmas_attached(routine, ir.Loop): + loops = find_driver_loops(routine.body, targets=None) splitting_vars, inner_loop, outer_loop = split_loop(routine, loops[0], block_size) loops = FindNodes(ir.Loop).visit(routine.ir) - assert len( - loops) == num_loops + 1, f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" - assert len( - routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, f"Total number of variables after loop splitting is: {len(routine.variable_map)} but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + assert len(loops) == num_loops + 1, \ + f"Total number of loops transformation is: {len(loops)} but expected {num_loops + 1}" + assert len(routine.variable_map) == num_vars + LOKI_LOOP_SLIT_VAR_ADDITION, ( + f"Total number of variables after loop splitting is: {len(routine.variable_map)} " + f"but expected {num_vars + LOKI_LOOP_SLIT_VAR_ADDITION}" + ) num_vars = len(routine.variable_map) blocking_indices = ['i'] diff --git a/loki/transformations/tests/test_utilities.py b/loki/transformations/tests/test_utilities.py index 5ccfcaa99..ff27b4ea8 100644 --- a/loki/transformations/tests/test_utilities.py +++ b/loki/transformations/tests/test_utilities.py @@ -394,7 +394,7 @@ def test_transform_utilites_get_loop_bounds(frontend, tmp_path): y = Dimension(name='y', size='n', index='i', bounds=('a', 'b')) z = Dimension(name='y', size='n', index='i', bounds=('dim%a', 'dim%b')) - start, end = get_loop_bounds(routine, x) + start, end = get_loop_bounds(routine, x) # pylint: disable=unbalanced-tuple-unpacking assert isinstance(start, sym.Scalar) assert start.type.dtype == BasicType.INTEGER assert start.type.intent == 'in' @@ -403,10 +403,10 @@ def test_transform_utilites_get_loop_bounds(frontend, tmp_path): assert end.type.intent == 'in' with pytest.raises(RuntimeError): - _, _ = get_loop_bounds(routine, y) + _, _ = get_loop_bounds(routine, y) # pylint: disable=unbalanced-tuple-unpacking # Test type-bound symbol resolution - start, end = get_loop_bounds(routine, z) + start, end = get_loop_bounds(routine, z) # pylint: disable=unbalanced-tuple-unpacking assert isinstance(start, sym.Scalar) assert start.type.dtype == BasicType.INTEGER assert start.type.kind == '8' diff --git a/loki/transformations/transpile/tests/test_sdfg.py b/loki/transformations/transpile/tests/test_sdfg.py index af568f449..d214db008 100644 --- a/loki/transformations/transpile/tests/test_sdfg.py +++ b/loki/transformations/transpile/tests/test_sdfg.py @@ -7,7 +7,6 @@ import importlib import itertools -from shutil import rmtree from pathlib import Path import numpy as np import pytest