Skip to content

Commit ee25f8a

Browse files
authored
Merge pull request #3258 from stfc/3250_complete_coverage
(closes #279) Remove Arguments.dofs and generally improve code coverage
2 parents 470e0f7 + acbc434 commit ee25f8a

23 files changed

+144
-172
lines changed

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
16) PR #3258 for #279. Removes Arguments.dofs and generally improves
2+
testing coverage.
3+
14
15) PR #3260 for #2884. Allow WHERE with imported symbols by changing
25
Ref2ArrayRangeTrans behaviour to do the validations.
36

codecov.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
removed_code_behavior: fully_covered_patch
6+

src/psyclone/core/access_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from psyclone.core.signature import Signature
4848
from psyclone.errors import InternalError
4949

50-
if TYPE_CHECKING: # pragma: no cover
50+
if TYPE_CHECKING:
5151
from psyclone.psyir.nodes import Node
5252
from psyclone.psyir.symbols import Symbol
5353

src/psyclone/gocean1p0.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,6 @@ def __init__(self, call, parent_call, check=True):
11711171
raise ParseError(f"Invalid kernel argument type. Found "
11721172
f"'{arg.argument_type}' but must be one of "
11731173
f"['grid_property', 'scalar', 'field'].")
1174-
self._dofs = []
11751174

11761175
def psyir_expressions(self):
11771176
'''
@@ -1207,13 +1206,6 @@ def find_grid_access(self):
12071206
# if the kernel requires a grid-property argument.
12081207
return None
12091208

1210-
@property
1211-
def dofs(self):
1212-
''' Currently required for invoke base class although this makes no
1213-
sense for GOcean. Need to refactor the Invoke base class and
1214-
remove the need for this property (#279). '''
1215-
return self._dofs
1216-
12171209
@property
12181210
def acc_args(self):
12191211
'''

src/psyclone/lfric.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,8 +5416,6 @@ def __init__(self, call, parent_call, check=True):
54165416
)
54175417
arg.stencil.direction_arg.varname = symbol.name
54185418

5419-
self._dofs = []
5420-
54215419
# Generate a static list of unique function-space names used
54225420
# by the set of arguments: store the mangled names as these
54235421
# are what we use at the level of an Invoke
@@ -5605,13 +5603,6 @@ def iteration_space_arg(self):
56055603
"field, a modified operator, or an unmodified field (in the case "
56065604
"of a modified scalar). None of these were found.")
56075605

5608-
@property
5609-
def dofs(self):
5610-
''' Currently required for Invoke base class although this
5611-
makes no sense for LFRic. Need to refactor the Invoke base class
5612-
and remove the need for this property (#279). '''
5613-
return self._dofs
5614-
56155606
def psyir_expressions(self):
56165607
'''
56175608
:returns: the PSyIR expressions representing this Argument list.

src/psyclone/psyGen.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ def container(self):
232232
'''
233233
return self._container
234234

235-
def __str__(self):
236-
return "PSy"
237-
238235
@property
239236
def invokes(self):
240237
''':returns: the list of invokes.
@@ -310,9 +307,6 @@ def __init__(self, alg_calls, invoke_cls, psy):
310307
self.invoke_map[my_invoke.name] = my_invoke
311308
self.invoke_list.append(my_invoke)
312309

313-
def __str__(self):
314-
return "Invokes object containing "+str(self.names)
315-
316310
@property
317311
def psy(self):
318312
'''
@@ -431,17 +425,6 @@ def __init__(self, alg_invocation, idx, schedule_class, invokes):
431425
# literals have no name
432426
pass
433427

434-
# work out the unique dofs required in this subroutine
435-
self._dofs = {}
436-
for kern_call in self._schedule.coded_kernels():
437-
dofs = kern_call.arguments.dofs
438-
for dof in dofs:
439-
if dof not in self._dofs:
440-
# Only keep the first occurrence for the moment. We will
441-
# need to change this logic at some point as we need to
442-
# cope with writes determining the dofs that are used.
443-
self._dofs[dof] = [kern_call, dofs[dof][0]]
444-
445428
def __str__(self):
446429
return self._name+"("+", ".join([str(arg) for arg in
447430
self._alg_unique_args])+")"
@@ -850,65 +833,6 @@ def args(self):
850833
base method and simply return our argument. '''
851834
return [self._field]
852835

853-
def check_vector_halos_differ(self, node):
854-
'''Helper method which checks that two halo exchange nodes (one being
855-
self and the other being passed by argument) operating on the
856-
same field, both have vector fields of the same size and use
857-
different vector indices. If this is the case then the halo
858-
exchange nodes do not depend on each other. If this is not the
859-
case then an internal error will have occured and we raise an
860-
appropriate exception.
861-
862-
:param node: a halo exchange which should exchange the same field as \
863-
self.
864-
:type node: :py:class:`psyclone.psyGen.HaloExchange`
865-
:raises GenerationError: if the argument passed is not a halo exchange.
866-
:raises GenerationError: if the field name in the halo exchange \
867-
passed in has a different name to the field \
868-
in this halo exchange.
869-
:raises GenerationError: if the field in this halo exchange is not a \
870-
vector field
871-
:raises GenerationError: if the vector size of the field in this halo \
872-
exchange is different to vector size of the \
873-
field in the halo exchange passed by argument.
874-
:raises GenerationError: if the vector index of the field in this \
875-
halo exchange is the same as the vector \
876-
index of the field in the halo exchange \
877-
passed by argument.
878-
879-
'''
880-
881-
if not isinstance(node, HaloExchange):
882-
raise GenerationError(
883-
"Internal error, the argument passed to "
884-
"HaloExchange.check_vector_halos_differ() is not "
885-
"a halo exchange object")
886-
887-
if self.field.name != node.field.name:
888-
raise GenerationError(
889-
f"Internal error, the halo exchange object passed to "
890-
f"HaloExchange.check_vector_halos_differ() has a different "
891-
f"field name '{node.field.name}' to self '{self.field.name}'")
892-
893-
if self.field.vector_size <= 1:
894-
raise GenerationError(
895-
"Internal error, HaloExchange.check_vector_halos_differ() "
896-
"a halo exchange depends on another halo exchange but the "
897-
f"vector size of field '{self.field.name}' is 1")
898-
899-
if self.field.vector_size != node.field.vector_size:
900-
raise GenerationError(
901-
f"Internal error, HaloExchange.check_vector_halos_differ() "
902-
f"a halo exchange depends on another halo exchange but the "
903-
f"vector sizes for field '{self.field.name}' differ")
904-
905-
if self.vector_index == node.vector_index:
906-
raise GenerationError(
907-
f"Internal error, HaloExchange.check_vector_halos_differ() "
908-
f"a halo exchange depends on another halo exchange but both "
909-
f"vector id's ('{self.vector_index}') of field "
910-
f"'{self.field.name}' are the same")
911-
912836
def node_str(self, colour=True):
913837
'''
914838
Returns the name of this node with (optional) control codes

src/psyclone/psyir/frontend/fparser2.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5727,9 +5727,6 @@ def _program_handler(self, node, parent):
57275727
# one) so this can't be provided as the name of the
57285728
# FileContainer.
57295729
file_container = FileContainer("None", parent=parent)
5730-
if len(node.children) == 1 and node.children[0] is None:
5731-
# We have an empty file
5732-
return file_container
57335730
self.process_nodes(file_container, node.children)
57345731
return file_container
57355732

src/psyclone/psyir/nodes/codeblock.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ def get_symbol_names(self) -> List[str]:
213213
# symbol table.
214214
for node in walk(parse_tree, Fortran2003.Directive):
215215
string_rep = node.tostr()
216-
# Directives start with a $
217-
if string_rep.lstrip()[0:2] != "!$":
218-
continue
219-
string_rep = string_rep[2:]
216+
string_rep = string_rep[string_rep.index("$"):]
220217
pattern = pattern_tools.name.get_compiled()
221218
matches = re.findall(pattern, string_rep)
222219
scope = self.scope

src/psyclone/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def pytest_addoption(parser):
8181

8282

8383
@pytest.fixture
84-
def have_graphviz():
84+
def have_graphviz(): # pragma: no-cover
8585
''' Whether or not the system has graphviz installed. This refers to
8686
the underlying system library, not the python bindings that are provided
8787
by 'import graphviz'. '''

src/psyclone/tests/domain/gocean/transformations/globalstoargs_test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838

3939
import os
4040
import pytest
41+
from psyclone.gocean1p0 import GOKern
4142
from psyclone.parse.algorithm import parse
4243
from psyclone.psyGen import PSyFactory, InvokeSchedule
4344
from psyclone.psyir.symbols import (DataSymbol, REAL_TYPE, INTEGER_TYPE,
44-
CHARACTER_TYPE, Symbol)
45+
CHARACTER_TYPE, Symbol, SymbolError)
4546
from psyclone.tests.utilities import get_invoke, make_external_module
4647
from psyclone.transformations import (KernelImportsToArguments,
4748
TransformationError)
@@ -87,6 +88,30 @@ def test_kernelimportsstoargumentstrans_no_outer_module_import():
8788
"module scope." in str(err.value))
8889

8990

91+
def test_kernelimportsstoargumentstrans_unsuccessful_get_callees(monkeypatch):
92+
''' Check that the validation produces the correct error when a
93+
get_callees method is unsuccessful.
94+
'''
95+
trans = KernelImportsToArguments()
96+
path = os.path.join(BASEPATH, "gocean1p0")
97+
_, invoke_info = parse(os.path.join(path,
98+
"single_invoke_kern_with_global.f90"),
99+
api=API)
100+
psy = PSyFactory(API).create(invoke_info)
101+
invoke = psy.invokes.invoke_list[0]
102+
kernel = invoke.schedule.coded_kernels()[0]
103+
104+
# Monkeypatch get_callees to always produce an error.
105+
def raise_error(_):
106+
raise SymbolError("some error")
107+
108+
monkeypatch.setattr(GOKern, "get_callees", raise_error)
109+
with pytest.raises(TransformationError) as err:
110+
trans.validate(kernel)
111+
assert ("Kernel 'kernel_with_global_code' contains undeclared symbol:"
112+
in str(err.value))
113+
114+
90115
def test_kernelimportstoargumentstrans_no_wildcard_import():
91116
''' Check that the transformation rejects kernels with wildcard
92117
imports. '''

0 commit comments

Comments
 (0)