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

2265 rename split dyn stencil #2266

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion src/psyclone/domain/lfric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
from psyclone.domain.lfric.arg_index_to_metadata_index import \
ArgIndexToMetadataIndex
from psyclone.domain.lfric.lfric_collection import LFRicCollection
from psyclone.domain.lfric.lfric_stencil import LFRicStencil
from psyclone.domain.lfric.lfric_loop_bounds import LFRicLoopBounds



__all__ = [
'ArgOrdering',
'FunctionSpace',
Expand All @@ -78,5 +80,7 @@
'LFRicConstants',
'LFRicExtractDriverCreator',
'LFRicInvoke',
'LFRicStencil',
oakleybrunt marked this conversation as resolved.
Show resolved Hide resolved
'LFRicLoopBounds',
'LFRicSymbolTable']
'LFRicSymbolTable']

86 changes: 86 additions & 0 deletions src/psyclone/domain/lfric/lfric_stencil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -----------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this class, it seems to me we could do without it and have a NamedTuple instead:

LFRicArgStencil = namedtuple("Symbol", "name extent extent_arg direction_arg")

I say this because none of the setters do any validation. Can @rupertford, @TeranIvy or @hiker see any potential problem with doing that? (e.g. is this class likely to need significant additional functionality in future?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arporter, I think that the potential future functionality would be "more of the same" in the sense of more stencil types, but the underlying mechanism wouldn't change. If doing away with the class doesn't affect adding more stencil types then I'm fine with it!

# BSD 3-Clause License
#
# Copyright (c) 2017-2023, Science and Technology Facilities Council.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Authors R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab
# Modified I. Kavcic, A. Coughtrie, L. Turner and O. Brunt, Met Office
# Modified J. Henrichs, Bureau of Meteorology
# Modified A. B. G. Chalk and N. Nobre, STFC Daresbury Lab

''' This module contains the LFRicStencil class which provides stencil
information about a Dynamo agrument. LFRicStencil can provide the extent,
oakleybrunt marked this conversation as resolved.
Show resolved Hide resolved
algorithm argument for the extent, and the direction argument of a
stencil or set any of these properties.'''

# pylint: disable=too-many-lines

class LFRicStencil():
''' Provides stencil information about a Dynamo argument '''
oakleybrunt marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, name):
self._name = name
self._extent = None
self._extent_arg = None
self._direction_arg = None

@property
def extent(self):
'''Returns the extent of the stencil if it is known. It will be known
oakleybrunt marked this conversation as resolved.
Show resolved Hide resolved
if it is specified in the metadata.'''
return self._extent

@property
def extent_arg(self):
'''Returns the algorithm argument associated with the extent value if
extent has not been provided in the metadata.'''
return self._extent_arg

@extent_arg.setter
def extent_arg(self, value):
''' sets the extent_arg argument. '''
self._extent_arg = value

@property
def direction_arg(self):
'''returns the direction argument associated with the direction of
the stencil if the direction of the stencil is not known'''
return self._direction_arg

@direction_arg.setter
def direction_arg(self, value):
''' sets the direction_arg argument. '''
self._direction_arg = value


# ---------- Documentation utils -------------------------------------------- #
# The list of module members that we wish AutoAPI to generate
# documentation for. (See https://psyclone-ref.readthedocs.io)
__all__ = ['LFRicStencil']
48 changes: 5 additions & 43 deletions src/psyclone/dynamo0p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
LFRicArgDescriptor, KernelInterface,
LFRicCollection, LFRicConstants,
LFRicSymbolTable, LFRicInvoke,
LFRicKernCallFactory)
LFRicKernCallFactory, LFRicStencil)
from psyclone.errors import GenerationError, InternalError, FieldNotFoundError
from psyclone.f2pygen import (AllocateGen, AssignGen, CallGen, CommentGen,
DeallocateGen, DeclGen, DoGen, IfThenGen,
Expand Down Expand Up @@ -8499,43 +8499,6 @@ def check_args(call):
f"qr_arguments'")


class DynStencil():
''' Provides stencil information about a Dynamo argument '''
def __init__(self, name):
self._name = name
self._extent = None
self._extent_arg = None
self._direction_arg = None

@property
def extent(self):
'''Returns the extent of the stencil if it is known. It will be known
if it is specified in the metadata.'''
return self._extent

@property
def extent_arg(self):
'''Returns the algorithm argument associated with the extent value if
extent has not been provided in the metadata.'''
return self._extent_arg

@extent_arg.setter
def extent_arg(self, value):
''' sets the extent_arg argument. '''
self._extent_arg = value

@property
def direction_arg(self):
'''returns the direction argument associated with the direction of
the stencil if the direction of the stencil is not known'''
return self._direction_arg

@direction_arg.setter
def direction_arg(self, value):
''' sets the direction_arg argument. '''
self._direction_arg = value


class DynKernelArguments(Arguments):
'''
Provides information about Dynamo kernel call arguments
Expand Down Expand Up @@ -8573,14 +8536,14 @@ def __init__(self, call, parent_call, check=True):
if dyn_argument.descriptor.stencil:
# Create a stencil object and store a reference to it in our
# new DynKernelArgument object.
stencil = DynStencil(dyn_argument.descriptor.stencil['type'])
stencil = LFRicStencil(dyn_argument.descriptor.stencil['type'])
dyn_argument.stencil = stencil

if dyn_argument.descriptor.stencil['extent']:
raise GenerationError("extent metadata not yet supported")
# if supported we would add the following
# line. However, note there is currently no setter
# for extent in DynStencil so this would need to
# for extent in LFRicStencil so this would need to
# be added. stencil.extent =
# dyn_argument.descriptor.stencil['extent']
# An extent argument has been added.
Expand Down Expand Up @@ -9603,7 +9566,7 @@ def discontinuous(self):
def stencil(self):
'''
:returns: stencil information for this argument if it exists.
:rtype: :py:class:`psyclone.dynamo0p3.DynStencil`
:rtype: :py:class:`psyclone.domain.lfric.LFRicStencil`
'''
return self._stencil

Expand All @@ -9613,7 +9576,7 @@ def stencil(self, value):
Sets stencil information for this kernel argument.

:param value: stencil information for this argument.
:type value: :py:class:`psyclone.dynamo0p3.DynStencil`
:type value: :py:class:`psyclone.domain.lfric.LFRicStencil`

'''
self._stencil = value
Expand Down Expand Up @@ -9764,7 +9727,6 @@ def data_on_device(self, _):
'DynKern',
'FSDescriptor',
'FSDescriptors',
'DynStencil',
'DynKernelArguments',
'DynKernelArgument',
'DynACCEnterDataDirective']
Loading