Skip to content

Commit

Permalink
ClimaDiagnostics 0.0.1
Browse files Browse the repository at this point in the history
It is a good early draft
  • Loading branch information
Sbozzolo committed Apr 3, 2024
1 parent c8fb159 commit d8f5bc0
Show file tree
Hide file tree
Showing 30 changed files with 1,998 additions and 900 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
41 changes: 41 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on:
pull_request:
push:
branches:
- main
tags: '*'

# Needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
climadiagnostics:
runs-on: ubuntu-latest
strategy:
matrix:
version:
- '1.9'
- '1.10'
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@latest
- uses: codecov/codecov-action@v4
with:
files: lcov.info
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CompatHelper

on:
schedule:
- cron: '00 00 * * *'

jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
28 changes: 28 additions & 0 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Documentation

on:
push:
branches:
- main
pull_request:
tags: '*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: 1
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ docs/make.jl
14 changes: 14 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: TagBot
on:
issue_comment:
types:
- created
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
76 changes: 72 additions & 4 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.0"
julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "cdeef9b141080e066a2723370b0023ce6ad799b1"
project_hash = "5483fa0b563f8745422df8ee3f196ad3888c38e9"

[[deps.ADTypes]]
git-tree-sha1 = "016833eb52ba2d6bea9fcb50ca295980e728ee24"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
version = "0.2.7"

[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -218,6 +223,11 @@ git-tree-sha1 = "d7d7b58e149f19c322840a50d1bc20e8c23addb4"
uuid = "1fbeeb36-5f17-413c-809b-666fb144f157"
version = "0.3.5"

[[deps.CommonSolve]]
git-tree-sha1 = "0eee5eb66b1cf62cd6ad1b460238e60e4b09400c"
uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
version = "0.2.4"

[[deps.CommonSubexpressions]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7"
Expand All @@ -237,7 +247,7 @@ weakdeps = ["Dates", "LinearAlgebra"]
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.0.5+1"
version = "1.1.0+0"

[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
Expand Down Expand Up @@ -334,6 +344,11 @@ git-tree-sha1 = "71c79e77221ab3a29918aaf6db4f217b89138608"
uuid = "b305315f-e792-5b7a-8f41-49f472929428"
version = "1.0.1"

[[deps.EnumX]]
git-tree-sha1 = "bdb1942cd4c45e3c678fd11569d5cccd80976237"
uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
version = "1.0.4"

[[deps.ExprTools]]
git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Expand Down Expand Up @@ -386,6 +401,17 @@ weakdeps = ["StaticArrays"]
[deps.ForwardDiff.extensions]
ForwardDiffStaticArraysExt = "StaticArrays"

[[deps.FunctionWrappers]]
git-tree-sha1 = "d62485945ce5ae9c0c48f124a84998d755bae00e"
uuid = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
version = "1.1.3"

[[deps.FunctionWrappersWrappers]]
deps = ["FunctionWrappers"]
git-tree-sha1 = "b104d487b34566608f8b4e1c39fb0b10aa279ff8"
uuid = "77dc65aa-8811-40c2-897b-53d922fa7daf"
version = "0.1.3"

[[deps.Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
Expand Down Expand Up @@ -764,7 +790,7 @@ weakdeps = ["Adapt"]
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+2"
version = "0.3.23+4"

[[deps.OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down Expand Up @@ -928,6 +954,42 @@ version = "0.5.12"
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.SciMLBase]]
deps = ["ADTypes", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "Printf", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "SciMLStructures", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"]
git-tree-sha1 = "d15c65e25615272e1b1c5edb1d307484c7942824"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
version = "2.31.0"

[deps.SciMLBase.extensions]
SciMLBaseChainRulesCoreExt = "ChainRulesCore"
SciMLBaseMakieExt = "Makie"
SciMLBasePartialFunctionsExt = "PartialFunctions"
SciMLBasePyCallExt = "PyCall"
SciMLBasePythonCallExt = "PythonCall"
SciMLBaseRCallExt = "RCall"
SciMLBaseZygoteExt = "Zygote"

[deps.SciMLBase.weakdeps]
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[[deps.SciMLOperators]]
deps = ["ArrayInterface", "DocStringExtensions", "LinearAlgebra", "MacroTools", "Setfield", "SparseArrays", "StaticArraysCore"]
git-tree-sha1 = "10499f619ef6e890f3f4a38914481cc868689cd5"
uuid = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
version = "0.3.8"

[[deps.SciMLStructures]]
git-tree-sha1 = "5833c10ce83d690c124beedfe5f621b50b02ba4d"
uuid = "53ae85a6-f571-4167-b2af-e1d143709226"
version = "1.1.0"

[[deps.Scratch]]
deps = ["Dates"]
git-tree-sha1 = "3bac05bc7e74a75fd9cba4295cde4045d9fe2386"
Expand All @@ -943,6 +1005,12 @@ version = "1.4.1"
[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.Setfield]]
deps = ["ConstructionBase", "Future", "MacroTools", "StaticArraysCore"]
git-tree-sha1 = "e2cc6d8c88613c05e1defb55170bf5ff211fbeac"
uuid = "efcf1570-3423-57d1-acb7-fd33fddbac46"
version = "1.1.1"

[[deps.Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

Expand Down
11 changes: 10 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
name = "ClimaDiagnostics"
uuid = "1ecacbb8-0713-4841-9a07-eb5aa8a2d53f"
authors = ["Gabriele Bozzola <[email protected]>"]
version = "0.1.0"
version = "0.0.1"

[deps]
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"

[compat]
Aqua = "0.8"
ClimaComms = "0.5"
ClimaCore = "0.13"
ClimaTimeSteppers = "0.7"
Documenter = "1"
JuliaFormatter = "1"
NCDatasets = "0.13, 0.14"
SafeTestsets = "0.1"
SciMLBase = "1, 2"
Test = "1"
julia = "1.9"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ClimaTimeSteppers = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "ClimaTimeSteppers", "Documenter", "JuliaFormatter", "SafeTestsets", "Test"]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@
<img src="logo.svg" width="180px"> <br>
ClimaDiagnostics.jl
</h1>

`ClimaDiagnostics.jl` provides a simple framework to add diagnostics to `CliMA`
simulations.

`ClimaDiagnostics.jl`defined two important concepts:
- `DiagnosticVariable`: A recipe to compute a diagnostic from the integrator
alongside with names, units, comments.
- `ScheduledDiagnostic`: When to compute and output the `DiagnosticVariable` and
what type of accumulation to perform.

To add the diagnostics to a simulation from a list of `ScheduledDiagnostic`s,
one first needs to initialize them with `diagnostic_handler =
DiagnosticHandler(diangostics, Y, p, t; dt)`, and finally add the
`DiagnosticsCallback(diagnostic_handler)` callback to the integrator.

> :warning: README under construction. While we work on the README, you can find
> all the relevant information in the
> [documentation](https://clima.github.io/ClimaDiagnostics.jl/dev/).
4 changes: 3 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# `ClimaDiagnostics.jl`

`ClimaDiagnostics.jl`
`ClimaDiagnostics.jl`



40 changes: 40 additions & 0 deletions docs/src/internals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

## Accumulation

Several diagnostics require performing reductions, such as taking the maximum or
the average. Since it is not feasible to store all the lists of all the
intermediate values, we aggregate the results in specific storage areas (e.g.,
we take `max(max(max(max(t1, t2), t3), t4), t5)` instead of `max(t1, t2, t3, t4,
t5)` In this, it is convenient to preallocate the space where we want to
accumulate the intermediate.

Accumulation is accomplished by the `accumulate!` function. All this function
does is applying the binary `reduction_time_func` to the previous accumulated
value and the newly computed one and store the output to the accumulator.




After an accumulated variable is output, the accumulator is reset to its natural
state. This is achieved with the `reset_accumulator!` function.



However, we have to fill the space with something
that does not affect the reduction. This, by definition, is the identity of the
operation. The identity of the operation `+` is `0` because `x + 0 = x` for
every `x`.

We have to know the identity for every operation we want to support. Of course,
users are welcome to define their own by adding new methods to
identity_of_reduction.

For instance, to define the identity of the reduction `-`, one would write
```julia
function ClimaDiagnostics.Diagnostics.identity_of_reduction(::typeof(-))
return 0
end
```
(Or add this to the `reduction_identities.jl` file.)


15 changes: 15 additions & 0 deletions src/AbstractTypes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Abstract types needed across submodules

"""
AbstractWriter
An object that knows how to save some output.
`AbstractWriter`s have to provide one function, `write_field!`
The function has to have singature
`write_field!(writer::Writer, field, diagnostic::ScheduledDiagnostic, u, p, t)`
It is up to the writer to implment this
"""
abstract type AbstractWriter end
Loading

2 comments on commit d8f5bc0

@Sbozzolo
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/104161

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.0.1 -m "<description of version>" d8f5bc0e2a5fce2b5034a9a23781a699a0656ed2
git push origin v0.0.1

Please sign in to comment.