Skip to content

Commit

Permalink
Add support for reading input maps
Browse files Browse the repository at this point in the history
Okay, this is a massive commit (and I feel bad about it).

This commit splits PrescribedDataStatic and PrescibedDataTemporal in
multiple independent modules.

Before, PrescribedData was:
- reading files
- regridding
- discovering dates available
- interpolating
- taking care of edge cases (e.g., what to do when reading outside of
where the date is outside of the definition range)

This commit splits all the different functions in different independent
modules so that they can be more easily maintained and upgraded.

This commit also introduces InterpolationsRemapper, which uses
Interpolations.jl to do online/ and distributed remapping from files.

This will soon be needed to efficiently support reading and buffering
reads for GPU runs.
  • Loading branch information
Sbozzolo committed Mar 19, 2024
1 parent 308dbfc commit 1f020ff
Show file tree
Hide file tree
Showing 25 changed files with 1,503 additions and 1,592 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Insolation = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
Expand All @@ -38,12 +39,12 @@ CreateParametersExt = "ClimaParams"
Adapt = "3, 4"
ArtifactWrappers = "0.2"
CFTime = "0.1"
ClimaParams = "0.10.2"
CSV = "0.10"
CUDA = "5"
ClimaComms = "0.5.6"
ClimaCore = "0.13.2"
ClimaCoreTempestRemap = "0.3"
ClimaParams = "0.10.2"
DataFrames = "1"
Dates = "1"
DocStringExtensions = "0.8, 0.9"
Expand Down
18 changes: 9 additions & 9 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.1"
julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "5f713b750235cf07465e21e92a6bd2f152ad3358"

Expand Down Expand Up @@ -273,9 +273,9 @@ version = "0.5.7"

[[deps.ClimaCore]]
deps = ["Adapt", "BandedMatrices", "BlockArrays", "CUDA", "ClimaComms", "CubedSphere", "DataStructures", "DocStringExtensions", "ForwardDiff", "GaussQuadrature", "GilbertCurves", "HDF5", "InteractiveUtils", "IntervalSets", "KrylovKit", "LinearAlgebra", "PkgVersion", "RecursiveArrayTools", "RootSolvers", "SparseArrays", "Static", "StaticArrays", "Statistics", "Unrolled"]
git-tree-sha1 = "bc6a0154e3bcc1657d3a75f697e216fb70121969"
git-tree-sha1 = "844afbd6a7c4f112f974e0031ebf4fb13d0b4157"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
version = "0.13.2"
version = "0.13.1"
weakdeps = ["Krylov"]

[deps.ClimaCore.extensions]
Expand All @@ -299,9 +299,9 @@ weakdeps = ["ClimaParams"]

[[deps.ClimaParams]]
deps = ["DocStringExtensions", "TOML", "Test"]
git-tree-sha1 = "ec67949db856e01df4cbf7d6ddafefeda02f93ee"
git-tree-sha1 = "323dd6c5423caf31f0da81bb9c288683cbdafb01"
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
version = "0.10.3"
version = "0.10.2"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
Expand Down Expand Up @@ -379,7 +379,7 @@ weakdeps = ["Dates", "LinearAlgebra"]
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.0+0"
version = "1.0.5+1"

[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
Expand All @@ -394,9 +394,9 @@ version = "0.1.2"

[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "6cbbd4d241d7e6579ab354737f4dd95ca43946e1"
git-tree-sha1 = "9c4708e3ed2b799e6124b5673a712dda0b596a9b"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.1"
version = "2.3.1"

[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -1495,7 +1495,7 @@ version = "0.3.24+0"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+4"
version = "0.3.23+2"

[[deps.OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down
6 changes: 3 additions & 3 deletions docs/src/APIs/Regridder.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Bucket

```@meta
CurrentModule = ClimaLand.Regridder
CurrentModule = ClimaLand.Regridders
```

## Functions

```@docs
ClimaLand.Regridder.hdwrite_regridfile_rll_to_cgll
ClimaLand.Regridder.swap_space
ClimaLand.Regridders.hdwrite_regridfile_rll_to_cgll
ClimaLand.Regridders.swap_space
```
18 changes: 9 additions & 9 deletions experiments/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.1"
julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "960bdc0a1ed4b3f2aee66ed2e0c02065769614a9"

Expand Down Expand Up @@ -330,9 +330,9 @@ version = "0.5.7"

[[deps.ClimaCore]]
deps = ["Adapt", "BandedMatrices", "BlockArrays", "CUDA", "ClimaComms", "CubedSphere", "DataStructures", "DocStringExtensions", "ForwardDiff", "GaussQuadrature", "GilbertCurves", "HDF5", "InteractiveUtils", "IntervalSets", "KrylovKit", "LinearAlgebra", "PkgVersion", "RecursiveArrayTools", "RootSolvers", "SparseArrays", "Static", "StaticArrays", "Statistics", "Unrolled"]
git-tree-sha1 = "bc6a0154e3bcc1657d3a75f697e216fb70121969"
git-tree-sha1 = "844afbd6a7c4f112f974e0031ebf4fb13d0b4157"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
version = "0.13.2"
version = "0.13.1"
weakdeps = ["Krylov"]

[deps.ClimaCore.extensions]
Expand All @@ -356,9 +356,9 @@ weakdeps = ["ClimaParams"]

[[deps.ClimaParams]]
deps = ["DocStringExtensions", "TOML", "Test"]
git-tree-sha1 = "ec67949db856e01df4cbf7d6ddafefeda02f93ee"
git-tree-sha1 = "323dd6c5423caf31f0da81bb9c288683cbdafb01"
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
version = "0.10.3"
version = "0.10.2"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
Expand Down Expand Up @@ -453,7 +453,7 @@ weakdeps = ["Dates", "LinearAlgebra"]
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.0+0"
version = "1.0.5+1"

[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
Expand All @@ -468,9 +468,9 @@ version = "0.1.2"

[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "6cbbd4d241d7e6579ab354737f4dd95ca43946e1"
git-tree-sha1 = "9c4708e3ed2b799e6124b5673a712dda0b596a9b"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.1"
version = "2.3.1"

[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -1793,7 +1793,7 @@ version = "0.3.24+0"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+4"
version = "0.3.23+2"

[[deps.OpenEXR]]
deps = ["Colors", "FileIO", "OpenEXR_jll"]
Expand Down
17 changes: 4 additions & 13 deletions experiments/standalone/Bucket/global_bucket_staticmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,9 @@ tf = 7 * 86400;
Δt = 3600.0;

# Construct albedo parameter object using static map
# Use separate regridding directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
regrid_dir = joinpath(
pkgdir(ClimaLand),
"experiments/standalone/Bucket/$device_suffix/regrid-static/",
)
!ispath(regrid_dir) && mkpath(regrid_dir)
surface_space = bucket_domain.space.surface
α_snow = FT(0.8)
albedo = PrescribedBaregroundAlbedo{FT}(α_snow, regrid_dir, surface_space);
albedo = PrescribedBaregroundAlbedo{FT}(α_snow, surface_space);

bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);

Expand Down Expand Up @@ -213,6 +204,9 @@ F_sfc = [
];

# save prognostic state to CSV - for comparison between GPU and CPU output
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
open(joinpath(outdir, "tf_state_$device_suffix.txt"), "w") do io
writedlm(io, hcat(T_sfc[end][:], W[end][:], Ws[end][:], σS[end][:]), ',')
end;
Expand Down Expand Up @@ -261,6 +255,3 @@ for (i, (field_ts, field_name)) in enumerate(
end
outfile = joinpath(outdir, string("ts_$device_suffix.png"))
CairoMakie.save(outfile, fig_ts)

# delete regrid directory
rm(regrid_dir, recursive = true)
21 changes: 5 additions & 16 deletions experiments/standalone/Bucket/global_bucket_temporalmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,12 @@ outdir = joinpath(
"experiments/standalone/Bucket/artifacts_temporalmap",
)
!ispath(outdir) && mkpath(outdir)
# Use separate output directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
regrid_dir = joinpath(
pkgdir(ClimaLand),
"experiments/standalone/Bucket/$device_suffix/regrid-temporal/",
)
!ispath(regrid_dir) && mkpath(regrid_dir)

t0 = 0.0;
# run for 50 days to test monthly file update
tf = 50 * 86400;
Δt = 3600.0;


function setup_prob(t0, tf, Δt)
# We set up the problem in a function so that we can make multiple copies (for profiling)

Expand All @@ -108,8 +99,7 @@ function setup_prob(t0, tf, Δt)

surface_space = bucket_domain.space.surface
# Construct albedo parameter object using temporal map
albedo =
PrescribedSurfaceAlbedo{FT}(regrid_dir, ref_time, t0, surface_space)
albedo = PrescribedSurfaceAlbedo{FT}(ref_time, t0, surface_space)

bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc)

Expand Down Expand Up @@ -148,7 +138,6 @@ function setup_prob(t0, tf, Δt)
ref_time,
)


model = BucketModel(
parameters = bucket_parameters,
domain = bucket_domain,
Expand Down Expand Up @@ -262,6 +251,9 @@ F_sfc = [
];

# save prognostic state to CSV - for comparison between GPU and CPU output
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
open(joinpath(outdir, "tf_state_$device_suffix.txt"), "w") do io
writedlm(io, hcat(T_sfc[end][:], W[end][:], Ws[end][:], σS[end][:]), ',')
end;
Expand Down Expand Up @@ -310,6 +302,3 @@ for (i, (field_ts, field_name)) in enumerate(
end
outfile = joinpath(outdir, string("ts_$device_suffix.png"))
CairoMakie.save(outfile, fig_ts)

# delete regrid directory
rm(regrid_dir, recursive = true)
7 changes: 4 additions & 3 deletions src/ClimaLand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ include("shared_utilities/Parameters.jl")
import .Parameters as LP

include("shared_utilities/general_utils.jl")
include("shared_utilities/Domains.jl")
include("shared_utilities/FileReaders.jl")
include("shared_utilities/Regridders.jl")
include("shared_utilities/DataHandling.jl")
include("shared_utilities/TimeVaryingInputs.jl")
using .TimeVaryingInputs
export TimeVaryingInput, evaluate!
include("shared_utilities/Regridder.jl")
include("shared_utilities/Domains.jl")
include("shared_utilities/FileReader.jl")
include("shared_utilities/SpaceVaryingInputs.jl")
using .SpaceVaryingInputs
export SpaceVaryingInput
Expand Down
Loading

0 comments on commit 1f020ff

Please sign in to comment.