Skip to content

Commit

Permalink
remove Polyester (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf authored Oct 12, 2021
1 parent dbeca02 commit d6dedd0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 72 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnROOT"
uuid = "3cd96dde-e98d-4713-81e9-a4a1b0235ce9"
authors = ["Tamas Gal", "Jerry Ling", "Johannes Schumann", "Nick Amin"]
version = "0.7.3"
version = "0.8.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -18,7 +18,6 @@ Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73"
Mixers = "2a8e4939-dab8-5edc-8f64-72a8776f13de"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
Expand All @@ -39,7 +38,6 @@ Mixers = "^0.1.0"
Parameters = "^0.12.0"
Polyester = "^0.5.3"
PrettyTables = "^1.2.0"
Requires = "^1"
StaticArrays = "^0.12.0, ^1"
Tables = "^1.0.0"
TypedTables = "^1.0.0"
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ julia> for event in mytree
end
event.Electron_dxy = Float32[0.00037050247]

julia> using Polyester #optional dependency

julia> @batch for event in mytree # multi-threading
julia> Threads.@threads for event in mytree # multi-threading
...
end
```
Expand Down
19 changes: 7 additions & 12 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,18 @@ julia> for (i, event) in enumerate(mytree)
end
```

Both of which are compostable with `@batch` from `Polyester.jl` for multi-threading:
Both of which are compostable with `@threads` for multi-threading:
```julia
julia> using Polyester # need to install it first as it's an optional dependency

julia> @batch for event in mytree
julia> Threads.@threads for event in mytree
...
end

julia> @batch for (i, event) in enumerate(mytree)
julia> Threads.@threads for (i, event) in enumerate(mytree)
...
end
```
On finer control over `@batch`, such as batch size or per-core/thread, see [Polyester](https://github.com/JuliaSIMD/Polyester.jl)'s page.

Only one basket per branch will be cached so you don't have to worry about running out of RAM.
At the same time, `event` inside the for-loop is not materialized until a field is accessed. If your event
is fairly small or you need all of them anyway, you can `collect(event)` first inside the loop.
At the same time, `event` inside the for-loop is not materialized until a field is accessed.

## Laziness in Indexing, Slicing, and Looping
Laziness (or eagerness) in UnROOT generally refers to if an "event" has read each branches of the tree or not.
Expand Down Expand Up @@ -84,6 +79,6 @@ The laziness of the main interfaces are summarized below:
| | `mytree` | `enumerate(mytree)` |
| ---------------------- |:-----------:|:-------------------:|
| `for X in ...` | 💤 | 💤 |
| `@threads for X in ...`| 🚨 | 💤 |
| `@batch for X in ...` | 💤 | 💤 |
| `getindex()` | 🚨 | 💤 |
| `@threads for X in ...`| 💤 | 💤 |
| `getindex(tree, row::Int)`| 💤 | N/A |
| `getindex(tree, row::Range)`| 🚨 | N/A |
24 changes: 0 additions & 24 deletions docs/src/performancetips.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,3 @@ for evt in mytree
calculation(nmu)
end
```

## `Threads.@threads` should go with `enumerate()`
tl;dr: just use `@batch` provided by [Polyester.jl](https://github.com/JuliaSIMD/Polyester.jl) since UnROOT
can customize behavior.

Unlike `@batch`, there's not much we can do to customize behavior of `@threads`. It is essentially
calling `getindex()`, which we want to keep eager for regular use (e.v `mytree[120]` is eager). Thus, if for some
reason you want to use `@threads` instead of `@batch`, you should use it with `enumerate`:
```julia
julia> for evt in mytree
@show evt
break
end
evt = "LazyEvent with: (:tree, :idx)"

julia> Threads.@threads for evt in mytree
@show evt
break
end
evt = (nMuon = 0x00000000, Muon_pt = Float32[])
evt = (nMuon = 0x00000001, Muon_pt = Float32[3.4505641])
evt = (nMuon = 0x00000000, Muon_pt = Float32[])
evt = (nMuon = 0x00000002, Muon_pt = Float32[21.279676, 7.6710315])
```
8 changes: 2 additions & 6 deletions src/UnROOT.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module UnROOT

using Requires, LazyArrays
export ROOTFile, LazyBranch, LazyTree, @batch
using LazyArrays
export ROOTFile, LazyBranch, LazyTree

import Base: close, keys, get, getindex, getproperty, show, length, iterate, position, ntoh, lock, unlock, reinterpret
ntoh(b::Bool) = b
Expand Down Expand Up @@ -30,8 +30,4 @@ include("iteration.jl")
include("custom.jl")
include("displays.jl")

function __init__()
@require Polyester="f517fe37-dbe3-4b94-8317-1923a5111588" include("polyester.jl")
end

end # module
4 changes: 2 additions & 2 deletions src/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ Base.lastindex(lt::LazyTree) = length(lt)
Base.eachindex(lt::LazyTree) = 1:lastindex(lt)

# allow enumerate() to be chunkable (eg with Threads.@threads)
Base.step(e::Iterators.Enumerate{LazyTree{T}}) where T = 1
Base.firstindex(e::Iterators.Enumerate{LazyTree{T}}) where T = firstindex(e.itr)
Base.lastindex(e::Iterators.Enumerate{LazyTree{T}}) where T = lastindex(e.itr)
Base.eachindex(e::Iterators.Enumerate{LazyTree{T}}) where T = eachindex(e.itr)
Base.getindex(e::Iterators.Enumerate{LazyTree{T}}, row::Int) where T = (row, first(iterate(e.itr, row)))

Base.getindex(e::Iterators.Enumerate{LazyTree{T}}, row::Int) where T = (row, LazyEvent(innertable(e.itr), row))
# interfacing Table
Base.names(lt::LazyTree) = collect(String.(propertynames(innertable(lt))))
Base.length(lt::LazyTree) = length(innertable(lt))
Expand Down
8 changes: 0 additions & 8 deletions src/polyester.jl

This file was deleted.

15 changes: 1 addition & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -658,19 +658,6 @@ end
@test count(>(0), nmus) > 1 # test @threads is actually threading
@test sum(nmus) == 878

nmus .= 0
@batch for (i, evt) in enumerate(t)
nmus[Threads.threadid()] += length(evt.Muon_pt)
end
@test count(>(0), nmus) > 1 # test @batch is actually threading
@test sum(nmus) == 878

event_nums = zeros(Int, Threads.nthreads())
@batch for (i, evt) in enumerate(t)
event_nums[Threads.threadid()] += 1
end
@test count(>(0), event_nums) > 1 # test @batch is actually threading
@test sum(event_nums) == length(t)

nmus .= 0
@batch for evt in t
Expand All @@ -688,7 +675,7 @@ end

for j in 1:3
inds = [Vector{Int}() for _ in 1:Threads.nthreads()]
@batch for (i, evt) in enumerate(t)
Threads.@threads for (i, evt) in enumerate(t)
push!(inds[Threads.threadid()], i)
end
@test sum([length(inds[i] inds[j]) for i=1:length(inds), j=1:length(inds) if j>i]) == 0
Expand Down

2 comments on commit d6dedd0

@Moelf
Copy link
Member Author

@Moelf Moelf commented on d6dedd0 Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/46563

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.0 -m "<description of version>" d6dedd0b28adcc7c94339d691c51a135d65eb281
git push origin v0.8.0

Please sign in to comment.