enthought / distarray

Default Repo description from terraform module
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Reductions do not properly support unstructured distributions #659

Open cfarrow opened 7 years ago

cfarrow commented 7 years ago

This reproduces the problem

# Using IPython.parallel: 'dacluster start -n4' before running.
import numpy as np
from distarray.globalapi import Context
from distarray.globalapi.maps import Distribution, NoDistMap, UnstructuredMap

nparr = np.random.rand(4, 5)

context = Context()
m0 = UnstructuredMap(4, 3, [[0], [1], [2, 3]])
m1 = NoDistMap(5, 1)
distribution = Distribution.from_maps(
    context,
    maps=[m0, m1],
    targets=[0, 1, 3]
)

darr = context.fromarray(nparr, distribution)
from IPython.core.debugger import Tracer; Tracer()()
darr.sum(axis=1)  # boom!

This results in

Traceback (most recent call last):
  File "failure.py", line 19, in <module>
    darr.sum(axis=1)  # boom!
  File "/Users/cfarrow/projects/distarray/distarray/globalapi/distarray.py", line 383, in sum
    return self._reduce('sum_reducer', axis, dtype, out)
  File "/Users/cfarrow/projects/distarray/distarray/globalapi/distarray.py", line 362, in _reduce
    ddpr = out_dist.get_dim_data_per_rank()
  File "/Users/cfarrow/projects/distarray/distarray/globalapi/maps.py", line 830, in get_dim_data_per_rank
    dds = [enumerate(m.get_dimdicts()) for m in self.maps]
  File "/Users/cfarrow/projects/distarray/distarray/globalapi/maps.py", line 510, in get_dimdicts
    raise ValueError()
ValueError

Distribution.reduce does not appear to consider UnstructuredMap, which leads to the indices used by the input UnstructuredMap to not be propagated to the output UnstructuredMap.