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

Clear ALL_DIAGNOSTICS in define_diagnostics #977

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imreddyTeja
Copy link
Contributor

@imreddyTeja imreddyTeja commented Jan 11, 2025

Purpose

Closes #955

When a simulation is re-run by re-including the experiment script, many diagnostic overwrite warnings are logged. This PR proposes a fix where only a single warning is logged.

The many warnings occur when default_diagnostics is called. default_diagnostics calls define_diagnostics!, which repeatedly calls add_diagnostic_variable, which throws a warning.

One idea is to not overwrite and warn when the DiagnosticVariable being overwritten has not changed. This cannot be done because the compute! fields cannot be checked for equivalence as they are anonymous functions. Facilitating this would require changes to ClimaDiagnostics that allow compute! to not be an anonymous function.

Another option I considered is making ALL_DIAGNOSTICS non global, and make a new one when default_diagnostics is called. This would change the interface and functionality, so I decided against it.

To-do

Content

This commit makes the define_diagnostics function clear ALL_DIAGNOSTICS. The dictionary is only cleared when it has data, and a warning is given. This prevents each add_diagnostic_variable call in define_diagnostics from logging overwrite warnings.

This only changes the resulting diagnostics when a user calls add_diagnostic_variable! and then calls define_diagnostics! or default_diagnostics. This desired result could still be achieved by swapping the orders of the call.


  • I have read and checked the items on the review checklist.

This commit makes the `define_diagnostics` function
clear `ALL_DIAGNOSTICS`. The dictionary is only cleared
when it has data, and a warning is given. This prevents
each `add_diagnostic_variable` call in `define_diagnostics` from
throwing overwrite warnings.

This only changes the resulting diagnostics when a user calls `add_diagnostic_variable!`
and then calls `define_diagnostics!` or `default_diagnostics`. This desired result
could still be achieved by swapping the orders of the call.
@imreddyTeja imreddyTeja force-pushed the tr/restart-diagnostics-warnings branch from d8a3f69 to e5d00f4 Compare January 13, 2025 17:34
@imreddyTeja imreddyTeja marked this pull request as ready for review January 14, 2025 16:20
Copy link
Member

@AlexisRenchon AlexisRenchon left a comment

Choose a reason for hiding this comment

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

This is great! Thank you Teja

@Sbozzolo
Copy link
Member

I am not sure if this is the best solution. Users could add their own diagnostics in ALL_DIAGNOSTICS, and this would remove them, while only adding back the default ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rerunning simulations leads to a lot of warnings about diagnostics
3 participants