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

Output writer "diagnostic dependencies" #886

Merged
merged 6 commits into from
Sep 2, 2020

Conversation

glwagner
Copy link
Member

This PR introduces the concept of an output writer "diagnostic dependency": a diagnostic which must be added to simulation.diagnostics in order for output to be correct.

If a type of output has a "diagnostic dependency", it must define the function add_dependency!(diagnostics, output), which will add any appropriate diagnostics to the ordered dictionary diagnostics.

Currently we only have one type of output that requires a diagnostic, which is the WindowedTimeAverage. For WindowedTimeAverage, add_dependency! is

add_dependency!(diags, wta::WindowedTimeAverage) = !(wta  values(diags)) && push!(diags, wta)

(As a side note, we could require that all values of diagnostics are unique, which would obviate the check above.)

@glwagner
Copy link
Member Author

I couldn't get tests to work for the NetCDFOutputWriter. @ali-ramadhan can you take a look at

#attributes = Dict(:time_average => Dict("longname" => "A time average",
# "units" => "arbitrary")windowed_time_average_attributes)
#
#dimensions = Dict(:time_average => ("xF", "yC", "zC"))
#
#netcdf_output_writer = NetCDFOutputWriter(model, output, time_interval=4.0, filename="test.nc",
# output_attributes=attributes, dimensions=dimensions)
#
#@test dependencies_added_correctly!(model, windowed_time_average, netcdf_output_writer)

@codecov
Copy link

codecov bot commented Aug 29, 2020

Codecov Report

Merging #886 into master will increase coverage by 0.67%.
The diff coverage is 97.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #886      +/-   ##
==========================================
+ Coverage   70.99%   71.67%   +0.67%     
==========================================
  Files         188      188              
  Lines        5230     5433     +203     
==========================================
+ Hits         3713     3894     +181     
- Misses       1517     1539      +22     
Impacted Files Coverage Δ
src/Simulations/run.jl 93.61% <83.33%> (-1.63%) ⬇️
test/test_output_writers.jl 93.15% <100.00%> (+0.36%) ⬆️
test/test_simulations.jl 100.00% <100.00%> (ø)
src/Fields/field.jl 66.66% <0.00%> (+1.04%) ⬆️
src/AbstractOperations/computations.jl 72.34% <0.00%> (+1.28%) ⬆️
src/Grids/grid_utils.jl 90.50% <0.00%> (+2.33%) ⬆️
src/OutputWriters/netcdf_output_writer.jl 83.33% <0.00%> (+2.81%) ⬆️
src/Diagnostics/average.jl 97.29% <0.00%> (+5.99%) ⬆️
src/Grids/Grids.jl 78.57% <0.00%> (+7.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbbb5f8...d326819. Read the comment docs.

Copy link
Member

@ali-ramadhan ali-ramadhan left a comment

Choose a reason for hiding this comment

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

Fixed the NetCDFOutputWriter test for dependencies_added_correctly! so it passes now. I think since it goes through a C library, NetCDFOutputWriter needs strings as keys, while it was using symbols. Annoying, but probably a NetCDF limitation.

Also, simulations are tested before output writers so I'm slightly concerned that we are relying on output writers before they are tested so there's no guarantee they even work. I.e. the dependencies_added_correctly! tests should go into test_output_writers.jl.

@@ -44,6 +46,12 @@ function wall_time_limit_exceeded(sim)
return false
end

add_dependency!(diagnostics, output) = nothing # fallback
add_dependency!(diags, wta::WindowedTimeAverage) = !(wta ∈ values(diags)) && push!(diags, wta)
Copy link
Member

Choose a reason for hiding this comment

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

I would probably write this as

wta  values(diags) || push!(diags, wta)

but maybe it's a bit more obfuscated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh that's nice.

@glwagner
Copy link
Member Author

glwagner commented Sep 1, 2020

@ali-ramadhan I'll move the tests to test_output_writers.jl.

@glwagner
Copy link
Member Author

glwagner commented Sep 1, 2020

@ali-ramadhan can you restart gitlab?

@glwagner glwagner merged commit edcedc3 into master Sep 2, 2020
@glwagner glwagner deleted the glw/diagnostic-dependencies branch September 2, 2020 16:30
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.

2 participants