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

EAMxx: extract diagnostic creation logic outside of output class #6796

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

bartgol
Copy link
Contributor

@bartgol bartgol commented Dec 4, 2024

Extract creation of diagnostic classes out of the AtmosphereOutput class and into its own routine.


This allows to

  • reduce length of scorpio_output.cpp (which is way too long)
  • make the logic we use to translate a diag name into a diag object more transparent and less hidden
  • ability to unit test this logic without having to create output streams.

To avoid issues like the ones discussed in this conversation, we now use std::regex. The regexes look for special strings (such at "at_500mb") at the end of the diagnostic field name. This ensures that we pipe diagnostics correclty, and process them one at a time. In particular, parsing somethin like blah_at_500hPa_atm_backtend is univokely parsed as "the back-tendency of the field blah_at_500hPa", the latter being itself a diagnostic to be created once the output class process the "outer" diagnostic inputs.

Side note: it is different to request T_mid_at_500hPa_atm_backtend vs T_mid_atm_backtend_at_500hPa, since the two diags are nested in specular ways. In the end, the result should be similar (up to roundings/truncations), but computationally speaking, one of the two may be cheaper than the other.

This GM is useful for unit tests, but more generally for situations
where only grids are avaialble, but interfaces require a grids manager.
@bartgol bartgol added BFB PR leaves answers BFB EAMxx PRs focused on capabilities for EAMxx code cleanup labels Dec 4, 2024
@bartgol bartgol requested a review from mahf708 December 4, 2024 00:48
@bartgol bartgol self-assigned this Dec 4, 2024
Copy link

github-actions bot commented Dec 4, 2024

PR Preview Action v1.4.8
🚀 Deployed preview to https://E3SM-Project.github.io/E3SM/pr-preview/pr-6796/
on branch gh-pages at 2024-12-04 00:50 UTC

@bartgol bartgol force-pushed the bartgol/eamxx/encapsulate-diagnostics-creation branch 2 times, most recently from 7710d70 to 52ae29f Compare December 4, 2024 15:57
* Add free function to build a diagnostic obj from a diag field name
* Adapt existing diags so that their name is "static", rather than
  matching the diag field name
* Adapt AtmosphereOutput to use this utility. Enhances encapsulation,
  and avoids hiding the diag naming convention deep in the IO class
@bartgol bartgol force-pushed the bartgol/eamxx/encapsulate-diagnostics-creation branch from 52ae29f to a851099 Compare December 4, 2024 16:24
Copy link
Contributor

@mahf708 mahf708 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment that doesn't have to be addressed right away (maybe I am slow this morning and I couldn't figure it out)

// Construct a diagnostic by this name
ekat::ParameterList params;
std::string diag_name;
// Some diags need some extra setup or trigger extra behaviors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear to me what the FieldAtXyz diag needs this special-casing ... consider adding an explicit comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the gh diff may make it hard to see, with the red lines intertwined with the green lines. If you look at the file, it should be clear, since it's right there: we possibly set the mast value in the params list, and we trigger avg count.

Now, why we do those things, that may indeed not be obvious, so I'll add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, why do we need to trigger the avg counts, etc. for only the FieldAtXyz ones? That was my confusion... Is there something special?

Copy link
Contributor Author

@bartgol bartgol Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, FieldAtHeight and FieldAtPressure may request to find the value outside what's actually in the model (e.g., FieldAtPressure for 1000mbar is OOB on mount Everest), which generates FillValue entries in the diag. When we do averaging, we don't want to count the FillValue entries, so we keep track of how many time samples are actuall valid (and we keep a separate count for each column), so that we can only average those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, shouldn't we let all diags do that btw? AodVis does assign fillvals

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all diags create fill value. If Aodvis does, then yes, we should handle that too. We could maybe think of adding a method to AtmosphereDiagnostic, something like "bool can_generate_fill_value()" so that we don't have to do all these if/else...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since I was responsible for adding those, I can handle them in a subsequent PR. For the record, both atm_backtend and aodvis use fill_value. For aodvis, to fill nighttime indices. For atm_backtend, for undefined behavior in the first step

@mahf708
Copy link
Contributor

mahf708 commented Dec 5, 2024

@bartgol are you happy with the state of this? I can take care of the other diags needing the fillval treatment in subsequent PRs (no need to address that now). If so you could merge at your convenience :)

@bartgol bartgol merged commit 4b58ed4 into master Dec 5, 2024
16 of 20 checks passed
@bartgol bartgol deleted the bartgol/eamxx/encapsulate-diagnostics-creation branch December 5, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BFB PR leaves answers BFB code cleanup EAMxx PRs focused on capabilities for EAMxx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants