-
Notifications
You must be signed in to change notification settings - Fork 64
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
Capgen cleanup #493
Merged
Merged
Capgen cleanup #493
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a6cc0d
initial stab at cleanup-only PR
3d75c77
cleanup and fixes
52626d0
bugfixes
3c6a9e2
add code owners
1be9b3d
code cleanup
55e4c59
merge up to head of feature/capgen
c8ad82d
generalize host
44ea46f
change to fstrings
3f5c06f
Cleaning up units regex.
mwaxmonsky 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,87 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Define the CCPPDatabaseObj object | ||
Object definition and methods to provide information from a run of capgen. | ||
""" | ||
|
||
from host_model import HostModel | ||
from ccpp_suite import API | ||
|
||
class CCPPDatabaseObjError(ValueError): | ||
"""Error class specific to CCPPDatabaseObj. | ||
All uses of this error should be internal (i.e., programmer error, | ||
not user error).""" | ||
|
||
def __init__(self, message): | ||
"""Initialize this exception""" | ||
super().__init__(message) | ||
|
||
class CCPPDatabaseObj: | ||
"""Object with data and methods to provide information from a run of capgen. | ||
""" | ||
|
||
def __init__(self, run_env, host_model=None, api=None, database_file=None): | ||
"""Initialize this CCPPDatabaseObj. | ||
If <database_file> is not None, all other inputs MUST be None and | ||
the object is created from the database table created by capgen. | ||
To initialize the object from an in-memory capgen run, ALL other | ||
inputs MUST be passed (i.e., not None) and it is an error to pass | ||
a value for <database_file>. | ||
""" | ||
|
||
runtime_obj = all([host_model is not None, api is not None]) | ||
self.__host_model = None | ||
self.__api = None | ||
self.__database_file = None | ||
if runtime_obj and database_file: | ||
emsg = "Cannot provide both runtime arguments and database_file." | ||
elif (not runtime_obj) and (not database_file): | ||
emsg = "Must provide either database_file or all runtime arguments." | ||
else: | ||
emsg = "" | ||
# end if | ||
if emsg: | ||
raise CCPPDatabaseObjError(f"ERROR: {emsg}") | ||
# end if | ||
if runtime_obj: | ||
self.__host_model = host_model | ||
self.__api = api | ||
else: | ||
self.db_from_file(run_env, database_file) | ||
# end if | ||
|
||
def db_from_file(self, run_env, database_file): | ||
"""Create the necessary internal data structures from a CCPP | ||
datatable.xml file created by capgen. | ||
""" | ||
metadata_tables = {} | ||
host_name = "host" | ||
self.__host_model = HostModel(metadata_tables, host_name, run_env) | ||
self.__api = API(sdfs, host_model, scheme_headers, run_env) | ||
raise CCPPDatabaseObjError("ERROR: <database_file> not supported") | ||
|
||
def host_model_dict(self): | ||
"""Return the host model dictionary for this CCPP DB object""" | ||
if self.__host_model is not None: | ||
return self.__host_model | ||
# end if | ||
raise CCPPDatabaseObjError("ERROR: <database_file> not supported") | ||
|
||
def suite_list(self): | ||
"""Return a list of suites built into the API""" | ||
if self.__api is not None: | ||
return list(self.__api.suites) | ||
# end if | ||
raise CCPPDatabaseObjError("ERROR: <database_file> not supported") | ||
|
||
def constituent_dictionary(self, suite): | ||
"""Return the constituent dictionary for <suite>""" | ||
return suite.constituent_dictionary() | ||
|
||
def call_list(self, phase): | ||
"""Return the API call list for <phase>""" | ||
if self.__api is not None: | ||
return self.__api.call_list(phase) | ||
# end if | ||
raise CCPPDatabaseObjError("ERROR: <database_file> not supported") |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -17,8 +17,7 @@ | |
from fortran_tools import FortranWriter | ||
from framework_env import CCPPFrameworkEnv | ||
from metavar import Var, VarDictionary, ccpp_standard_var | ||
from metavar import CCPP_CONSTANT_VARS, CCPP_LOOP_VAR_STDNAMES | ||
from parse_tools import ParseContext, ParseSource, context_string | ||
from parse_tools import ParseContext, ParseSource | ||
from parse_tools import ParseInternalError, CCPPError | ||
from parse_tools import read_xml_file, validate_xml_file, find_schema_version | ||
from parse_tools import init_log, set_log_to_null | ||
|
@@ -31,12 +30,12 @@ | |
############################################################################### | ||
|
||
# Source for internally generated variables. | ||
_API_SOURCE_NAME = "CCPP_API" | ||
API_SOURCE_NAME = "CCPP_API" | ||
# Use the constituent source type for consistency | ||
_API_SUITE_VAR_NAME = ConstituentVarDict.constitutent_source_type() | ||
_API_SCHEME_VAR_NAME = "scheme" | ||
_API_CONTEXT = ParseContext(filename="ccpp_suite.py") | ||
_API_SOURCE = ParseSource(_API_SOURCE_NAME, _API_SCHEME_VAR_NAME, _API_CONTEXT) | ||
_API_SOURCE = ParseSource(API_SOURCE_NAME, _API_SCHEME_VAR_NAME, _API_CONTEXT) | ||
_API_LOGGING = init_log('ccpp_suite') | ||
set_log_to_null(_API_LOGGING) | ||
_API_DUMMY_RUN_ENV = CCPPFrameworkEnv(_API_LOGGING, | ||
|
@@ -299,7 +298,7 @@ def find_variable(self, standard_name=None, source_var=None, | |
# Remove this entry to avoid looping back here | ||
del self.__gvar_stdnames[standard_name] | ||
# Let everyone know this is now a Suite variable | ||
var.source = ParseSource(_API_SOURCE_NAME, | ||
var.source = ParseSource(API_SOURCE_NAME, | ||
_API_SUITE_VAR_NAME, | ||
var.context) | ||
self.add_variable(var, self.__run_env) | ||
|
@@ -730,9 +729,8 @@ def write_var_set_loop(ofile, varlist_name, var_list, indent, | |
|
||
def write_suite_part_list_sub(self, ofile, errmsg_name, errcode_name): | ||
"""Write the suite-part list subroutine""" | ||
oline = "suite_name, part_list, {errmsg}, {errcode}" | ||
inargs = oline.format(errmsg=errmsg_name, errcode=errcode_name) | ||
ofile.write("\nsubroutine {}({})".format(API.__part_fname, inargs), 1) | ||
inargs = f"suite_name, part_list, {errmsg_name}, {errcode_name}" | ||
ofile.write(f"subroutine {API.__part_fname}({inargs})", 1) | ||
oline = "character(len=*), intent(in) :: suite_name" | ||
ofile.write(oline, 2) | ||
oline = "character(len=*), allocatable, intent(out) :: part_list(:)" | ||
|
@@ -741,22 +739,22 @@ def write_suite_part_list_sub(self, ofile, errmsg_name, errcode_name): | |
self._errcode_var.write_def(ofile, 2, self) | ||
else_str = '' | ||
ename = self._errcode_var.get_prop_value('local_name') | ||
ofile.write("{} = 0".format(ename), 2) | ||
ofile.write(f"{ename} = 0", 2) | ||
ename = self._errmsg_var.get_prop_value('local_name') | ||
ofile.write("{} = ''".format(ename), 2) | ||
ofile.write(f"{ename} = ''", 2) | ||
for suite in self.suites: | ||
oline = "{}if(trim(suite_name) == '{}') then" | ||
ofile.write(oline.format(else_str, suite.name), 2) | ||
API.write_var_set_loop(ofile, 'part_list', suite.part_list(), 3) | ||
else_str = 'else ' | ||
# end for | ||
ofile.write("else", 2) | ||
emsg = "write({errmsg}, '(3a)')".format(errmsg=errmsg_name) | ||
emsg = f"write({errmsg_name}, '(3a)')" | ||
emsg += "'No suite named ', trim(suite_name), ' found'" | ||
ofile.write(emsg, 3) | ||
ofile.write("{errcode} = 1".format(errcode=errcode_name), 3) | ||
ofile.write(f"{errcode_name} = 1", 3) | ||
ofile.write("end if", 2) | ||
ofile.write("end subroutine {}".format(API.__part_fname), 1) | ||
ofile.write(f"end subroutine {API.__part_fname}", 1) | ||
climbfuji marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def write_req_vars_sub(self, ofile, errmsg_name, errcode_name): | ||
"""Write the required variables subroutine""" | ||
|
@@ -807,9 +805,9 @@ def write_req_vars_sub(self, ofile, errmsg_name, errcode_name): | |
parent = suite.parent | ||
# Collect all the suite variables | ||
oline = "{}if(trim(suite_name) == '{}') then" | ||
input_vars = [set(), set(), set()] # leaves, arrrays, leaf elements | ||
inout_vars = [set(), set(), set()] # leaves, arrrays, leaf elements | ||
output_vars = [set(), set(), set()] # leaves, arrrays, leaf elements | ||
input_vars = [set(), set(), set()] # leaves, arrays, leaf elements | ||
inout_vars = [set(), set(), set()] # leaves, arrays, leaf elements | ||
output_vars = [set(), set(), set()] # leaves, arrays, leaf elements | ||
Comment on lines
+808
to
+810
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No more pirates? |
||
for part in suite.groups: | ||
for var in part.call_list.variable_list(): | ||
stdname = var.get_prop_value("standard_name") | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!