Skip to content

Commit ef58e85

Browse files
authored
Improve DiskArrayEngine integration (#578)
* diskarrayengine updates * bump DAE version * Allow xmap computations on disconnected graphs * custom loopranges
1 parent 6ddc25c commit ef58e85

3 files changed

Lines changed: 59 additions & 30 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "YAXArrays"
22
uuid = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
33
authors = ["Fabian Gans <fgans@bgc-jena.mpg.de>"]
4-
version = "0.7.2"
4+
version = "0.7.3"
55

66
[deps]
77
CFTime = "179af706-886a-5703-950a-314cd64e0468"
@@ -36,7 +36,7 @@ YAXArrayBase = "90b8fcef-0c2d-428d-9c56-5f86629e9d14"
3636
CFTime = "0.0, 0.1, 0.2"
3737
DataStructures = "0.17, 0.18, 0.19"
3838
DimensionalData = "0.27, 0.28, 0.29"
39-
DiskArrayEngine = "0.3"
39+
DiskArrayEngine = "0.3.2"
4040
DiskArrayTools = "0.1.12"
4141
DiskArrays = "0.4.18"
4242
DocStringExtensions = "0.8, 0.9"

src/DAT/xmap.jl

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ intervals = MovingIntervals(:open, :closed; left=left_bounds, width=width)
181181
182182
# Access the first interval
183183
first_interval = intervals[1] # Interval(1, 3)
184+
```
184185
"""
185186
struct MovingIntervals{T,O,L,R} <: DD.AbstractBins
186187
i1::T
@@ -618,7 +619,7 @@ Computes the YAXArrays dataset `ods` and saves it to a Zarr dataset at `path`.
618619
- `max_cache`: The maximum amount of data to cache in memory while computing the dataset.
619620
- `overwrite`: Whether to overwrite the dataset at `path` if it already exists.
620621
"""
621-
function compute_to_zarr(ods, path; max_cache=5e8,overwrite=false)
622+
function compute_to_zarr(ods, path; max_cache=5e8, custom_loopranges=nothing, overwrite=false)
622623
if !isa(ods,Dataset)
623624
throw(ArgumentError("Direct saving of YAXArrays is not supported. Please wrap your array `a` into a Dataset by calling `Dataset(layer=a)`"))
624625
end
@@ -629,35 +630,49 @@ function compute_to_zarr(ods, path; max_cache=5e8,overwrite=false)
629630
end
630631
rpd = DAE.remove_aliases!(g)
631632
DAE.fuse_graph!(g)
632-
op = DAE.gmwop_from_conn(only(g.connections), g.nodes)
633-
lr = DAE.optimize_loopranges(op,max_cache)
634-
635-
newcubes = map(collect(keys(outnodes))) do k
636-
looprange = lr.lr.members
637-
lw = op.outspecs[1].lw
638-
mylr = DAE.mysub(lw,looprange)
639-
newcs = map(mylr,lw.windows.members) do mlr, w
640-
map(mlr) do lr
641-
DAE.windowmin(w[first(lr)]):DAE.windowmax(w[last(lr)]) |> length
642-
end |> chunktype_from_chunksizes
643-
end |> GridChunks
644-
k=>YAXArrays.Datasets.setchunks(ods.cubes[k],newcs)
645-
end
646-
newds = Dataset(;newcubes...)
647-
648-
emptyds = savedataset(newds,path=path,skeleton=true, overwrite=true)
649-
outars = Array{Any}(undef,length(op.outspecs))
650-
fill!(outars,nothing)
651-
for (k,v) in outnodes
652-
v = get(rpd, v, v)
653-
outars[v] = emptyds.cubes[k].data
633+
opinfo = map(g.connections) do conn
634+
op = DAE.gmwop_from_conn(conn, g.nodes)
635+
lr = if custom_loopranges === nothing
636+
DAE.optimize_loopranges(op, max_cache)
637+
else
638+
DAE.custom_loopranges(op, custom_loopranges)
639+
end
640+
641+
newcubes = map(conn.outputids, op.outspecs) do oid, ospec
642+
looprange = lr.lr.members
643+
lw = ospec.lw
644+
mylr = DAE.mysub(lw, looprange)
645+
newcs = map(mylr, lw.windows.members) do mlr, w
646+
map(mlr) do lr
647+
DAE.windowmin(w[first(lr)]):DAE.windowmax(w[last(lr)]) |> length
648+
end |> chunktype_from_chunksizes
649+
end |> GridChunks
650+
k = findfirst(==(oid), outnodes)
651+
if k === nothing
652+
l = findall(==(oid), rpd)
653+
k = findfirst(in(l), outnodes)
654+
end
655+
k => YAXArrays.Datasets.setchunks(ods.cubes[k], newcs)
656+
end
657+
op, lr, newcubes
654658
end
655-
runner = if DAE.Distributed.nworkers() > 1
656-
DAE.DaggerRunner(op,lr,outars)
657-
else
658-
DAE.LocalRunner(op,lr,outars)
659+
660+
newds = Dataset(; reduce(vcat, last.(opinfo))...)
661+
662+
emptyds = savedataset(newds, path=path, skeleton=true, overwrite=overwrite)
663+
664+
for (op, lr, newcubes) in opinfo
665+
666+
outars = map(newcubes) do (k, _)
667+
emptyds.cubes[k].data
668+
end
669+
runner = if DAE.Distributed.nworkers() > 1
670+
DAE.DaggerRunner(op, lr, outars)
671+
else
672+
DAE.LocalRunner(op, lr, outars)
673+
end
674+
run(runner)
659675
end
660-
run(runner)
661676
emptyds
662677
end
663678

test/DAT/xmap.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
#end
2020
@test r.data == a2.data .+ reshape(a3.data,(4,1,5))
2121
end
22+
@testset "Disconnected Graphs" begin
23+
using Test
24+
using YAXArrays
25+
a1 = YAXArray((Dim{:d1}(1:10),), 1:10)
26+
a2 = YAXArray((Dim{:d2}(1:20),), 1:20)
27+
outds = Dataset(a=a1 .* 2, b=a2 .+ 5)
28+
@test outds.a.data isa YAXArrays.Xmap.DAE.GMWOPResult
29+
@test outds.b.data isa YAXArrays.Xmap.DAE.GMWOPResult
30+
outpath = tempname()
31+
isfile(outpath)
32+
dsdisk = compute_to_zarr(outds, outpath)
33+
@test dsdisk.a[:] == 2:2:20
34+
@test dsdisk.b[:] == 6:25
35+
end
2236
end
2337
@testitem "set outtype" begin
2438
using YAXArrays

0 commit comments

Comments
 (0)