Unverified Commit 34b2c21b authored by Stephan Rave's avatar Stephan Rave Committed by GitHub
Browse files

Merge pull request #1453 from pymor/mpi_caching2

Improve error handling in DiskRegion / Don't disable caching in mpi_wrap_model
parents e5021923 d780950f
Pipeline #106239 failed with stages
in 37 minutes and 35 seconds
......@@ -14,6 +14,7 @@ if config.HAVE_FENICS:
from pymor.core.base import ImmutableObject
from pymor.core.defaults import defaults
from pymor.core.pickle import unpicklable
from pymor.operators.constructions import ZeroOperator
from pymor.operators.interface import Operator
from pymor.operators.list import LinearComplexifiedListVectorArrayOperatorBase
......@@ -22,6 +23,7 @@ if config.HAVE_FENICS:
from pymor.vectorarrays.list import CopyOnWriteVector, ComplexifiedVector, ComplexifiedListVectorSpace
from pymor.vectorarrays.numpy import NumpyVectorSpace
@unpicklable
class FenicsVector(CopyOnWriteVector):
"""Wraps a FEniCS vector to make it usable with ListVectorArray."""
......
......@@ -78,7 +78,7 @@ import numpy as np
from pymor.core.base import ImmutableObject
from pymor.core.defaults import defaults, defaults_changes
from pymor.core.exceptions import CacheKeyGenerationError
from pymor.core.exceptions import CacheKeyGenerationError, UnpicklableError
from pymor.core.logger import getLogger
from pymor.core.pickle import dumps
from pymor.parameters.base import Mu
......@@ -186,7 +186,12 @@ class DiskRegion(CacheRegion):
if has_key:
getLogger('pymor.core.cache.DiskRegion').warning('Key already present in cache region, ignoring.')
return
self._cache.set(key, value)
try:
self._cache.set(key, value)
except UnpicklableError as e:
getLogger('pymor.core.cache.DiskRegion').warning(f'{e.cls} cannot be pickled. Not caching result.')
except (TypeError, AttributeError) as e:
getLogger('pymor.core.cache.DiskRegion').warning(f'Pickling failed. Not caching result (error: {e}).')
def clear(self):
self._cache.clear()
......
......@@ -89,3 +89,11 @@ class IOLibsMissing(ImportError):
def __init__(self, msg=None):
msg = msg or 'meshio, pyevtk, xmljson and lxml are needed for full file I/O functionality'
super().__init__(msg)
class UnpicklableError(Exception):
def __init__(self, cls):
self.cls = cls
def __str__(self):
return f'{self.cls} cannot be pickled.'
......@@ -21,6 +21,8 @@ import pickle
from io import BytesIO as IOtype
import platform
from pymor.core.exceptions import UnpicklableError
PicklingError = pickle.PicklingError
UnpicklingError = pickle.UnpicklingError
......@@ -62,6 +64,15 @@ else:
loads = pickle.loads
def unpicklable(cls):
"""Class decorator to mark a class as unpicklable."""
def __getstate__(self):
raise UnpicklableError(cls)
cls.__getstate__ = __getstate__
return cls
def _generate_opcode(code_object):
import dis
for ins in dis.get_instructions(code_object):
......
......@@ -139,7 +139,6 @@ def mpi_wrap_model(local_models, mpi_spaces=('STATE',), use_with=True, with_appl
if m.visualizer:
wrapped_attributes['visualizer'] = MPIVisualizer(local_models)
m = m.with_(**wrapped_attributes)
m.disable_caching()
return m
else:
......
......@@ -15,10 +15,12 @@ by :mod:`pymor.tools.mpi`.
import numpy as np
from pymor.core.pickle import unpicklable
from pymor.tools import mpi
from pymor.vectorarrays.interface import VectorArray, VectorSpace
@unpicklable
class MPIVectorArray(VectorArray):
"""MPI distributed |VectorArray|.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment