-
Notifications
You must be signed in to change notification settings - Fork 34
#1312: metadata for read-only arrays #2173
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
Merged
Merged
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 721e7eb
#1312 missed a name change oops
mo-lottieturner 694dd10
#1312 list in test file needed to be updated
mo-lottieturner fffce7e
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner f866583
#1312 adding tests, some not yet working
mo-lottieturner f18c0eb
#1312 making more tests work and adding LFRicArrayArgs
mo-lottieturner e240d71
#1312 more test changes
mo-lottieturner eb1e9fc
#1312 more changes for tests
mo-lottieturner 6285ad1
#1312 removing lfric_array_args and relevant tests as was getting ahe…
mo-lottieturner a79104a
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 705d38e
#1312 adding metadata in the new style
mo-lottieturner c3f45a5
#1312 changes in new metadata
mo-lottieturner bc4bbc0
#1312 removing unneeded commmented out code
mo-lottieturner 7ca546c
#1312 changing get_vector_length to get_array_dimension
mo-lottieturner 32db8f5
#1312 test for incorrect operator added
mo-lottieturner aeebec2
#1312 tidying up mistakes and pylint
mo-lottieturner d54e65b
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 8fb098a
#1312 temp hopeful fix for get_array_dimension
mo-lottieturner 5972289
1312 reverting changes to get_array_dimension
mo-lottieturner a1c0774
#1312: *facepalm*
mo-lottieturner f07e02a
#1312 more facepalming (should work now!)
mo-lottieturner 0c2bcb8
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner dca477d
#1312 writing more tests
mo-lottieturner 9ee4fe0
#1312 returning get_array_dimensions to get_vector_length in preparat…
mo-lottieturner cc0ca8b
#1312 removing name from modifier list and reinstating previous copyr…
mo-lottieturner c9e7357
#1312 cleaning up pylint &c
mo-lottieturner 2e442ed
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 961c519
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner cac55c8
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 5433b4f
#1312 DynKernMetadata -> LFRicKernMetadata, plus labelling untested l…
mo-lottieturner 255113d
#1312 removing ParseError that is impossible to trigger
mo-lottieturner 2e7b8ef
#1312 some tidying and adding a new file for the tests
mo-lottieturner 6927e3b
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner e8da6d0
#1312 uncommenting section and distinguising array_size (prev array_n…
mo-lottieturner 0400ae0
#1312 missed one
mo-lottieturner d9f4f60
#1312 forgot some brackets!
mo-lottieturner 2a05865
#1312 pycodestyle changes
mo-lottieturner e42c51b
#1312 finally managed to get all but one of the array_arg_metadata te…
mo-lottieturner 351c4d1
#1312 commenting out non-working test to check nothing else is broken
mo-lottieturner 5abb56f
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 2e03912
#1312 missing ParseError import
mo-lottieturner d0fe57c
#1312 more fixing for tests + adding name to file
mo-lottieturner e12aefa
#1312 tidying for pylint and pycodestyle
mo-lottieturner 0f7272b
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner d40d01b
#1312 adding test for get_array_ndims
mo-lottieturner fe4baf9
#1312 adding test for the array_ndims setter
mo-lottieturner 0d2eae6
#1312 fixing fortran_string test
mo-lottieturner db64978
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 9fa6093
1312 tidying of comments and strings
mo-lottieturner 23b4b25
#1312 removing unused code
mo-lottieturner 5df7abb
#1312 adding test for get_array_dims ParseError
mo-lottieturner 2223df2
#1312 expanding check_datatype to test gh_integer and gh_logical
mo-lottieturner 8d2a37a
#1312 changes for pylint and pycodestyle
mo-lottieturner c530e69
#1312 removing unnecessary 'for' loops for pylint
mo-lottieturner 311b31c
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 9d75b5e
#1312 adding flags to where docs need adding to
mo-lottieturner 0cdb2fc
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner d642345
#1312 more docs changes
mo-lottieturner e24d286
#1312 more docs changes
mo-lottieturner e9ddb47
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 5867a30
#1312 clearing up of flags addressed
mo-lottieturner b40e7da
#1312 expanding on the Data Types and precision table, plus changing …
mo-lottieturner 996a0a3
#1312 adding final bits of documentation
mo-lottieturner b978fe1
#1312 adding a modifier line that slipped through the cracks@
mo-lottieturner 59e272e
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner e571bc1
#1312 space fixing
mo-lottieturner 48f72bd
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner 9243f29
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 6857e55
#1312 removing backslashes in comments from lfric_arg_descriptor.py
mo-lottieturner c7d4ab3
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner 901ea74
#1312 merging lines in table and adding missing array mention
mo-lottieturner 5f4fda5
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 335205c
#1312 including arrays in some missed spots in the docs
mo-lottieturner 275b755
#1312 removing NRANKS, hopefully I got all of them
mo-lottieturner 038e0d6
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 8f98f7f
#1312 line length is 79 characters not 80
mo-lottieturner 5240679
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner bedf340
#1312 removing unused ParseError
mo-lottieturner 51358d3
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 8acfa80
Merge branch 'master' into 1312_metadata_for_arrays
arporter 7134c95
#1312 review changes on user guide
mo-lottieturner be295e5
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 288f7b2
#1312 lfric_constants review comment
mo-lottieturner 8c82811
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 7d03e9a
#1312 changing gh_array to gh_scalar_array
mo-lottieturner e8bbc73
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner 62c648d
#1312 ArrayArgMetadata -> ScalarArrayArgMetadata, some review changes…
mo-lottieturner b22d45e
#1312 review changes in lfric_arg_descriptor
mo-lottieturner 8f88377
#1312 pycodestyle change
mo-lottieturner 21f2914
#1312 forgot to change a test to match
mo-lottieturner 88c5135
#1312 more changes from review comments
mo-lottieturner 6ad8c10
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 9434c8d
#1312 pylinting
mo-lottieturner dbfb013
#1312 more pylinting
mo-lottieturner 67a9e91
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 02d8221
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 81d076c
#1312 fixing tests
mo-lottieturner fe87718
Revert "#1312 fixing tests"
mo-lottieturner 47c68b0
Merge branch '1312_metadata_for_arrays' of github.com:stfc/PSyclone i…
mo-lottieturner 359d4de
#1312 fixing tests (in 2/3 files)
mo-lottieturner 0652266
#1312 commenting out failing tests to see code coverage
mo-lottieturner 433b385
#1312 pycodestyle fixes
mo-lottieturner ad08064
#1312 fixing final test file test_get_array_ndims
mo-lottieturner 6332d7e
#1312 line length
mo-lottieturner 738bad3
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner e0899d5
#1312 removing an error and its test that can't be triggered
mo-lottieturner 180c0ae
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 0cbad6c
Merge branch 'master' into 1312_metadata_for_arrays
mo-lottieturner 0a81360
Merge branch 'master' into 1312_metadata_for_arrays
arporter 5aeb092
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 7328648
#1312: fix table of datatypes
mo-alistairp 0b740e1
#1312: Update LFRic array names to ScalarArray
mo-alistairp de5ba1d
#1312: lint fix
mo-alistairp df5816b
#1312: Update LFRic array tests to be ScalarArray
mo-alistairp b8ac6c1
#1312: Change array size to array rank
mo-alistairp e00f0d1
#1312: lint fix
mo-alistairp 51a618d
#1312: Fix test
mo-alistairp e0cfec0
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 398a867
#1312: Rename to scalar_array_arg_metadata
mo-alistairp 2cbd2d0
#1312: Rename scalar array test
mo-alistairp 37ff3bf
#1312: test the scalar array setter
mo-alistairp fdeb70f
#1312: fix syntax
mo-alistairp 7989283
#1312: fix type comparison
mo-alistairp 2d4e0d3
#1312: lint fix
mo-alistairp 17ef14e
#1312: Fix test
mo-alistairp 2e7b7ca
#1312: fix test
mo-alistairp d0fa615
#1312: Add print statements to diagnose
mo-alistairp b652b74
#1312: temporarily remove test
mo-alistairp a976ad8
#1312: test fix for scalar array tests
mo-alistairp 249229b
#1312: revert changes
mo-alistairp 2cbdd86
#1312: fix test
mo-alistairp c8991cd
#1312: fix setter in scalar array tests
mo-alistairp af2b0fa
#1312: convert error into string
mo-alistairp 03cbd74
#1312: change class name in test
mo-alistairp c3f38ac
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp e033522
#1312: update text to ScalarArray
mo-alistairp 1f64126
#1312: fix ScalarArray test bug
mo-alistairp 3ecb824
#1312: fix ScalarArray error handling
mo-alistairp 8b2127b
#1312: lint fix
mo-alistairp f329bac
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp fd16bf7
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 8477d5a
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp dc63686
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp ecac860
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 7893310
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp fa1c1df
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 8dbc183
#1312: fix typo
mo-alistairp 82118c0
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp ceca33c
#1312: add typehinting
mo-alistairp 2f55dc4
#1312: Import Fparser and fix lint
mo-alistairp 7a75df5
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp f6bc943
#1312: Remove typing module dependence
mo-alistairp 59e7d02
#1312: Reintroduce typing for union
mo-alistairp 98dfa59
#1312: change raises text
mo-alistairp df2ca5a
#1312: revert common_meta_arg_metadata
mo-alistairp 1a140a9
#1312: update api to LFRic
mo-alistairp a7c76ce
#1312: correct the number of ScalarArray arguments needed to 4
mo-alistairp d4f4ff2
#1312: fix ScalarArray metadata comment
mo-alistairp c614ade
#1312: update user guide for scalar arrays
mo-alistairp 284d390
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 9992239
#1312: fix lfric doc to allow it to build
mo-alistairp 2ac7ccb
#1312: fix indentation on numbered list
mo-alistairp 6f3ce1e
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp 55bcf72
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp dc31eb9
#1312: change array_ndims to be saved as an int
mo-alistairp cbeee61
#1312: update the documentation
mo-alistairp a66cc50
#1312: correct the author section
mo-alistairp 7ca77cd
#1312: fix test text from int to integer
mo-alistairp 3c37804
Merge branch 'master' into 1312_metadata_for_arrays
mo-alistairp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
src/psyclone/domain/lfric/kernel/scalar_array_arg_metadata.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). | ||
| :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"] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.