def get(self, key=None): """Execute and return the result of the computation *key*. Only *key* and its dependencies are computed. Parameters ---------- key : str, optional If not provided, :attr:`default_key` is used. Raises ------ ValueError If `key` and :attr:`default_key` are both :obj:`None`. """ if key is None: if self.default_key is not None: key = self.default_key else: raise ValueError('no default reporting key set') # Cull the graph, leaving only those needed to compute *key* dsk, deps = cull(self.graph, key) log.debug('Cull {} -> {} keys'.format(len(self.graph), len(dsk))) try: return dask_get(dsk, key) except Exception as exc: raise ComputationError from exc
def get(self, key=None): """Execute and return the result of the computation *key*. Only *key* and its dependencies are computed. Parameters ---------- key : str, optional If not provided, :attr:`default_key` is used. Raises ------ ValueError If `key` and :attr:`default_key` are both :obj:`None`. """ if key is None: if self.default_key is not None: key = self.default_key else: raise ValueError('no default reporting key set') # Cull the graph, leaving only those needed to compute *key* dsk, deps = cull(self.graph, key) log.debug('Cull {} -> {} keys'.format(len(self.graph), len(dsk))) try: # Protect 'config' dict, so that dask schedulers do not try to # interpret its contents as further tasks. Workaround for # https://github.com/dask/dask/issues/3523 dsk['config'] = dask.core.quote(dsk['config']) except KeyError: pass try: return dask_get(dsk, key) except Exception as exc: # Print the exception in case ComputationError.__str__ fails; # workaround for https://github.com/iiasa/ixmp/issues/206 print(exc) raise ComputationError from exc