Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
a9f4f6f
#1312: starting on adding the metadata for arrays
mo-lottieturner Jun 12, 2023
721e7eb
#1312 missed a name change oops
mo-lottieturner Jun 12, 2023
694dd10
#1312 list in test file needed to be updated
mo-lottieturner Jun 12, 2023
fffce7e
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 12, 2023
f866583
#1312 adding tests, some not yet working
mo-lottieturner Jun 14, 2023
f18c0eb
#1312 making more tests work and adding LFRicArrayArgs
mo-lottieturner Jun 15, 2023
e240d71
#1312 more test changes
mo-lottieturner Jun 15, 2023
eb1e9fc
#1312 more changes for tests
mo-lottieturner Jun 16, 2023
6285ad1
#1312 removing lfric_array_args and relevant tests as was getting ahe…
mo-lottieturner Jun 19, 2023
a79104a
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 19, 2023
705d38e
#1312 adding metadata in the new style
mo-lottieturner Jun 20, 2023
c3f45a5
#1312 changes in new metadata
mo-lottieturner Jun 20, 2023
bc4bbc0
#1312 removing unneeded commmented out code
mo-lottieturner Jun 20, 2023
7ca546c
#1312 changing get_vector_length to get_array_dimension
mo-lottieturner Jun 21, 2023
32db8f5
#1312 test for incorrect operator added
mo-lottieturner Jun 21, 2023
aeebec2
#1312 tidying up mistakes and pylint
mo-lottieturner Jun 22, 2023
d54e65b
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 22, 2023
8fb098a
#1312 temp hopeful fix for get_array_dimension
mo-lottieturner Jun 26, 2023
5972289
1312 reverting changes to get_array_dimension
mo-lottieturner Jun 28, 2023
a1c0774
#1312: *facepalm*
mo-lottieturner Jun 29, 2023
f07e02a
#1312 more facepalming (should work now!)
mo-lottieturner Jun 29, 2023
0c2bcb8
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 29, 2023
dca477d
#1312 writing more tests
mo-lottieturner Jul 6, 2023
9ee4fe0
#1312 returning get_array_dimensions to get_vector_length in preparat…
mo-lottieturner Sep 25, 2023
cc0ca8b
#1312 removing name from modifier list and reinstating previous copyr…
mo-lottieturner Sep 25, 2023
c9e7357
#1312 cleaning up pylint &c
mo-lottieturner Sep 25, 2023
2e442ed
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Sep 25, 2023
961c519
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Sep 26, 2023
cac55c8
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jan 18, 2024
5433b4f
#1312 DynKernMetadata -> LFRicKernMetadata, plus labelling untested l…
mo-lottieturner Jan 18, 2024
255113d
#1312 removing ParseError that is impossible to trigger
mo-lottieturner Jan 18, 2024
2e7b8ef
#1312 some tidying and adding a new file for the tests
mo-lottieturner Jan 19, 2024
6927e3b
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jan 23, 2024
e8da6d0
#1312 uncommenting section and distinguising array_size (prev array_n…
mo-lottieturner Jan 23, 2024
0400ae0
#1312 missed one
mo-lottieturner Jan 23, 2024
d9f4f60
#1312 forgot some brackets!
mo-lottieturner Jan 23, 2024
2a05865
#1312 pycodestyle changes
mo-lottieturner Jan 23, 2024
e42c51b
#1312 finally managed to get all but one of the array_arg_metadata te…
mo-lottieturner Feb 2, 2024
351c4d1
#1312 commenting out non-working test to check nothing else is broken
mo-lottieturner Feb 2, 2024
5abb56f
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 2, 2024
2e03912
#1312 missing ParseError import
mo-lottieturner Feb 5, 2024
d0fe57c
#1312 more fixing for tests + adding name to file
mo-lottieturner Feb 5, 2024
e12aefa
#1312 tidying for pylint and pycodestyle
mo-lottieturner Feb 5, 2024
0f7272b
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 5, 2024
d40d01b
#1312 adding test for get_array_ndims
mo-lottieturner Feb 5, 2024
fe4baf9
#1312 adding test for the array_ndims setter
mo-lottieturner Feb 5, 2024
0d2eae6
#1312 fixing fortran_string test
mo-lottieturner Feb 6, 2024
db64978
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 6, 2024
9fa6093
1312 tidying of comments and strings
mo-lottieturner Feb 6, 2024
23b4b25
#1312 removing unused code
mo-lottieturner Feb 6, 2024
5df7abb
#1312 adding test for get_array_dims ParseError
mo-lottieturner Feb 6, 2024
2223df2
#1312 expanding check_datatype to test gh_integer and gh_logical
mo-lottieturner Feb 6, 2024
8d2a37a
#1312 changes for pylint and pycodestyle
mo-lottieturner Feb 6, 2024
c530e69
#1312 removing unnecessary 'for' loops for pylint
mo-lottieturner Feb 6, 2024
311b31c
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 7, 2024
9d75b5e
#1312 adding flags to where docs need adding to
mo-lottieturner Feb 7, 2024
0cdb2fc
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner Feb 7, 2024
d642345
#1312 more docs changes
mo-lottieturner Feb 7, 2024
e24d286
#1312 more docs changes
mo-lottieturner Feb 7, 2024
e9ddb47
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 7, 2024
5867a30
#1312 clearing up of flags addressed
mo-lottieturner Feb 7, 2024
b40e7da
#1312 expanding on the Data Types and precision table, plus changing …
mo-lottieturner Feb 7, 2024
996a0a3
#1312 adding final bits of documentation
mo-lottieturner Feb 8, 2024
b978fe1
#1312 adding a modifier line that slipped through the cracks@
mo-lottieturner Feb 9, 2024
59e272e
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 20, 2024
e571bc1
#1312 space fixing
mo-lottieturner May 21, 2024
48f72bd
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner May 21, 2024
9243f29
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner May 21, 2024
6857e55
#1312 removing backslashes in comments from lfric_arg_descriptor.py
mo-lottieturner May 21, 2024
c7d4ab3
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner May 21, 2024
901ea74
#1312 merging lines in table and adding missing array mention
mo-lottieturner May 21, 2024
5f4fda5
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner May 23, 2024
335205c
#1312 including arrays in some missed spots in the docs
mo-lottieturner May 23, 2024
275b755
#1312 removing NRANKS, hopefully I got all of them
mo-lottieturner May 30, 2024
038e0d6
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner May 30, 2024
8f98f7f
#1312 line length is 79 characters not 80
mo-lottieturner May 30, 2024
5240679
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner May 30, 2024
bedf340
#1312 removing unused ParseError
mo-lottieturner May 30, 2024
51358d3
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 11, 2024
8acfa80
Merge branch 'master' into 1312_metadata_for_arrays
arporter Jun 12, 2024
7134c95
#1312 review changes on user guide
mo-lottieturner Jun 18, 2024
be295e5
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 21, 2024
288f7b2
#1312 lfric_constants review comment
mo-lottieturner Jun 25, 2024
8c82811
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Jun 25, 2024
7d03e9a
#1312 changing gh_array to gh_scalar_array
mo-lottieturner Jun 25, 2024
e8bbc73
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner Jun 25, 2024
62c648d
#1312 ArrayArgMetadata -> ScalarArrayArgMetadata, some review changes…
mo-lottieturner Jun 25, 2024
b22d45e
#1312 review changes in lfric_arg_descriptor
mo-lottieturner Jun 25, 2024
8f88377
#1312 pycodestyle change
mo-lottieturner Jun 25, 2024
21f2914
#1312 forgot to change a test to match
mo-lottieturner Jun 25, 2024
88c5135
#1312 more changes from review comments
mo-lottieturner Aug 23, 2024
6ad8c10
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Aug 23, 2024
9434c8d
#1312 pylinting
mo-lottieturner Aug 23, 2024
dbfb013
#1312 more pylinting
mo-lottieturner Aug 27, 2024
67a9e91
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Oct 18, 2024
02d8221
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Feb 26, 2025
81d076c
#1312 fixing tests
mo-lottieturner Feb 26, 2025
fe87718
Revert "#1312 fixing tests"
mo-lottieturner Feb 26, 2025
47c68b0
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner Feb 26, 2025
359d4de
#1312 fixing tests (in 2/3 files)
mo-lottieturner Feb 26, 2025
0652266
#1312 commenting out failing tests to see code coverage
mo-lottieturner Feb 26, 2025
433b385
#1312 pycodestyle fixes
mo-lottieturner Feb 26, 2025
ad08064
#1312 fixing final test file test_get_array_ndims
mo-lottieturner Feb 26, 2025
6332d7e
#1312 line length
mo-lottieturner Feb 26, 2025
738bad3
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Mar 25, 2025
e0899d5
#1312 removing an error and its test that can't be triggered
mo-lottieturner Mar 25, 2025
180c0ae
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner Apr 1, 2025
0cbad6c
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner May 13, 2025
0a81360
Merge branch 'master' into 1312_metadata_for_arrays
arporter May 21, 2025
5aeb092
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 3, 2025
7328648
#1312: fix table of datatypes
mo-alistairp Jun 3, 2025
0b740e1
#1312: Update LFRic array names to ScalarArray
mo-alistairp Jun 5, 2025
de5ba1d
#1312: lint fix
mo-alistairp Jun 5, 2025
df5816b
#1312: Update LFRic array tests to be ScalarArray
mo-alistairp Jun 5, 2025
b8ac6c1
#1312: Change array size to array rank
mo-alistairp Jun 6, 2025
e00f0d1
#1312: lint fix
mo-alistairp Jun 6, 2025
51a618d
#1312: Fix test
mo-alistairp Jun 6, 2025
e0cfec0
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 9, 2025
398a867
#1312: Rename to scalar_array_arg_metadata
mo-alistairp Jun 9, 2025
2cbd2d0
#1312: Rename scalar array test
mo-alistairp Jun 9, 2025
37ff3bf
#1312: test the scalar array setter
mo-alistairp Jun 12, 2025
fdeb70f
#1312: fix syntax
mo-alistairp Jun 12, 2025
7989283
#1312: fix type comparison
mo-alistairp Jun 12, 2025
2d4e0d3
#1312: lint fix
mo-alistairp Jun 12, 2025
17ef14e
#1312: Fix test
mo-alistairp Jun 12, 2025
2e7b7ca
#1312: fix test
mo-alistairp Jun 12, 2025
d0fa615
#1312: Add print statements to diagnose
mo-alistairp Jun 12, 2025
b652b74
#1312: temporarily remove test
mo-alistairp Jun 12, 2025
a976ad8
#1312: test fix for scalar array tests
mo-alistairp Jun 13, 2025
249229b
#1312: revert changes
mo-alistairp Jun 13, 2025
2cbdd86
#1312: fix test
mo-alistairp Jun 13, 2025
c8991cd
#1312: fix setter in scalar array tests
mo-alistairp Jun 13, 2025
af2b0fa
#1312: convert error into string
mo-alistairp Jun 13, 2025
03cbd74
#1312: change class name in test
mo-alistairp Jun 13, 2025
c3f38ac
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 13, 2025
e033522
#1312: update text to ScalarArray
mo-alistairp Jun 16, 2025
1f64126
#1312: fix ScalarArray test bug
mo-alistairp Jun 16, 2025
3ecb824
#1312: fix ScalarArray error handling
mo-alistairp Jun 16, 2025
8b2127b
#1312: lint fix
mo-alistairp Jun 16, 2025
f329bac
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 16, 2025
fd16bf7
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 24, 2025
8477d5a
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 24, 2025
dc63686
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 25, 2025
ecac860
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jun 26, 2025
7893310
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 1, 2025
fa1c1df
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 8, 2025
8dbc183
#1312: fix typo
mo-alistairp Jul 17, 2025
82118c0
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 17, 2025
ceca33c
#1312: add typehinting
mo-alistairp Jul 17, 2025
2f55dc4
#1312: Import Fparser and fix lint
mo-alistairp Jul 17, 2025
7a75df5
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 17, 2025
f6bc943
#1312: Remove typing module dependence
mo-alistairp Jul 17, 2025
59e7d02
#1312: Reintroduce typing for union
mo-alistairp Jul 17, 2025
98dfa59
#1312: change raises text
mo-alistairp Jul 17, 2025
df2ca5a
#1312: revert common_meta_arg_metadata
mo-alistairp Jul 17, 2025
1a140a9
#1312: update api to LFRic
mo-alistairp Jul 18, 2025
a7c76ce
#1312: correct the number of ScalarArray arguments needed to 4
mo-alistairp Jul 18, 2025
d4f4ff2
#1312: fix ScalarArray metadata comment
mo-alistairp Jul 18, 2025
c614ade
#1312: update user guide for scalar arrays
mo-alistairp Jul 18, 2025
284d390
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 18, 2025
9992239
#1312: fix lfric doc to allow it to build
mo-alistairp Jul 18, 2025
2ac7ccb
#1312: fix indentation on numbered list
mo-alistairp Jul 21, 2025
6f3ce1e
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 21, 2025
55bcf72
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 22, 2025
dc31eb9
#1312: change array_ndims to be saved as an int
mo-alistairp Jul 23, 2025
cbeee61
#1312: update the documentation
mo-alistairp Jul 23, 2025
a66cc50
#1312: correct the author section
mo-alistairp Jul 23, 2025
7ca77cd
#1312: fix test text from int to integer
mo-alistairp Jul 23, 2025
3c37804
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp Jul 23, 2025
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
238 changes: 142 additions & 96 deletions doc/user_guide/lfric.rst

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/psyclone/domain/lfric/kernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Author R. W. Ford, STFC Daresbury Lab
# Modified L. Turner, Met Office

'''Module for Kernels in the LFRic domain.'''


from psyclone.domain.lfric.kernel.scalar_array_arg_metadata import \
ScalarArrayArgMetadata
from psyclone.domain.lfric.kernel.columnwise_operator_arg_metadata import \
ColumnwiseOperatorArgMetadata
from psyclone.domain.lfric.kernel.common_arg_metadata import CommonArgMetadata
Expand Down
165 changes: 165 additions & 0 deletions src/psyclone/domain/lfric/kernel/scalar_array_arg_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2023-2024, 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.
# -----------------------------------------------------------------------------
# Author L. Turner, Met Office
# Modified A. Pirrie, Met Office

'''Module containing the ScalarArrayArgMetadata class which captures the
metadata associated with a ScalarArray argument. Supports the creation,
modification and Fortran output of a ScalarArray argument.

'''
from typing import Union
from fparser.two import Fortran2003
from psyclone.domain.lfric.kernel.common_arg_metadata import CommonArgMetadata
from psyclone.domain.lfric.kernel.scalar_arg_metadata import ScalarArgMetadata


class ScalarArrayArgMetadata(ScalarArgMetadata):
'''Class to capture LFRic kernel metadata information for a ScalarArray
argument.

:param str datatype: the datatype of this ScalarArray (GH_INTEGER, ...).
:param str access: the way the kernel accesses this Scalar Array (GH_READ).
Comment thread
arporter marked this conversation as resolved.
:param str array_ndims: the rank (number of dimensions) of this
ScalarArray.

'''
# The name used to specify a ScalarArray argument in LFRic metadata.
form = "gh_scalar_array"
# The relative positions of LFRic metadata. Metadata for a ScalarArray
# argument is provided in the following format 'arg_type(form,
# datatype, access, array_ndims)'. Therefore, for example, the
# index of the form argument (form_arg_index) is 0.
form_arg_index = 0
datatype_arg_index = 1
access_arg_index = 2
array_ndims_arg_index = 3
# The name to use for any exceptions.
check_name = "array"
# The number of arguments in the language-level metadata (min and
# max values).
nargs = (4, 4)

def __init__(self, datatype, access, array_ndims):
super().__init__(datatype, access)
self.array_ndims = array_ndims

@classmethod
def _get_metadata(cls, fparser2_tree: Union[Fortran2003.Part_Ref,
Fortran2003.Structure_Constructor]
) -> tuple[str, str, int]:

'''Extract the required metadata from the fparser2 tree and return it
as strings. Also check that the metadata is in the expected
form (but do not check the metadata values as that is done
separately).

:param fparser2_tree: fparser2 tree containing the metadata
for this argument.

:returns: a tuple containing the datatype, access and array ndims
metadata.

'''
datatype, access = super()._get_metadata(fparser2_tree)
array_ndims = cls.get_array_ndims(fparser2_tree)
return (datatype, access, array_ndims)

def fortran_string(self) -> str:
'''
:returns: the metadata represented by this class as Fortran.
'''
return (f"arg_type({self.form}, {self.datatype}, {self.access}, "
f"{self.array_ndims})")

@property
def array_ndims(self) -> int:
'''
:returns: the number of dimensions for this ScalarArray argument.
'''
return self._array_ndims

@array_ndims.setter
def array_ndims(self, value):
'''
:param str value: set the number of dimensions to the specified value.

:raises TypeError: if value is not an integer type.
:raises ValueError: if value is less than 1.

'''
if not isinstance(value, int):
raise TypeError(f"The type of value must be an integer, but "
f"found input of type {type(value)}.")

if value < 1:
raise ValueError(f"The number of dimensions of a ScalarArray "
f"should be an integer greater than or "
f"equal to 1 but found {value}.")

self._array_ndims = value

@classmethod
def get_array_ndims(cls, fparser2_tree) -> int:
'''Retrieves the array ndims metadata value found within the
supplied fparser2 tree and checks that it is valid.

:param fparser2_tree: fparser2 tree capturing the required metadata.
:type fparser2_tree: :py:class:`fparser.two.Fortran2003.Part_Ref`

:returns: the array ndims value extracted from the fparser2 tree,
converted to an int.

:raises ValueError: if the array ndims is not a string.
:raises ValueError: if the array ndims is less than 1.

'''
array_datatype = CommonArgMetadata.get_arg(
fparser2_tree, cls.array_ndims_arg_index)
array_ndims = array_datatype.strip()
try:
int_value = int(array_ndims)
except ValueError as info:
raise ValueError(f"The number of dimensions of a ScalarArray "
f"should be a string containing an integer, "
f"but found '{array_ndims}'.") from info

if int_value < 1:
raise ValueError(f"The number of dimensions of a ScalarArray "
f"should be an integer greater than or "
f"equal to 1 but found {int_value}.")
return int_value


__all__ = ["ScalarArrayArgMetadata"]
Loading
Loading