-
Notifications
You must be signed in to change notification settings - Fork 15
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
Improve input validation and testing #628
Conversation
5cddd93
to
ee8d74b
Compare
0820d07
to
f8acf41
Compare
bundle = "bundle3" # Let bundle1 finish first because "e3sm_diags: atm_monthly_180x360_aave_mvm" requires "ts: atm_monthly_180x360_aave" | ||
scratch = "#expand scratch#zppy_weekly_bundles_scratch/#expand unique_id#/#expand case_name#" | ||
years = "1985:1989:2", | ||
# TODO: Add "tc_analysis" back in after empty dat is resolved. |
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.
tc_analysis
must be excluded for now because of E3SM-Project/e3sm_diags#866 (comment)
shutil.copy( | ||
path_to_actual_png, | ||
os.path.join(diff_dir, "{}_actual.png".format(simple_image_name)), | ||
os.path.join(diff_dir, "{}_actual.png".format(image_name)), |
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.
Resolves #358
# If cyclones_stitch file is empty, exit | ||
if ! [ -s ${result_dir}cyclones_stitch_${file_name}.dat ]; then | ||
cd {{ scriptDir }} | ||
echo 'ERROR (1)' > {{ prefix }}.status | ||
exit 1 | ||
fi | ||
|
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.
Catches the error in E3SM-Project/e3sm_diags#866 (comment).
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.
@forsyth2 I suggest not to catch this error, so that othere3sm_diags
runs won't be blocked by empty stitch files.
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.
Based on your comment here: #632 (comment).
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.
@chengzhuzhang I think it would be a mistake to let errors slide by silently, especially considering this one was hard to track down.
A couple options on the top of my mind:
- Leave this as-is. If
tc_analysis
fails because of this, then users can removetc_analysis
from their list of sets in thee3sm_diags
task and then re-runzppy
. - Have a parameter something like
fail_on_empty_stitch
to toggle this error on/off
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.
My take is that this is not an error, just no cyclone is detected. Without catching the error, it should work more smoothly, we can print in the log that indicate no cyclone stitch file is generated.
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.
That makes sense, but it does cause an error in E3SM Diags down the road then. Notably, the IndexError: list index out of range
error on #625 (comment) didn't add much clarity to the error.
I think if we remove this error check in the tc_analysis
bash script (which I agree we should do if it's not actually an error per-se), we should add an empty-dat check in the e3sm_diags
task.
I've copied the stack trace again here:
Traceback (most recent call last):
File "/home/ac.forsyth2/miniconda3/envs/e3sm_diags_1003/lib/python3.10/site-packages/e3sm_diags/parameter/core_parameter.py", line 266, in _run_diag
single_result = module.run_diag(self)
File "/home/ac.forsyth2/miniconda3/envs/e3sm_diags_1003/lib/python3.10/site-packages/e3sm_diags/driver/tc_analysis_driver.py", line 91, in run_diag
test_data["metrics"] = generate_tc_metrics_from_te_stitch_file(test_te_file)
File "/home/ac.forsyth2/miniconda3/envs/e3sm_diags_1003/lib/python3.10/site-packages/e3sm_diags/driver/tc_analysis_driver.py", line 172, in generate_tc_metrics_from_te_stitch_file
te_stitch_vars = _get_vars_from_te_stitch(lines, max_len, num_storms)
File "/home/ac.forsyth2/miniconda3/envs/e3sm_diags_1003/lib/python3.10/site-packages/e3sm_diags/driver/tc_analysis_driver.py", line 249, in _get_vars_from_te_stitch
year_start = int(lines[0].split("\t")[2])
IndexError: list index out of range
test_te_file = os.path.join(
test_data_path,
"cyclones_stitch_{}_{}_{}.dat".format(test_name, test_start_yr, test_end_yr),
)
So, it would be nice to add a non-empty check to that test_te_file
. Based on the stack trace, it would probably be easier to add that in e3sm_diags
than in zppy
.
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.
Yes, it makes sense to catch it in e3sm_diags. This error doesn't affect other non tc_analysis
sets, right?
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.
Sounds good. And no, I don't think these dat
files are used in any other sets. The TC analysis task isn't even a dependency for any other set:
if "tc_analysis" in c["sets"]:
dependencies.append(os.path.join(script_dir, f"tc_analysis{status_suffix}"))
f8acf41
to
4e8de5a
Compare
Issue resolution
Select one: This pull request is...
1. Does this do what we want it to do?
Objectives:
Adding "defensive programming" techniques to catch bad input early.
Functional code:
guess_path_parameters
&guess_section_parameters
parameters, defaulting to True, to keep backwards compatibility. Setting to False allows for more transparency of what paths are being used.climo_diurnal_frequency
check.fail_on_dependency_skip
parameter, defaulting to False, to keep backwards compatibility. Setting to True stops zppy if any job launch fails.dat
file is empty.Testing:
ts
subtask to support the tropical_subseasonal e3sm_diags set.simple_image_name
so that all image check failures actually show up in the web's diff directory. Resolves Clarify simple_image_name #358.Required:
IO
monad were the code written in Haskell).If applicable:
fail_on_dependency_skip
(False
on v2,v3 tests;True
on bundles tests) ,guess_path_parameters
,guess_section_parameters
(False
on v3 tests;True
on v2, bundles tests)2. Are the implementation details accurate & efficient?
Required:
If applicable:
zppy/conda
, not just animport
statement.3. Is this well documented?
Required:
zppy
documentation is through reading parameter comments ondefault.ini
.4. Is this code clean?
Required:
If applicable: