예제 #1
0
def test_pickle_by_solving(discretization):
    d = discretization
    d2 = loads(dumps(d))
    d.disable_caching()
    d2.disable_caching()
    for mu in d.parameter_space.sample_randomly(3, seed=234):
        assert np.all(d.solve(mu).almost_equal(d2.solve(mu)))
예제 #2
0
def test_pickle_by_evaluation(function):
    f = function
    f2 = loads(dumps(f))
    mus = parameters_of_type(f.parameter_type, 47)
    for arg in function_argument(f, 10, 42):
        mu = next(mus)
        assert np.all(f.evaluate(arg, mu) == f2.evaluate(arg, mu))
예제 #3
0
def test_pickle_by_solving(model):
    m = model
    m2 = loads(dumps(m))
    m.disable_caching()
    m2.disable_caching()
    for mu in m.parameter_space.sample_randomly(3, seed=234):
        assert np.all(almost_equal(m.solve(mu), m2.solve(mu)))
예제 #4
0
파일: function.py 프로젝트: renemilk/pyMor
def test_pickle_by_evaluation(function):
    f = function
    f2 = loads(dumps(f))
    mus = parameters_of_type(f.parameter_type, 47)
    for arg in function_argument(f, 10, 42):
        mu = next(mus)
        assert np.all(f.evaluate(arg, mu) == f2.evaluate(arg, mu))
예제 #5
0
def assert_picklable_without_dumps_function(o):
    def dumps_function_raise(function):
        raise PicklingError('Cannot pickle function {}'.format(function))

    old_code = dumps_function.__code__
    dumps_function.__code__ = dumps_function_raise.__code__
    try:
        s = dumps(o)
        o2 = loads(s)
        assert_is_equal(o, o2)
    finally:
        dumps_function.__code__ = old_code
예제 #6
0
파일: pickle.py 프로젝트: sdrave/pymor
def assert_picklable_without_dumps_function(o):
    def dumps_function_raise(function):
        raise PicklingError("Cannot pickle function {}".format(function))

    old_code = dumps_function.func_code
    dumps_function.func_code = dumps_function_raise.func_code
    try:
        s = dumps(o)
        o2 = loads(s)
        assert_is_equal(o, o2)
    finally:
        dumps_function.func_code = old_code
예제 #7
0
파일: pickling.py 프로젝트: pymor/pymor
def assert_picklable_without_dumps_function(o):

    def dumps_function_raise(function):
        raise PicklingError(f'Cannot pickle function {function}')

    old_code = dumps_function.__code__
    dumps_function.__code__ = dumps_function_raise.__code__
    try:
        s = dumps(o)
        o2 = loads(s)
        assert_is_equal(o, o2)
    finally:
        dumps_function.__code__ = old_code
예제 #8
0
파일: mpi.py 프로젝트: denfromufa/pymor
    def event_loop():
        """Launches an MPI-based event loop.

        Events can be sent by either calling :func:`call` on
        rank 0 to execute an arbitrary method on all ranks or
        by calling :func:`quit` to exit the loop.
        """
        assert not rank0
        while True:
            try:
                method, args, kwargs = loads(comm.bcast(None))
                if method == 'QUIT':
                    break
                else:
                    method(*args, **kwargs)
            except:
                import traceback
                print("Caught exception on MPI rank {}:".format(rank))
                traceback.print_exception(*sys.exc_info())
예제 #9
0
    def event_loop():
        """Launches an MPI-based event loop.

        Events can be sent by either calling :func:`call` on
        rank 0 to execute an arbitrary method on all ranks or
        by calling :func:`quit` to exit the loop.
        """
        assert not rank0
        while True:
            try:
                method, args, kwargs = loads(comm.bcast(None))
                if method == 'QUIT':
                    break
                else:
                    method(*args, **kwargs)
            except:
                import traceback
                print(f"Caught exception on MPI rank {rank}:")
                traceback.print_exception(*sys.exc_info())
예제 #10
0
파일: pickling.py 프로젝트: prklVIP/pymor
def assert_picklable(o):
    s = dumps(o)
    o2 = loads(s)
    assert_is_equal(o, o2)
예제 #11
0
 def __setstate__(self, state):
     if state.pop('_picklable'):
         state['_mapping'] = loads(state['_mapping'])
     else:
         state['_mapping'] = loads_function(state['_mapping'])
     self.__dict__.update(state)
예제 #12
0
 def __setstate__(self, state):
     if state.pop('_picklable'):
         state['_mapping'] = loads(state['_mapping'])
     else:
         state['_mapping'] = loads_function(state['_mapping'])
     self.__dict__.update(state)