Skip to content

Commit aa50f3a

Browse files
committed
convert fields GPU to CPU for plots
1 parent 78655b3 commit aa50f3a

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

experiments/AMIP/Manifest.toml

+1-1
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 = "284db48dcd39d58ad8518daa0c1caded1552fa4a"
5+
project_hash = "a198c94037ccdef0790bbbb0c9a214fd17aa95f9"
66

77
[[deps.ADTypes]]
88
git-tree-sha1 = "016833eb52ba2d6bea9fcb50ca295980e728ee24"

experiments/AMIP/Project.toml

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

experiments/AMIP/user_io/debug_plots.jl

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using ClimaCorePlots
33
using Printf
44
using ClimaCoupler.Interfacer: ComponentModelSimulation, SurfaceModelSimulation
55
using ClimaCore
6+
using Adapt
67

78
# plotting functions for the coupled simulation
89
"""
@@ -42,15 +43,21 @@ function debug(cs_fields::NamedTuple, dir, cs_fields_ref = nothing)
4243
:z0m_S,
4344
)
4445
all_plots = []
46+
cpu_comms_ctx = ClimaComms.SingletonCommsContext()
47+
48+
4549
for field_name in field_names
4650
field = getproperty(cs_fields, field_name)
47-
push!(all_plots, Plots.plot(field, title = string(field_name) * print_extrema(field)))
51+
# Convert field from GPU to CPU if necessary
52+
cpu_field = Adapt.adapt(Array, field)
53+
54+
push!(all_plots, Plots.plot(cpu_field, title = string(field_name) * print_extrema(cpu_field)))
4855
if (field_name == :T_S) && (@isdefined debug_csf0)
4956
push!(
5057
all_plots,
5158
Plots.plot(
52-
field .- debug_csf0.T_S,
53-
title = string(field_name) * "_anom" * print_extrema(field),
59+
cpu_field .- debug_csf0.T_S,
60+
title = string(field_name) * "_anom" * print_extrema(cpu_field),
5461
color = :viridis,
5562
),
5663
)
@@ -64,11 +71,14 @@ function debug(cs_fields::NamedTuple, dir, cs_fields_ref = nothing)
6471
all_plots = []
6572
for field_name in field_names
6673
field = getproperty(cs_fields, field_name)
74+
# Convert field from GPU to CPU if necessary
75+
cpu_field = Adapt.adapt(Array, field)
76+
6777
push!(
6878
all_plots,
6979
Plots.plot(
70-
field .- getproperty(cs_fields_ref, field_name),
71-
title = string(field_name) * print_extrema(field),
80+
cpu_field .- getproperty(cs_fields_ref, field_name),
81+
title = string(field_name) * print_extrema(cpu_field),
7282
),
7383
)
7484
end
@@ -89,7 +99,10 @@ function debug(sim::ComponentModelSimulation, dir)
8999
all_plots = []
90100
for field_name in field_names
91101
field = get_field(sim, Val(field_name))
92-
push!(all_plots, Plots.plot(field, title = string(field_name) * print_extrema(field)))
102+
# Convert field from GPU to CPU if necessary
103+
cpu_field = Adapt.adapt(Array, field)
104+
105+
push!(all_plots, Plots.plot(cpu_field, title = string(field_name) * print_extrema(cpu_field)))
93106
end
94107
fig = Plots.plot(all_plots..., size = (1500, 800))
95108
Plots.png(joinpath(dir, "debug_$(name(sim))"))

test/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
23
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
34
ArtifactWrappers = "a14bc488-3040-4b00-9dc1-f6467924858a"
45
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"

0 commit comments

Comments
 (0)