Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
import sys
import dill
import test_mixins as module
try: from imp import reload
except ImportError: pass
dill.settings['recurse'] = True
cached = (module.__cached__ if hasattr(module, "__cached__")
else module.__file__.split(".", 1)[0] + ".pyc")
module.a = 1234
pik_mod = dill.dumps(module)
module.a = 0
# remove module
del sys.modules[module.__name__]
del module
module = dill.loads(pik_mod)
def test_attributes():
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
import functools
import dill
dill.settings['recurse'] = True
def f(a, b, c): # without keywords
pass
def g(a, b, c=2): # with keywords
pass
def h(a=1, b=2, c=3): # without args
pass
def test_functools():
fp = functools.partial(f, 1, 2)
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
"""
testing some selected object types
"""
import dill
dill.settings['recurse'] = True
verbose = False
def test_dict_contents():
c = type.__dict__
for i,j in c.items():
#try:
ok = dill.pickles(j)
#except:
# print ("FAIL: %s with %s" % (i, dill.detect.errors(j)))
if verbose: print ("%s: %s, %s" % (ok, type(j), j))
assert ok
if verbose: print ("")
def _g(x): yield x;
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
import sys
import dill
dill.settings['recurse'] = True
class Foo(object):
def __init__(self):
self._data = 1
def _get_data(self):
return self._data
def _set_data(self, x):
self._data = x
data = property(_get_data, _set_data)
def test_data_not_none():
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
import dill
dill.settings['recurse'] = True
import weakref
class _class:
def _method(self):
pass
class _class2:
def __call__(self):
pass
class _newclass(object):
def _method(self):
pass
class _newclass2(object):
def __call__(self):
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
"""
test dill's ability to handle nested functions
"""
import os
import math
import dill as pickle
pickle.settings['recurse'] = True
# the nested function: pickle should fail here, but dill is ok.
def adder(augend):
zero = [0]
def inner(addend):
return addend + augend + zero[0]
return inner
# rewrite the nested function using a class: standard pickle should work here.
class cadder(object):
def __init__(self, augend):
self.augend = augend
self.zero = [0]
Author: Dat Tran
Email: dat.tranthanh@tut.fi, viebboy@gmail.com
github: https://github.com/viebboy
"""
import pickle
from . import misc
import os
import glob
import dill
import copy
import subprocess
import time
import numpy as np
dill.settings['recurse'] = True
def he_init(fan_in, fan_out, shape):
"""Initialize layer weights using He init method
Args:
fan_in (int): Number of input neurons
fan_out (int): Number of output neurons
shape (list): Shape of layer weight
Returns:
Numpy array of given shape
Reference:
https://arxiv.org/abs/1502.01852
"""
from __future__ import print_function
from . import gop_operators
from keras.callbacks import Callback as Callback
from keras import backend as K
from keras import optimizers as keras_optimizers
import pickle
import os
import sys
import dill
import inspect
import copy
import numpy as np
dill.settings['recurse'] = True
CUDA_FLAG = 'CUDA_VISIBLE_DEVICES'
class BestModelLogging(Callback):
"""Custom callback used when training Keras model
This callback allows recording all metrics in keras model
as well as special metrics, which require full batch evaluation instead of
mini-batch aggregation
Args:
convergence_measure (str): Name of metric to monitor best model setting
direction (str): String to indicate relative quality of convergence measure
special_metrics (list): List of callable to calculate special metrics
# Copyright (C) 2016 Antoine Carme
# All rights reserved.
# This file is part of the Python Automatic Forecasting (PyAF) library and is made available under
# the terms of the 3 Clause BSD license
import pandas as pd
import numpy as np
import traceback
import dill
dill.settings['recurse'] = False
# import dill
# import multiprocessing as mp
from pathos.multiprocessing import ProcessingPool as Pool
# for timing
import time
import threading
from . import Time as tsti
from . import Exogenous as tsexog
from . import MissingData as tsmiss
from . import Signal_Transformation as tstransf
from . import Perf as tsperf
from . import SignalDecomposition_Trend as tstr
from . import SignalDecomposition_Cycle as tscy
import json
import functools
from contextlib import contextmanager
import boto3
import botocore
import dill
from .deployment import DeploymentPackage
dill.settings['recurse'] = True
# this flags allow you to control the point in time at which to create/update your function
# It is needed due to the expensive transfer of a zip file with packed environment
# when updating/creating a function code
UPDATE_EXPLICIT = 0 # you'll have to create your lambda explicitly
UPDATE_ON_INIT = 1 # perform update on Lambda initialization
UPDATE_LAZY = 2 # perform update just before invoking the function
CREATE_ONCE = 4 # create the function, if it doesn't exist
class Lambda(object):
"""Wrapper class around a callable
This wrapper basically replaces the original function with it's AWS Lambda instance.
When called, the instance of this class will route the call to the AWS Instance, instead of