Skip to content

Commit

Permalink
Fix reading/writing purely vertical spaces
Browse files Browse the repository at this point in the history
This previously was not supported
  • Loading branch information
Sbozzolo committed Dec 18, 2024
1 parent 6ad8294 commit 3a64eec
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 19 deletions.
20 changes: 12 additions & 8 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,35 +1146,39 @@ steps:

- label: "Unit: spectralelement2d"
key: unit_spectralelement2d
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/spectralelement2d.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_spectralelement2d.jl"

- label: "Unit: hybrid2dbox"
key: unit_hybrid2dbox
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid2dbox.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid2dbox.jl"

- label: "Unit: hybrid2dbox topography"
key: unit_hybrid2dbox_topography
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid2dbox_topography.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid2dbox_topography.jl"

- label: "Unit: hybrid2dbox stretched"
key: unit_hybrid2dbox_stretched
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid2dbox_stretched.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid2dbox_stretched.jl"

- label: "Unit: hybrid3dbox"
key: unit_hybrid3dbox
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dbox.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dbox.jl"

- label: "Unit: hybrid3dcubedsphere"
key: unit_hybrid3dcubedsphere
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dcubedsphere.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dcubedsphere.jl"

- label: "Unit: hybrid3dcubedsphere topography"
key: unit_hybrid3dcubedsphere_topography
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dcubedsphere_topography.jl"
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dcubedsphere_topography.jl"

- label: "Unit: finitedifference"
key: unit_finitedifference
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_finitedifference.jl"

- label: "Unit: Parallel HDF5 IO tests"
key: "cpu_parallel_hdf5"
command: "srun julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dcubedsphere.jl"
command: "srun julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dcubedsphere.jl"
timeout_in_minutes: 5
env:
CLIMACOMMS_CONTEXT: "MPI"
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ClimaCore.jl Release Notes
main
-------


- We've added new convenience constructors for spaces PR [2082](https://github.com/CliMA/ClimaCore.jl/pull/2082). Here are links to the new constructors:
- [ExtrudedCubedSphereSpace]()
- [CubedSphereSpace]()
Expand All @@ -12,7 +13,12 @@ main
- [SliceXZSpace]()
- [RectangleXYSpace]()

### ![][badge-🐛bugfix] Bug fixes

- Fixed writing/reading purely vertical spaces

v0.14.20
--------

- We've added new convenience constructors for grids PR [1848](https://github.com/CliMA/ClimaCore.jl/pull/1848). Here are links to the new constructors:
- [ExtrudedCubedSphereGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L85-L144)
Expand Down
13 changes: 10 additions & 3 deletions src/InputOutput/readers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,19 @@ function _scan_data_layout(layoutstring::AbstractString)
"IFH",
"IHF",
"IF",
"VF",
"VIJFH",
"VIJHF",
"VIFH",
"VIHF",
)
) "datalayout is $layoutstring"
layoutstring == "IJFH" && return DataLayouts.IJFH
layoutstring == "IJHF" && return DataLayouts.IJHF
layoutstring == "IJF" && return DataLayouts.IJF
layoutstring == "IFH" && return DataLayouts.IFH
layoutstring == "IHF" && return DataLayouts.IHF
layoutstring == "IF" && return DataLayouts.IF
layoutstring == "VF" && return DataLayouts.VF
layoutstring == "VIJFH" && return DataLayouts.VIJFH
layoutstring == "VIJHF" && return DataLayouts.VIJHF
return DataLayouts.VIFH
Expand Down Expand Up @@ -482,8 +484,10 @@ function read_field(reader::HDF5Reader, name::AbstractString)
topology = Spaces.topology(space)
ArrayType = ClimaComms.array_type(topology)
data_layout = attrs(obj)["data_layout"]
has_horizontal = occursin('I', data_layout)
DataLayout = _scan_data_layout(data_layout)
h_dim = DataLayouts.h_dim(DataLayouts.singleton(DataLayout))
has_horizontal &&
(h_dim = DataLayouts.h_dim(DataLayouts.singleton(DataLayout)))
if topology isa Topologies.Topology2D
nd = ndims(obj)
localidx =
Expand All @@ -492,7 +496,7 @@ function read_field(reader::HDF5Reader, name::AbstractString)
else
data = ArrayType(read(obj))
end
Nij = size(data, findfirst("I", data_layout)[1])
has_horizontal && (Nij = size(data, findfirst("I", data_layout)[1]))
# For when `Nh` is added back to the type space
# Nhd = Nh_dim(data_layout)
# Nht = Nhd == -1 ? () : (size(data, Nhd),)
Expand All @@ -501,6 +505,9 @@ function read_field(reader::HDF5Reader, name::AbstractString)
Nv = size(data, 1)
# values = DataLayout{ElType, Nv, Nij, Nht...}(data) # when Nh is in type-domain
values = DataLayout{ElType, Nv, Nij}(data)
elseif data_layout in ("VF",)
Nv = size(data, 1)
values = DataLayout{ElType, Nv}(data)
else
# values = DataLayout{ElType, Nij, Nht...}(data) # when Nh is in type-domain
values = DataLayout{ElType, Nij}(data)
Expand Down
50 changes: 50 additions & 0 deletions test/InputOutput/unit_finitedifference.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Test
import ClimaCore
import ClimaCore.Fields

using ClimaComms
const comms_ctx = ClimaComms.context(ClimaComms.CPUSingleThreaded())
pid, nprocs = ClimaComms.init(comms_ctx)
filename = ClimaComms.bcast(comms_ctx, tempname(pwd()))
if ClimaComms.iamroot(comms_ctx)
@info "Comms context" comms_ctx nprocs filename
end

@testset "HDF5 restart test for 1d finite difference space" begin
FT = Float32

z_min = FT(0)
z_max = FT(30e3)
z_elem = 10
center_staggering = ClimaCore.Grids.CellCenter()
face_staggering = ClimaCore.Grids.CellFace()

center_space = ClimaCore.CommonSpaces.ColumnSpace(;
z_min,
z_max,
z_elem,
staggering = center_staggering,
)

face_space = ClimaCore.CommonSpaces.ColumnSpace(;
z_min,
z_max,
z_elem,
staggering = face_staggering,
)

center_field = Fields.local_geometry_field(center_space)
face_field = Fields.local_geometry_field(face_space)

Y = ClimaCore.Fields.FieldVector(; c = center_field, f = face_field)

# write field vector to hdf5 file
writer = ClimaCore.InputOutput.HDF5Writer(filename, comms_ctx)
ClimaCore.InputOutput.write!(writer, Y, "Y")
close(writer)

reader = ClimaCore.InputOutput.HDF5Reader(filename, comms_ctx)
restart_Y = ClimaCore.InputOutput.read_field(reader, "Y") # read fieldvector from hdf5 file
close(reader)
@test restart_Y == Y # test if restart is exact
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ UnitTest("Hypsography - 2d" ,"Hypsography/2d.jl"),
UnitTest("Hypsography - 3d sphere" ,"Hypsography/3dsphere.jl"),
UnitTest("Remapping" ,"Operators/remapping.jl"),
UnitTest("Limiter" ,"Limiters/limiter.jl"),
UnitTest("InputOutput - hdf5" ,"InputOutput/hdf5.jl"),
UnitTest("InputOutput - spectralelement2d" ,"InputOutput/spectralelement2d.jl"),
UnitTest("InputOutput - hybrid2dbox" ,"InputOutput/hybrid2dbox.jl"),
UnitTest("InputOutput - hybrid2dbox_topography" ,"InputOutput/hybrid2dbox_topography.jl"),
UnitTest("InputOutput - hybrid2dbox_stretched" ,"InputOutput/hybrid2dbox_stretched.jl"),
UnitTest("InputOutput - hybrid3dbox" ,"InputOutput/hybrid3dbox.jl"),
UnitTest("InputOutput - hybrid3dcubedsphere" ,"InputOutput/hybrid3dcubedsphere.jl"),
UnitTest("InputOutput - hybrid3dcubedsphere_topo" ,"InputOutput/hybrid3dcubedsphere_topography.jl"),
UnitTest("InputOutput - hdf5" ,"InputOutput/unit_hdf5.jl"),
UnitTest("InputOutput - spectralelement2d" ,"InputOutput/unit_spectralelement2d.jl"),
UnitTest("InputOutput - hybrid2dbox" ,"InputOutput/unit_hybrid2dbox.jl"),
UnitTest("InputOutput - hybrid2dbox_topography" ,"InputOutput/unit_hybrid2dbox_topography.jl"),
UnitTest("InputOutput - hybrid2dbox_stretched" ,"InputOutput/unit_hybrid2dbox_stretched.jl"),
UnitTest("InputOutput - hybrid3dbox" ,"InputOutput/unit_hybrid3dbox.jl"),
UnitTest("InputOutput - hybrid3dcubedsphere" ,"InputOutput/unit_hybrid3dcubedsphere.jl"),
UnitTest("InputOutput - hybrid3dcubedsphere_topo" ,"InputOutput/unit_hybrid3dcubedsphere_topography.jl"),
UnitTest("InputOutput - finitedifferences" ,"InputOutput/unit_finitedifference.jl"),
UnitTest("Array interpolation" ,"Remapping/interpolate_array.jl"),
UnitTest("Array interpolation" ,"Remapping/distributed_remapping.jl"),
UnitTest("Aqua" ,"aqua.jl"),
Expand Down

0 comments on commit 3a64eec

Please sign in to comment.