-
Notifications
You must be signed in to change notification settings - Fork 7
Add processing and comparison of ctests in JEDI builds #778
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
Open
mranst
wants to merge
7
commits into
develop
Choose a base branch
from
feature/mranst/jedi_ctest_comparisons
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
48a288d
Add processing and comparison of ctests in JEDI builds
mranst 091a872
Add to docs
mranst f84ca69
address comments
mranst a968d46
Merge branch 'develop' into feature/mranst/jedi_ctest_comparisons
mranst 71dbf78
Merge branch 'develop' into feature/mranst/jedi_ctest_comparisons
mranst c7b139f
Merge branch 'develop' into feature/mranst/jedi_ctest_comparisons
mranst ae722e9
Merge branch 'develop' into feature/mranst/jedi_ctest_comparisons
mranst 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 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
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
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,42 @@ | ||
| # (C) Copyright 2021- United States Government as represented by the Administrator of the | ||
| # National Aeronautics and Space Administration. All Rights Reserved. | ||
| # | ||
| # This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| # Cylc suite for comparing two builds of JEDI directly | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| [scheduler] | ||
| allow implicit tasks = False | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| [scheduling] | ||
|
|
||
| [[graph]] | ||
| R1 = """ | ||
| CompareJediCtests | ||
| """ | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| [runtime] | ||
|
|
||
| # Task defaults | ||
| # ------------- | ||
| [[root]] | ||
| pre-script = "source $CYLC_SUITE_DEF_PATH/modules" | ||
|
|
||
| [[[environment]]] | ||
| config = $CYLC_SUITE_DEF_PATH/experiment.yaml | ||
|
|
||
| # Tasks | ||
| # ----- | ||
| [[CompareJediCtests]] | ||
| script = "swell task CompareJediCtests $config" | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- |
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,33 @@ | ||
| # -------------------------------------------------------------------------------------------------- | ||
| # @package configuration | ||
| # | ||
| # Class containing the configuration. This is a dictionary that is converted from | ||
| # an input yaml configuration file. Various function are included for interacting with the | ||
| # dictionary. | ||
| # | ||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| from swell.utilities.swell_questions import QuestionContainer, QuestionList | ||
| from swell.suites.suite_questions import SuiteQuestions as sq | ||
|
|
||
| from enum import Enum | ||
|
|
||
| from swell.utilities.question_defaults import QuestionDefaults as qd | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class SuiteConfig(QuestionContainer, Enum): | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| compare_jedi = QuestionList( | ||
| list_name="compare_jedi", | ||
| questions=[ | ||
| sq.all_suites, | ||
| qd.comparison_experiment_paths() | ||
| ] | ||
| ) | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- |
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
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,140 @@ | ||
| # (C) Copyright 2021- United States Government as represented by the Administrator of the | ||
| # National Aeronautics and Space Administration. All Rights Reserved. | ||
| # | ||
| # This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
|
|
||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| import os | ||
| import re | ||
|
|
||
| from swell.utilities.comparisons import comparison_tags | ||
| from swell.tasks.base.task_base import taskBase | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class CompareJediCtests(taskBase): | ||
|
|
||
| def parse_results(self, results_file) -> list: | ||
| ''' | ||
| Read results from a file containing output from JEDI ctests, | ||
| and parse to a list of failed tests | ||
|
|
||
| Parameters: | ||
| results_file: path to a file containing output from bundle ctests | ||
| (e.g. one generated by the RunJediCtests task) | ||
|
|
||
| Returns: | ||
| failed_tests: list of tests failed for the build | ||
| ''' | ||
|
|
||
| with open(results_file, 'r') as f: | ||
| lines = f.readlines() | ||
|
|
||
| if len(lines) == 0: | ||
| raise Exception(f'File {results_file} does not contain results') | ||
|
|
||
| failed_tests = [] | ||
|
|
||
| for line in lines: | ||
| if re.search('- .* \(Failed\)', line): # noqa | ||
| failed_tests.append(line.split('-')[1].split('(Failed)')[0].strip()) | ||
|
|
||
| failed_tests = list(set(failed_tests)) | ||
|
|
||
| return failed_tests | ||
|
|
||
| def execute(self) -> None: | ||
|
|
||
| # Paths to experiments to compare | ||
| experiment_paths = self.config.comparison_experiment_paths() | ||
|
|
||
| # Bundles to consider ctest results for | ||
| bundles = self.config.bundles_to_run_ctests() | ||
|
|
||
| # Attach tags to paths, if not present | ||
| experiment_tag_paths = comparison_tags(experiment_paths, self.logger) | ||
|
|
||
| experiment_tag_1 = list(experiment_tag_paths.keys())[0] | ||
| experiment_tag_2 = list(experiment_tag_paths.keys())[1] | ||
|
|
||
| experiment_path_1 = list(experiment_tag_paths.values())[0] | ||
| experiment_path_2 = list(experiment_tag_paths.values())[1] | ||
|
|
||
| # Paths to the ctest results rendered by the RunJediCtests task | ||
| ctest_path_1 = os.path.join(os.path.dirname(experiment_path_1), '..', 'ctests') | ||
| ctest_path_2 = os.path.join(os.path.dirname(experiment_path_2), '..', 'ctests') | ||
|
|
||
| # Dict tracking all test results | ||
| results_dict = {} | ||
|
|
||
| for bundle in bundles: | ||
| ctest_file_1 = os.path.join(ctest_path_1, f'ctest_results-{bundle}.txt') | ||
| ctest_file_2 = os.path.join(ctest_path_2, f'ctest_results-{bundle}.txt') | ||
|
|
||
| # Parse for failed tests | ||
| failed_results_1 = self.parse_results(ctest_file_1) | ||
| failed_results_2 = self.parse_results(ctest_file_2) | ||
|
|
||
| results_dict[bundle] = {} | ||
|
|
||
| # Track which tests have failed for both builds | ||
| for test in failed_results_1: | ||
| if test not in results_dict[bundle].keys(): | ||
| results_dict[bundle][test] = {experiment_tag_2: 'Pass'} | ||
| results_dict[bundle][test][experiment_tag_1] = 'Fail' | ||
| results_dict[bundle][test]['width'] = len(test) | ||
|
|
||
| for test in failed_results_2: | ||
| if test not in results_dict[bundle].keys(): | ||
| results_dict[bundle][test] = {experiment_tag_1: 'Pass'} | ||
| results_dict[bundle][test][experiment_tag_2] = 'Fail' | ||
| results_dict[bundle][test]['width'] = len(test) | ||
|
|
||
| # Whether the same number of tests pass | ||
| passed = True | ||
|
|
||
| # Format the string for readable output | ||
| results_str = 'JEDI CTest Results Comparison\n' | ||
| results_str += f'{experiment_tag_1}: {experiment_path_1}\n' | ||
| results_str += f'{experiment_tag_2}: {experiment_path_2}\n\n' | ||
|
|
||
| width_col_1 = max(len('Fail'), len(experiment_tag_1)) + 2 | ||
| width_col_2 = max(len('Fail'), len(experiment_tag_2)) + 2 | ||
|
|
||
| for bundle in bundles: | ||
| max_width = max(len(bundle), max([results_dict[bundle][test]['width'] | ||
|
mranst marked this conversation as resolved.
|
||
| for test in results_dict[bundle]])) + 2 | ||
| results_str += bundle + ' ' * (max_width - len(bundle)) | ||
| results_str += experiment_tag_1 + ' ' * (width_col_1 - len(experiment_tag_1)) | ||
| results_str += experiment_tag_2 + ' ' * (width_col_2 - len(experiment_tag_2)) | ||
| results_str += '\n' | ||
| for test in results_dict[bundle].keys(): | ||
| results_str += test + ' ' * (max_width - len(test)) | ||
| result_1 = results_dict[bundle][test][experiment_tag_1] | ||
| result_2 = results_dict[bundle][test][experiment_tag_2] | ||
| if result_1 != result_2: | ||
| passed = False | ||
| results_str += result_1 + ' ' * (width_col_1 - len(result_1)) | ||
| results_str += result_2 + ' ' * (width_col_2 - len(result_2)) | ||
| results_str += '\n' | ||
|
|
||
| results_str += '\n' | ||
|
|
||
| self.logger.info(results_str) | ||
|
|
||
| out_path = os.path.join(self.experiment_path(), 'ctests') | ||
| os.makedirs(out_path, exist_ok=True) | ||
| with open(os.path.join(out_path, 'ctest_comparison.txt'), 'w') as f: | ||
| f.write(results_str) | ||
|
|
||
| if not passed: | ||
| # Send the result to job.err as well | ||
| self.logger.error(results_str) | ||
| raise Exception(f'Differing tests passed between experiments') | ||
|
|
||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
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,55 @@ | ||
|
|
||
| # (C) Copyright 2021- United States Government as represented by the Administrator of the | ||
| # National Aeronautics and Space Administration. All Rights Reserved. | ||
| # | ||
| # This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
|
|
||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
| from swell.tasks.base.task_base import taskBase | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class RunJediCtests(taskBase): | ||
|
|
||
| def execute(self) -> None: | ||
|
|
||
| # Locate the experiment's jedi build dir, must be built or linked first | ||
| build_dir = os.path.join(self.experiment_path(), 'jedi_bundle', 'build') | ||
|
|
||
| # Identify the bundles to run ctests on | ||
| bundles = self.config.bundles_to_run_ctests() | ||
|
|
||
| for bundle in bundles: | ||
| bundle_dir = os.path.join(build_dir, bundle) | ||
|
|
||
| # Run the ctests | ||
| cwd = os.getcwd() | ||
| os.chdir(bundle_dir) | ||
| command = ['ctest', '-V', '-I'] | ||
|
mranst marked this conversation as resolved.
Outdated
|
||
| process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
|
||
| # Record the output | ||
| results, error = process.communicate() | ||
| os.chdir(cwd) | ||
|
|
||
| # Get the output file name | ||
| out_name = f'ctest_results-{bundle}.txt' | ||
|
|
||
| # Make the output directory | ||
| out_path = os.path.join(self.experiment_path(), 'ctests') | ||
| os.makedirs(out_path, exist_ok=True) | ||
|
|
||
| # Write the results | ||
| with open(os.path.join(out_path, out_name), 'w') as f: | ||
| f.write(f'CTest results for {bundle} bundle located at: {bundle_dir}\n') | ||
| f.write(results.decode('utf-8')) | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
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
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
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 |
|---|---|---|
|
|
@@ -357,6 +357,27 @@ class bundles(TaskQuestion): | |
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| @dataclass | ||
| class bundles_to_run_ctests(TaskQuestion): | ||
| default_value: list[str] = mutable_field([ | ||
| "fv3-jedi" | ||
|
Collaborator
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. Don't want to keep you from merging but did you test it with two bundles here? We could add |
||
| ]) | ||
| question_name: str = "bundles_to_run_ctests" | ||
| ask_question: bool = True | ||
| options: list[str] = mutable_field([ | ||
| "fv3-jedi", | ||
| "soca", | ||
| "iodaconv", | ||
| "ufo", | ||
| "ioda", | ||
| "oops", | ||
| "saber" | ||
| ]) | ||
| prompt: str = "Which JEDI bundles to you wish to run ctests on?" | ||
| widget_type: WType = WType.STRING_CHECK_LIST | ||
|
|
||
| # -------------------------------------------------------------------------------------------------- | ||
|
|
||
| @dataclass | ||
| class check_for_obs(TaskQuestion): | ||
| default_value: bool = True | ||
|
|
||
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.