A sequence of expressions This is used to be able to optimize multiple collections combined, e.g. when being computed simultaneously with ``dask.compute((Expr1, Expr2))``.
| 1188 | |
| 1189 | |
| 1190 | class _ExprSequence(Expr): |
| 1191 | """A sequence of expressions |
| 1192 | |
| 1193 | This is used to be able to optimize multiple collections combined, e.g. when |
| 1194 | being computed simultaneously with ``dask.compute((Expr1, Expr2))``. |
| 1195 | """ |
| 1196 | |
| 1197 | def __getitem__(self, other): |
| 1198 | return self.operands[other] |
| 1199 | |
| 1200 | def _layer(self) -> dict: |
| 1201 | return toolz.merge(op._layer() for op in self.operands) |
| 1202 | |
| 1203 | def __dask_keys__(self) -> list: |
| 1204 | all_keys = [] |
| 1205 | for op in self.operands: |
| 1206 | all_keys.append(list(op.__dask_keys__())) |
| 1207 | return all_keys |
| 1208 | |
| 1209 | def __repr__(self): |
| 1210 | return "ExprSequence(" + ", ".join(map(repr, self.operands)) + ")" |
| 1211 | |
| 1212 | __str__ = __repr__ |
| 1213 | |
| 1214 | def finalize_compute(self): |
| 1215 | return _ExprSequence( |
| 1216 | *(op.finalize_compute() for op in self.operands), |
| 1217 | ) |
| 1218 | |
| 1219 | def __dask_annotations__(self): |
| 1220 | annotations_by_type = {} |
| 1221 | for op in self.operands: |
| 1222 | for k, v in op.__dask_annotations__().items(): |
| 1223 | annotations_by_type.setdefault(k, {}).update(v) |
| 1224 | return annotations_by_type |
| 1225 | |
| 1226 | def __len__(self): |
| 1227 | return len(self.operands) |
| 1228 | |
| 1229 | def __iter__(self): |
| 1230 | return iter(self.operands) |
| 1231 | |
| 1232 | def _simplify_down(self): |
| 1233 | from dask.highlevelgraph import HighLevelGraph |
| 1234 | |
| 1235 | issue_warning = False |
| 1236 | hlgs = [] |
| 1237 | if any( |
| 1238 | isinstance(op, (HLGExpr, HLGFinalizeCompute, dict)) for op in self.operands |
| 1239 | ): |
| 1240 | for op in self.operands: |
| 1241 | if isinstance(op, (HLGExpr, HLGFinalizeCompute)): |
| 1242 | hlgs.append(op) |
| 1243 | elif isinstance(op, dict): |
| 1244 | hlgs.append( |
| 1245 | HLGExpr( |
| 1246 | dsk=HighLevelGraph.from_collections( |
| 1247 | str(id(op)), op, dependencies=() |
no outgoing calls
searching dependent graphs…