Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary task dependencies by using numpy arrays #872

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sgkit/stats/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def count_call_alleles(
n_alleles = ds.dims["alleles"]
G = da.asarray(ds[call_genotype])
shape = (G.chunks[0], G.chunks[1], n_alleles)
N = da.empty(n_alleles, dtype=np.uint8)
# use numpy array to avoid dask task dependencies between chunks
N = np.empty(n_alleles, dtype=np.uint8)
new_ds = create_dataset(
{
variables.call_allele_count: (
Expand Down Expand Up @@ -263,8 +264,10 @@ def count_cohort_alleles(
ds, variables.call_allele_count, call_allele_count, count_call_alleles
)
variables.validate(ds, {call_allele_count: variables.call_allele_count_spec})
AC, SC = da.asarray(ds[call_allele_count]), da.asarray(ds[sample_cohort])
n_cohorts = SC.max().compute() + 1 # 0-based indexing
# ensure cohorts is a numpy array to minimize dask task
# dependencies between chunks in other dimensions
AC, SC = da.asarray(ds[call_allele_count]), ds[sample_cohort].values
n_cohorts = SC.max() + 1 # 0-based indexing
AC = cohort_sum(AC, SC, n_cohorts, axis=1)
new_ds = create_dataset(
{variables.cohort_allele_count: (("variants", "cohorts", "alleles"), AC)}
Expand Down
6 changes: 4 additions & 2 deletions sgkit/stats/popgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,10 @@ def observed_heterozygosity(
)
variables.validate(ds, {call_heterozygosity: variables.call_heterozygosity_spec})
hi = da.asarray(ds[call_heterozygosity])
cohort = da.asarray(ds[sample_cohort])
n_cohorts = cohort.max().compute() + 1
# ensure cohorts is a numpy array to minimize dask task
# dependencies between chunks in other dimensions
cohort = ds[sample_cohort].values
n_cohorts = cohort.max() + 1
ho = cohort_nanmean(hi, cohort, n_cohorts)
if has_windows(ds):
ho_sum = window_statistic(
Expand Down