Source code for pymor.parallel.dummy

# This file is part of the pyMOR project (
# Copyright 2013-2020 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (

from copy import deepcopy

from pymor.core.base import ImmutableObject
from pymor.parallel.interface import WorkerPool, RemoteObject

[docs]class DummyPool(WorkerPool):
[docs] def __len__(self): return 1
[docs] def push(self, obj): if isinstance(obj, ImmutableObject): return DummyRemoteObject(obj) else: return DummyRemoteObject(deepcopy(obj)) # ensure we make a deep copy of the data
[docs] def scatter_array(self, U, copy=True): if copy: U = U.copy() return DummyRemoteObject(U)
[docs] def scatter_list(self, l): l = list(l) return DummyRemoteObject(l)
def _map_kwargs(self, kwargs): return {k: (v.obj if isinstance(v, DummyRemoteObject) else v) for k, v in kwargs.items()}
[docs] def apply(self, function, *args, **kwargs): kwargs = self._map_kwargs(kwargs) return [function(*args, **kwargs)]
[docs] def apply_only(self, function, worker, *args, **kwargs): kwargs = self._map_kwargs(kwargs) return function(*args, **kwargs)
[docs] def map(self, function, *args, **kwargs): kwargs = self._map_kwargs(kwargs) result = [function(*a, **kwargs) for a in zip(*args)] return result
def __bool__(self): return False
dummy_pool = DummyPool()
[docs]class DummyRemoteObject(RemoteObject): def __init__(self, obj): self.obj = obj def _remove(self): del self.obj