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

Constituent updates #468

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
cea2531
Refactor constituent mixing ratio properties
Jul 14, 2022
bce4d22
Avoid RE deprecation warning by moving case fold to state_machine.py
Aug 12, 2022
279c180
Fix doctest
Aug 12, 2022
057588e
Allow '1' to be a valid unit
Dec 12, 2022
678621e
Added molar_mass (molecular weight) value to constituent property type
Jan 2, 2023
27f6851
initial changes
Jan 5, 2023
ca65368
fixes
Jan 6, 2023
10416a9
address review comments
Jan 9, 2023
5e8e33a
hopefully final fixes
Jan 9, 2023
9bb155b
Merge pull request #41 from peverwhee/add_molecular_weight
gold2718 Jan 10, 2023
a2386d6
initial commit
Feb 5, 2023
7657f33
fix function name
Feb 5, 2023
5315500
fix fstring
Feb 6, 2023
84bade6
fix mistakes in routine names and comments
Feb 6, 2023
3494311
split up register and initialize
Mar 1, 2023
d9871c0
cleanup
Mar 1, 2023
a71e1b5
cleanup
Mar 1, 2023
6c7c82a
add temporary hash_table variable to avoid dangling pointer
Mar 1, 2023
d4ad4aa
deallocate hash_table
Mar 2, 2023
f549d64
cleaner way to deallocate hash table in iterator object
Mar 7, 2023
5813d19
change name of const array interfaces
Mar 22, 2023
8ff8d5a
add intialized_in_physics property
Apr 10, 2023
f074f1c
better error handling; fix for copy constituent
Apr 11, 2023
5e839bf
remove unnecessary use statment
Apr 12, 2023
feb8bcb
fix unit tests
Apr 19, 2023
15f52c6
revert changes for unit conversion test
May 11, 2023
3703645
handle constituent edge cases better and differently; revert module v…
May 22, 2023
1e83c4c
fix decimal
May 22, 2023
dad0dbd
remove initialized-in-physics constituent from advection test require…
Jun 9, 2023
c477eaf
Initial commit of containerized GitHub actions to run unit tests.
Jun 27, 2023
43a47e4
Fixing typo from previous commit.
mwaxmonsky Jun 27, 2023
5cc29b5
Fixing typo from previous commit.
mwaxmonsky Jun 27, 2023
aaa12aa
Addming missing python dependency.
mwaxmonsky Jun 27, 2023
92680b7
Removing incorrect flag from pip install.
mwaxmonsky Jun 27, 2023
3ff2d09
Replacing incorrect Dockerfile instruction.
mwaxmonsky Jun 27, 2023
7cce8c5
Returning non-zero if test failures detected.
mwaxmonsky Jun 27, 2023
8ac4c7e
Removing test failing due to not being fully implemented yet.
mwaxmonsky Jun 28, 2023
00edf9a
Addming missing newlines.
mwaxmonsky Jun 28, 2023
f44f377
add default_value to constituent properties object
Jul 3, 2023
d3413c1
Adding testing CI action to pull requests and all branches.
mwaxmonsky Jul 3, 2023
f3fa550
Updating workflow name with more accurate description.
mwaxmonsky Jul 3, 2023
7c5c3fb
Renaming capgen unit test workflow file.
mwaxmonsky Jul 3, 2023
97cd70a
Fixing typo.
mwaxmonsky Jul 3, 2023
e5fdab9
Moving capgen Dockerfile into test directory.
mwaxmonsky Jul 3, 2023
d5cc5f5
Adding print statement to test output for reasong for skipping var_ac…
mwaxmonsky Jul 3, 2023
a10648a
Moving tests to running in github container directly.
mwaxmonsky Jul 5, 2023
374a473
Replacing apt calls with apt-get.
mwaxmonsky Jul 5, 2023
7030d43
Adding sudo to apt-get commands.
mwaxmonsky Jul 5, 2023
d0e2e22
Updating package names to ubuntu packages.
mwaxmonsky Jul 5, 2023
5e70051
Updating path to cd into.
mwaxmonsky Jul 5, 2023
e76bb45
Removing test/Dockerfile as no longer needed.
mwaxmonsky Jul 5, 2023
752f1f1
Removing un-needed python dependencies install step.
mwaxmonsky Jul 5, 2023
62a0d03
Removing sourcing python venv.
mwaxmonsky Jul 5, 2023
2552b69
Filtering CI action to only auto run if in a PR or pushing to the mai…
mwaxmonsky Jul 7, 2023
731a0cb
Testing allowing run of actions manually.
mwaxmonsky Jul 7, 2023
b4ba84c
Adding proper filter to job to run unit test action manually.
mwaxmonsky Jul 7, 2023
af5119b
Fixing format of workflow_dispatch declaration.
mwaxmonsky Jul 7, 2023
813e46a
Changing ordering of workflow triggers.
mwaxmonsky Jul 7, 2023
08c5503
Adding initial pylint configuration.
mwaxmonsky Jul 7, 2023
e28d5d5
Removing pylint job to evaluate in a new PR.
mwaxmonsky Jul 7, 2023
85ce0aa
Merge pull request #2 from mwaxmonsky/test_actions
mwaxmonsky Jul 7, 2023
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
22 changes: 22 additions & 0 deletions .github/workflows/capgen_unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Capgen Unit Tests

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
#Trigger workflow on push to any branch or branch heirarchy:
- '**'

jobs:
unit_tests:
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || github.repository == 'NCAR/ccpp-framework'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: update repos and install dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential gfortran cmake python3 git
- name: Run unit tests
run: cd test && ./run_tests.sh

5 changes: 3 additions & 2 deletions doc/HelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
PROJECT(HelloWorld)
ENABLE_LANGUAGE(Fortran)

Expand Down Expand Up @@ -166,7 +166,8 @@ list(APPEND DTABLE_CMD "${CCPP_CAP_FILES}/datatable.xml")
list(APPEND DTABLE_CMD "--ccpp-files")
list(APPEND DTABLE_CMD "--separator=\\;")
string(REPLACE ";" " " DTABLE_STRING "${DTABLE_CMD}")
MESSAGE(STATUS "Running: ${DTABLE_STRING}")
string(STRIP ${DTABLE_STRING} DTABLE_STRING)
MESSAGE(STATUS "Running: ${DTABLE_STRING};")
EXECUTE_PROCESS(COMMAND ${DTABLE_CMD} OUTPUT_VARIABLE CCPP_CAPS
RESULT_VARIABLE RES
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
Expand Down
48 changes: 39 additions & 9 deletions scripts/ccpp_capgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
import re
# CCPP framework imports
from ccpp_database_obj import CCPPDatabaseObj
from ccpp_datafile import generate_ccpp_datatable
from ccpp_suite import API
from file_utils import check_for_writeable_file, remove_dir, replace_paths
Expand All @@ -26,11 +27,13 @@
from host_model import HostModel
from metadata_table import parse_metadata_file, SCHEME_HEADER_TYPE
from parse_tools import init_log, set_log_level, context_string
from parse_tools import register_fortran_ddt_name
from parse_tools import CCPPError, ParseInternalError

## Capture the Framework root
__SCRIPT_PATH = os.path.dirname(__file__)
__FRAMEWORK_ROOT = os.path.abspath(os.path.join(__SCRIPT_PATH, os.pardir))
_SCRIPT_PATH = os.path.dirname(__file__)
_FRAMEWORK_ROOT = os.path.abspath(os.path.join(_SCRIPT_PATH, os.pardir))
_SRC_ROOT = os.path.join(_FRAMEWORK_ROOT, "src")
## Init this now so that all Exceptions can be trapped
_LOGGER = init_log(os.path.basename(__file__))

Expand All @@ -43,6 +46,11 @@
## Metadata table types where order is significant
_ORDERED_TABLE_TYPES = [SCHEME_HEADER_TYPE]

## CCPP Framework supported DDT types
_CCPP_FRAMEWORK_DDT_TYPES = ["ccpp_hash_table_t",
"ccpp_hashable_t",
"ccpp_hashable_char_t"]

###############################################################################
def delete_pathnames_from_file(capfile, logger):
###############################################################################
Expand Down Expand Up @@ -559,7 +567,7 @@ def clean_capgen(cap_output_file, logger):
set_log_level(logger, log_level)

###############################################################################
def capgen(run_env):
def capgen(run_env, return_db=False):
###############################################################################
"""Parse indicated host, scheme, and suite files.
Generate code to allow host model to run indicated CCPP suites."""
Expand All @@ -578,12 +586,22 @@ def capgen(run_env):
# Try to create output_dir (let it crash if it fails)
os.makedirs(run_env.output_dir)
# end if
# Pre-register base CCPP DDT types
for ddt_name in _CCPP_FRAMEWORK_DDT_TYPES:
register_fortran_ddt_name(ddt_name)
# end for
src_dir = os.path.join(_FRAMEWORK_ROOT, "src")
host_files = run_env.host_files
host_name = run_env.host_name
scheme_files = run_env.scheme_files
# We need to create three lists of files, hosts, schemes, and SDFs
host_files = create_file_list(run_env.host_files, ['meta'], 'Host',
run_env.logger)
# The host model needs to know about the constituents module
const_mod = os.path.join(_SRC_ROOT, "ccpp_constituent_prop_mod.meta")
if const_mod not in host_files:
host_files.append(const_mod)
# end if
scheme_files = create_file_list(run_env.scheme_files, ['meta'],
'Scheme', run_env.logger)
sdfs = create_file_list(run_env.suites, ['xml'], 'Suite', run_env.logger)
Expand All @@ -595,10 +613,18 @@ def capgen(run_env):
# First up, handle the host files
host_model = parse_host_model_files(host_files, host_name, run_env)
# Next, parse the scheme files
# We always need to parse the ccpp_constituent_prop_ptr_t DDT
##XXgoldyXX: Should this be in framework_env.py?
const_prop_mod = os.path.join(src_dir, "ccpp_constituent_prop_mod.meta")
if const_prop_mod not in scheme_files:
scheme_files= [const_prop_mod] + scheme_files
# end if
scheme_headers, scheme_tdict = parse_scheme_files(scheme_files, run_env)
ddts = host_model.ddt_lib.keys()
if ddts and run_env.logger and run_env.logger.isEnabledFor(logging.DEBUG):
run_env.logger.debug("DDT definitions = {}".format(ddts))
if run_env.logger and run_env.logger.isEnabledFor(logging.DEBUG):
ddts = host_model.ddt_lib.keys()
if ddts:
run_env.logger.debug("DDT definitions = {}".format(ddts))
# end if
# end if
plist = host_model.prop_list('local_name')
if run_env.logger and run_env.logger.isEnabledFor(logging.DEBUG):
Expand Down Expand Up @@ -628,7 +654,8 @@ def capgen(run_env):
cap_filenames = ccpp_api.write(outtemp_dir, run_env)
if run_env.generate_host_cap:
# Create a cap file
host_files = [write_host_cap(host_model, ccpp_api,
cap_module = host_model.ccpp_cap_name()
host_files = [write_host_cap(host_model, ccpp_api, cap_module,
outtemp_dir, run_env)]
else:
host_files = list()
Expand All @@ -646,10 +673,13 @@ def capgen(run_env):
# end if
# Finally, create the database of generated files and caps
# This can be directly in output_dir because it will not affect dependencies
src_dir = os.path.join(__FRAMEWORK_ROOT, "src")
generate_ccpp_datatable(run_env, host_model, ccpp_api,
scheme_headers, scheme_tdict, host_files,
cap_filenames, kinds_file, src_dir)
if return_db:
return CCPPDatabaseObj(run_env, host_model=host_model, api=ccpp_api)
# end if
return None

###############################################################################
def _main_func():
Expand All @@ -665,7 +695,7 @@ def _main_func():
if framework_env.clean:
clean_capgen(framework_env.datatable_file, framework_env.logger)
else:
capgen(framework_env)
_ = capgen(framework_env)
# end if (clean)

###############################################################################
Expand Down
87 changes: 87 additions & 0 deletions scripts/ccpp_database_obj.py
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:
"""Ojbect 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 = "cam"
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")
13 changes: 9 additions & 4 deletions scripts/ccpp_datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,13 @@ def _new_var_entry(parent, var, full_entry=True):
"""Create a variable sub-element of <parent> with information from <var>.
If <full_entry> is False, only include standard name and intent.
"""
prop_list = ["intent"]
prop_list = ["intent", "local_name"]
if full_entry:
prop_list.extend(["allocatable", "active", "default_value",
"diagnostic_name", "diagnostic_name_fixed",
"kind", "persistence", "polymorphic", "protected",
"state_variable", "type", "units"])
"state_variable", "type", "units", "molar_mass",
"advected"])
prop_list.extend(Var.constituent_property_names())
# end if
ventry = ET.SubElement(parent, "var")
Expand All @@ -671,9 +672,13 @@ def _new_var_entry(parent, var, full_entry=True):
if full_entry:
dims = var.get_dimensions()
if dims:
dim_entry = ET.SubElement(ventry, "dimensions")
dim_entry.text = " ".join(dims)
v_entry = ET.SubElement(ventry, "dimensions")
v_entry.text = " ".join(dims)
# end if
v_entry = ET.SubElement(ventry, "source_type")
v_entry.text = var.source.ptype.lower()
v_entry = ET.SubElement(ventry, "source_name")
v_entry.text = var.source.name.lower()
# end if

###############################################################################
Expand Down
10 changes: 5 additions & 5 deletions scripts/ccpp_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# CCPP framework imports
from state_machine import StateMachine

_INIT_ST = r"(?:(?i)init(?:ial(?:ize)?)?)"
_FINAL_ST = r"(?:(?i)final(?:ize)?)"
_RUN_ST = r"(?:(?i)run)"
_TS_INIT_ST = r"(?:(?i)timestep_init(?:ial(?:ize)?)?)"
_TS_FINAL_ST = r"(?:(?i)timestep_final(?:ize)?)"
_INIT_ST = r"(?:init(?:ial(?:ize)?)?)"
_FINAL_ST = r"(?:final(?:ize)?)"
_RUN_ST = r"(?:run)"
_TS_INIT_ST = r"(?:timestep_init(?:ial(?:ize)?)?)"
_TS_FINAL_ST = r"(?:timestep_final(?:ize)?)"

# Allowed CCPP transitions
# pylint: disable=bad-whitespace
Expand Down
Loading