Skip to content

Commit a3cdf37

Browse files
committed
debug plots work cpu
1 parent 37c9e6b commit a3cdf37

File tree

3 files changed

+93
-49
lines changed

3 files changed

+93
-49
lines changed

experiments/AMIP/Manifest.toml

+29-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.10.2"
44
manifest_format = "2.0"
5-
project_hash = "a198c94037ccdef0790bbbb0c9a214fd17aa95f9"
5+
project_hash = "284db48dcd39d58ad8518daa0c1caded1552fa4a"
66

77
[[deps.ADTypes]]
88
git-tree-sha1 = "016833eb52ba2d6bea9fcb50ca295980e728ee24"
@@ -150,9 +150,9 @@ version = "0.4.2"
150150

151151
[[deps.BandedMatrices]]
152152
deps = ["ArrayLayouts", "FillArrays", "LinearAlgebra", "PrecompileTools"]
153-
git-tree-sha1 = "fe7ed7b33416db994f706f66e31bbd1b378f71b7"
153+
git-tree-sha1 = "c946c5014cf4cdbfacacb363b110e7bffba3e742"
154154
uuid = "aae01518-5342-5314-be14-df237901396f"
155-
version = "1.6.0"
155+
version = "1.6.1"
156156
weakdeps = ["SparseArrays"]
157157

158158
[deps.BandedMatrices.extensions]
@@ -397,9 +397,9 @@ weakdeps = ["ClimaParams"]
397397

398398
[[deps.ClimaParams]]
399399
deps = ["DocStringExtensions", "TOML", "Test"]
400-
git-tree-sha1 = "ec67949db856e01df4cbf7d6ddafefeda02f93ee"
400+
git-tree-sha1 = "1a3d2455fff201bcf130bbd5a71ac16fc3c21fd1"
401401
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
402-
version = "0.10.3"
402+
version = "0.10.4"
403403

404404
[[deps.ClimaTimeSteppers]]
405405
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
@@ -521,9 +521,9 @@ version = "2.4.1"
521521

522522
[[deps.ConstructionBase]]
523523
deps = ["LinearAlgebra"]
524-
git-tree-sha1 = "c53fc348ca4d40d7b371e71fd52251839080cbc9"
524+
git-tree-sha1 = "260fd2400ed2dab602a7c15cf10c1933c59930a2"
525525
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
526-
version = "1.5.4"
526+
version = "1.5.5"
527527
weakdeps = ["IntervalSets", "StaticArrays"]
528528

529529
[deps.ConstructionBase.extensions]
@@ -850,9 +850,9 @@ version = "0.3.1"
850850

851851
[[deps.FileIO]]
852852
deps = ["Pkg", "Requires", "UUIDs"]
853-
git-tree-sha1 = "c5c28c245101bd59154f649e19b038d15901b5dc"
853+
git-tree-sha1 = "82d8afa92ecf4b52d78d869f038ebfb881267322"
854854
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
855-
version = "1.16.2"
855+
version = "1.16.3"
856856

857857
[[deps.FilePaths]]
858858
deps = ["FilePathsBase", "MacroTools", "Reexport", "Requires"]
@@ -905,9 +905,9 @@ version = "0.8.4"
905905

906906
[[deps.Flux]]
907907
deps = ["Adapt", "ChainRulesCore", "Compat", "Functors", "LinearAlgebra", "MLUtils", "MacroTools", "NNlib", "OneHotArrays", "Optimisers", "Preferences", "ProgressLogging", "Random", "Reexport", "SparseArrays", "SpecialFunctions", "Statistics", "Zygote"]
908-
git-tree-sha1 = "5a626d6ef24ae0a8590c22dc12096fb65eb66325"
908+
git-tree-sha1 = "502d0232ec6430d40b6e5b57637333f32192592e"
909909
uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c"
910-
version = "0.14.13"
910+
version = "0.14.14"
911911

912912
[deps.Flux.extensions]
913913
FluxAMDGPUExt = "AMDGPU"
@@ -1127,9 +1127,9 @@ version = "1.3.14+0"
11271127

11281128
[[deps.GridLayoutBase]]
11291129
deps = ["GeometryBasics", "InteractiveUtils", "Observables"]
1130-
git-tree-sha1 = "af13a277efd8a6e716d79ef635d5342ccb75be61"
1130+
git-tree-sha1 = "6f93a83ca11346771a93bbde2bdad2f65b61498f"
11311131
uuid = "3955a311-db13-416c-9275-1d80ed98e5e9"
1132-
version = "0.10.0"
1132+
version = "0.10.2"
11331133

11341134
[[deps.Grisu]]
11351135
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
@@ -1154,9 +1154,9 @@ version = "1.14.3+1"
11541154

11551155
[[deps.HTTP]]
11561156
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
1157-
git-tree-sha1 = "db864f2d91f68a5912937af80327d288ea1f3aee"
1157+
git-tree-sha1 = "995f762e0182ebc50548c434c171a5bb6635f8e4"
11581158
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1159-
version = "1.10.3"
1159+
version = "1.10.4"
11601160

11611161
[[deps.HarfBuzz_jll]]
11621162
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"]
@@ -1430,9 +1430,9 @@ version = "3.0.0+1"
14301430

14311431
[[deps.LLVM]]
14321432
deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Preferences", "Printf", "Requires", "Unicode"]
1433-
git-tree-sha1 = "ddab4d40513bce53c8e3157825e245224f74fae7"
1433+
git-tree-sha1 = "7c6650580b4c3169d9905858160db895bff6d2e2"
14341434
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
1435-
version = "6.6.0"
1435+
version = "6.6.1"
14361436
weakdeps = ["BFloat16s"]
14371437

14381438
[deps.LLVM.extensions]
@@ -2119,9 +2119,9 @@ version = "1.40.2"
21192119

21202120
[[deps.Polyester]]
21212121
deps = ["ArrayInterface", "BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "ManualMemory", "PolyesterWeave", "Requires", "Static", "StaticArrayInterface", "StrideArraysCore", "ThreadingUtilities"]
2122-
git-tree-sha1 = "fca25670784a1ae44546bcb17288218310af2778"
2122+
git-tree-sha1 = "8df43bbe60029526dd628af7e9951f5af680d4d7"
21232123
uuid = "f517fe37-dbe3-4b94-8317-1923a5111588"
2124-
version = "0.7.9"
2124+
version = "0.7.10"
21252125

21262126
[[deps.PolyesterWeave]]
21272127
deps = ["BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "Static", "ThreadingUtilities"]
@@ -2405,10 +2405,10 @@ uuid = "76ed43ae-9a5d-5a62-8c75-30186b810ce8"
24052405
version = "3.45.0+0"
24062406

24072407
[[deps.SciMLBase]]
2408-
deps = ["ADTypes", "ArrayInterface", "CommonSolve", "ConstructionBase", "Distributed", "DocStringExtensions", "EnumX", "FunctionWrappersWrappers", "IteratorInterfaceExtensions", "LinearAlgebra", "Logging", "Markdown", "PrecompileTools", "Preferences", "Printf", "RecipesBase", "RecursiveArrayTools", "Reexport", "RuntimeGeneratedFunctions", "SciMLOperators", "StaticArraysCore", "Statistics", "SymbolicIndexingInterface", "Tables"]
2409-
git-tree-sha1 = "3a281a9fce9cd62b849d7f16e412933a5fe755cb"
2408+
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"]
2409+
git-tree-sha1 = "48f724c6a3355f11dae5f762983073d367c8b934"
24102410
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2411-
version = "2.29.0"
2411+
version = "2.30.1"
24122412

24132413
[deps.SciMLBase.extensions]
24142414
SciMLBaseChainRulesCoreExt = "ChainRulesCore"
@@ -2435,6 +2435,11 @@ git-tree-sha1 = "10499f619ef6e890f3f4a38914481cc868689cd5"
24352435
uuid = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
24362436
version = "0.3.8"
24372437

2438+
[[deps.SciMLStructures]]
2439+
git-tree-sha1 = "5833c10ce83d690c124beedfe5f621b50b02ba4d"
2440+
uuid = "53ae85a6-f571-4167-b2af-e1d143709226"
2441+
version = "1.1.0"
2442+
24382443
[[deps.Scratch]]
24392444
deps = ["Dates"]
24402445
git-tree-sha1 = "3bac05bc7e74a75fd9cba4295cde4045d9fe2386"
@@ -2791,9 +2796,9 @@ uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
27912796
version = "0.5.23"
27922797

27932798
[[deps.TranscodingStreams]]
2794-
git-tree-sha1 = "3caa21522e7efac1ba21834a03734c57b4611c7e"
2799+
git-tree-sha1 = "a09c933bebed12501890d8e92946bbab6a1690f1"
27952800
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
2796-
version = "0.10.4"
2801+
version = "0.10.5"
27972802
weakdeps = ["Random", "Test"]
27982803

27992804
[deps.TranscodingStreams.extensions]

experiments/AMIP/Project.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[deps]
2-
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
32
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
43
ArtifactWrappers = "a14bc488-3040-4b00-9dc1-f6467924858a"
54
AtmosphericProfilesLibrary = "86bc3604-9858-485a-bdbe-831ec50de11d"

experiments/AMIP/user_io/debug_plots.jl

+64-24
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ using Plots
22
using ClimaCorePlots
33
using Printf
44
using ClimaCoupler.Interfacer: ComponentModelSimulation, SurfaceModelSimulation
5+
using ClimaCoupler: TestHelper
56
using ClimaCore
6-
using Adapt
77

88
# plotting functions for the coupled simulation
99
"""
@@ -45,77 +45,117 @@ function debug(cs_fields::NamedTuple, dir, cs_fields_ref = nothing)
4545
all_plots = []
4646
cpu_comms_ctx = ClimaComms.SingletonCommsContext()
4747

48-
# Extract information from input space to create space on CPU for plotting
49-
field = getproperty(cs_fields, field_names[begin])
50-
space = axes(field)
51-
FT = ClimaCore.Spaces.undertype(space)
52-
R = space.grid.global_geometry.radius
53-
ne = space.grid.topology.mesh.ne
54-
polynomial_degree = Quadratures.degrees_of_freedom(Spaces.quadrature_style(space.grid))
55-
nz = Spaces.nlevels(space)
56-
57-
cpu_space = TestHelper.create_space(FT, comms_ctx = cpu_comms_ctx, R, ne, polynomial_degree, nz)
58-
cpu_field = Fields.ones(cpu_space)
59-
6048
for field_name in field_names
6149
field = getproperty(cs_fields, field_name)
50+
6251
# Copy field onto cpu space
52+
space = axes(field)
53+
FT = ClimaCore.Spaces.undertype(space)
54+
R = get_R(space.grid)
55+
ne = get_ne(space.grid)
56+
polynomial_degree = ClimaCore.Quadratures.polynomial_degree(ClimaCore.Spaces.quadrature_style(space.grid))
57+
nz = ClimaCore.Spaces.nlevels(space)
58+
cpu_space = TestHelper.create_space(
59+
FT,
60+
comms_ctx = cpu_comms_ctx,
61+
R = R,
62+
ne = ne,
63+
polynomial_degree = polynomial_degree,
64+
nz = nz,
65+
)
66+
cpu_field = ClimaCore.Fields.ones(cpu_space)
67+
6368
parent(cpu_field) .= parent(field)
6469

65-
push!(all_plots, plot(cpu_field, title = string(field_name) * print_extrema(field)))
70+
push!(all_plots, Plots.plot(cpu_field, title = string(field_name) * print_extrema(field)))
6671
if (field_name == :T_S) && (@isdefined debug_csf0)
6772
push!(
6873
all_plots,
69-
plot(
74+
Plots.plot(
7075
cpu_field .- debug_csf0.T_S,
7176
title = string(field_name) * "_anom" * print_extrema(field),
7277
color = :viridis,
7378
),
7479
)
7580
end
7681
end
77-
plot(all_plots..., size = (1500, 800))
82+
Plots.plot(all_plots..., size = (1500, 800))
7883
Plots.png(joinpath(dir, "debug_coupler"))
7984

8085
# plot anomalies if a reference cs.fields, `cs_fields_ref`, are provided
8186
if !isnothing(cs_fields_ref)
8287
all_plots = []
8388
for field_name in field_names
8489
field = getproperty(cs_fields, field_name)
85-
# Convert field from GPU to CPU if necessary
86-
cpu_field = Adapt.adapt(Array, field)
90+
# Copy field onto cpu space
91+
parent(cpu_field) .= parent(field)
8792

8893
push!(
8994
all_plots,
90-
plot(
95+
Plots.plot(
9196
cpu_field .- getproperty(cs_fields_ref, field_name),
9297
title = string(field_name) * print_extrema(field),
9398
),
9499
)
95100
end
96-
plot(all_plots..., size = (1500, 800))
101+
Plots.plot(all_plots..., size = (1500, 800))
97102
Plots.png(joinpath(dir, "debug_coupler_amomalies"))
98103
end
99104
end
100105

106+
function get_ne(grid::ClimaCore.Grids.SpectralElementGrid2D)
107+
return grid.topology.mesh.ne
108+
end
109+
function get_ne(grid::ClimaCore.Grids.LevelGrid)
110+
return get_ne(grid.full_grid.horizontal_grid)
111+
end
112+
function get_ne(grid::ClimaCore.Grids.ExtrudedFiniteDifferenceGrid)
113+
return get_ne(grid.horizontal_grid)
114+
end
115+
# function get_ne(space)
116+
# return get_ne(ClimaCore.Spaces.horizontal_space(space).grid)
117+
# end
118+
119+
function get_R(grid)#::ClimaCore.Grids.SpectralElementGrid2D)
120+
return ClimaCore.Grids.global_geometry(grid).radius
121+
end
101122
"""
102123
debug(sim::ComponentModelSimulation, dir)
103124
104125
Plot the fields of a component model simulation and save plots to a directory.
105126
"""
106127
function debug(sim::ComponentModelSimulation, dir)
107128

129+
@show name(sim)
108130
field_names = plot_field_names(sim)
131+
cpu_comms_ctx = ClimaComms.SingletonCommsContext()
109132

110133
all_plots = []
111134
for field_name in field_names
112135
field = get_field(sim, Val(field_name))
113-
# Convert field from GPU to CPU if necessary
114-
cpu_field = Adapt.adapt(Array, field)
136+
# Copy field onto cpu space
137+
space = axes(field)
138+
FT = ClimaCore.Spaces.undertype(space)
139+
R = get_R(space.grid)
140+
ne = get_ne(space.grid)
141+
polynomial_degree = ClimaCore.Quadratures.polynomial_degree(ClimaCore.Spaces.quadrature_style(space.grid))
142+
nz = ClimaCore.Spaces.nlevels(space)
143+
cpu_space = TestHelper.create_space(
144+
FT,
145+
comms_ctx = cpu_comms_ctx,
146+
R = R,
147+
ne = ne,
148+
polynomial_degree = polynomial_degree,
149+
nz = nz,
150+
)
151+
cpu_field = ClimaCore.Fields.ones(cpu_space)
152+
@show space
153+
@show cpu_space
154+
parent(cpu_field) .= parent(field)
115155

116-
push!(all_plots, plot(cpu_field, title = string(field_name) * print_extrema(field)))
156+
push!(all_plots, Plots.plot(cpu_field, title = string(field_name) * print_extrema(field)))
117157
end
118-
fig = plot(all_plots..., size = (1500, 800))
158+
fig = Plots.plot(all_plots..., size = (1500, 800))
119159
Plots.png(joinpath(dir, "debug_$(name(sim))"))
120160

121161
end

0 commit comments

Comments
 (0)