当前位置: 首页>>代码示例>>Python>>正文


Python dill.loads方法代码示例

本文整理汇总了Python中dill.loads方法的典型用法代码示例。如果您正苦于以下问题:Python dill.loads方法的具体用法?Python dill.loads怎么用?Python dill.loads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dill的用法示例。


在下文中一共展示了dill.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_excel_model_compile

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_excel_model_compile(self):
        xl_model = ExcelModel().loads(self.filename_compile).finish()

        inputs = ["A%d" % i for i in range(2, 5)]
        outputs = ["C%d" % i for i in range(2, 5)]
        func = xl_model.compile(
            ["'[EXCEL.XLSX]DATA'!%s" % i for i in inputs],
            ["'[EXCEL.XLSX]DATA'!%s" % i for i in outputs]
        )
        i = sh.selector(inputs, self.results_compile, output_type='list')
        res = sh.selector(outputs, self.results_compile, output_type='list')
        self.assertEqual([x.value[0, 0] for x in func(*i)], res)
        self.assertIsNot(xl_model, copy.deepcopy(xl_model))
        self.assertIsNot(func, copy.deepcopy(func))

        xl_model = ExcelModel().loads(self.filename_circular).finish(circular=1)
        func = xl_model.compile(
            ["'[CIRCULAR.XLSX]DATA'!A10"], ["'[CIRCULAR.XLSX]DATA'!E10"]
        )
        self.assertEqual(func(False).value[0, 0], 2.0)
        self.assertIs(func(True).value[0, 0], ERR_CIRCULAR)
        self.assertIsNot(xl_model, copy.deepcopy(xl_model))
        self.assertIsNot(func, copy.deepcopy(func)) 
开发者ID:vinci1it2000,项目名称:formulas,代码行数:25,代码来源:test_excel.py

示例2: get_function

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def get_function(self, func, name):
        """Returns a precondition/postcondition/execution object.

        Parameters
        ----------
        func : :obj:`str`
            Name of the function group (precondition, postcondition, execution)
        name : :obj:`str`
            Name of the function.

        Returns
        -------
        :obj: `function`
            Function obtained.

        """
        f = bytearray.fromhex(self._functions[func][name])
        return dill.loads(f) 
开发者ID:shramos,项目名称:polymorph,代码行数:20,代码来源:template.py

示例3: _handle_loopback

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def _handle_loopback(self, message):
        """
        Handle incoming messages in the loopback socket.
        """
        header, data = cloudpickle.loads(message)
        if header == 'EXECUTE_METHOD':
            method, args, kwargs = data
            try:
                response = getattr(self, method)(*args, **kwargs)
            except Exception as error:
                yield format_method_exception(error, method, args, kwargs)
                raise
            yield response or True
        else:
            error = 'Unrecognized loopback message: {} {}'.format(header, data)
            self.log_error(error)
            yield error 
开发者ID:opensistemas-hub,项目名称:osbrain,代码行数:19,代码来源:agent.py

示例4: dill_helper

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def dill_helper(payload: Any) -> Any:
    """
    Load single sample from data serialized by dill
    Args:
        payload: data which is loaded with dill

    Returns:
        Any: loaded data

    """
    if not DILL_AVAILABLE:
        raise RuntimeError('dill is not installed. For async loading '
                           'please install it')

    fn, args, kwargs = dill.loads(payload)
    return fn(*args, **kwargs) 
开发者ID:PhoenixDL,项目名称:rising,代码行数:18,代码来源:dataset.py

示例5: test_blue_io

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_blue_io(self):
        import dill
        s0 = self.dsp()
        pre_dsp = dill.dumps(self.dsp)
        blue = self.dsp.blue()
        self.assertEqual(pre_dsp, dill.dumps(self.dsp))
        pre = dill.dumps(blue), pre_dsp
        sol = blue()
        post = dill.dumps(blue), dill.dumps(self.dsp)
        self.assertEqual(pre, post)
        s = self.dsp()
        post = dill.dumps(blue), dill.dumps(self.dsp)
        self.assertEqual(pre, post)
        self.assertEqual(s, sol)
        self.assertEqual(s0, sol)
        self.assertLess(*map(len, post))
        self.assertLess(len(post[1]), len(dill.dumps(s)))
        blue, dsp = list(map(dill.loads, post))
        self.assertEqual(dsp.solution, {})
        self.assertEqual(s, dsp())
        self.assertEqual(s, blue()) 
开发者ID:vinci1it2000,项目名称:schedula,代码行数:23,代码来源:test_blue.py

示例6: __init__

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def __init__(self, algo, domain, trials, rstate, asynchronous=None,
                 max_queue_len=1,
                 poll_interval_secs=1.0,
                 max_evals=sys.maxsize,
                 verbose=0,
                 ):
        self.algo = algo
        self.domain = domain
        self.trials = trials
        if asynchronous is None:
            self.asynchronous = trials.asynchronous
        else:
            self.asynchronous = asynchronous
        self.poll_interval_secs = poll_interval_secs
        self.max_queue_len = max_queue_len
        self.max_evals = max_evals
        self.rstate = rstate

        if self.asynchronous:
            if 'FMinIter_Domain' in trials.attachments:
                logger.warn('over-writing old domain trials attachment')
            msg = pickler.dumps(domain)
            # -- sanity check for unpickling
            pickler.loads(msg)
            trials.attachments['FMinIter_Domain'] = msg 
开发者ID:LGE-ARC-AdvancedAI,项目名称:auptimizer,代码行数:27,代码来源:fmin.py

示例7: test_metric

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_metric():
    def _test(m, values, e):
        for v in values:
            m.update(v)
        assert m.compute() == e

    metric = Accumulation()

    m1 = dill.loads(dill.dumps(metric))

    values = list(range(10))
    expected = sum(values)

    _test(m1, values, expected)

    metric.update(5)

    m2 = dill.loads(dill.dumps(metric))

    _test(m2, values, expected + 5) 
开发者ID:pytorch,项目名称:ignite,代码行数:22,代码来源:test_dill.py

示例8: __init__

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def __init__(self,
                 topic,
                 consumer,
                 callback=None,
                 deserializer=None,
                 logger=None):

        assert is_str(topic), 'topic must be a str'
        assert isinstance(consumer, KafkaConsumer), 'bad consumer instance'
        assert consumer.config['group_id'], 'consumer must have group_id'
        assert is_none_or_func(callback), 'callback must be a callable'
        assert is_none_or_func(deserializer), 'deserializer must be a callable'
        assert is_none_or_logger(logger), 'bad logger instance'

        self._topic = topic
        self._hosts = consumer.config['bootstrap_servers']
        self._group = consumer.config['group_id']
        self._consumer = consumer
        self._callback = callback
        self._deserializer = deserializer or dill.loads
        self._logger = logger or logging.getLogger('kq.worker') 
开发者ID:joowani,项目名称:kq,代码行数:23,代码来源:worker.py

示例9: test_pickle

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_pickle(self):
        import sys
        if sys.version_info < (3, 4):
            import dill as pickle
        else:
            import pickle

        states = ['A', 'B', 'C', 'D']
        # Define with list of dictionaries
        transitions = [
            {'trigger': 'walk', 'source': 'A', 'dest': 'B'},
            {'trigger': 'run', 'source': 'B', 'dest': 'C'},
            {'trigger': 'sprint', 'source': 'C', 'dest': 'D'}
        ]
        m = Machine(states=states, transitions=transitions, initial='A')
        m.walk()
        dump = pickle.dumps(m)
        self.assertIsNotNone(dump)
        m2 = pickle.loads(dump)
        self.assertEqual(m.state, m2.state)
        m2.run() 
开发者ID:pytransitions,项目名称:transitions,代码行数:23,代码来源:test_core.py

示例10: test_pickle

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_pickle(self):
        print("separator", self.state_cls.separator)
        if sys.version_info < (3, 4):
            import dill as pickle
        else:
            import pickle

        states = ['A', 'B', {'name': 'C', 'children': ['1', '2', {'name': '3', 'children': ['a', 'b', 'c']}]},
                  'D', 'E', 'F']
        transitions = [
            {'trigger': 'walk', 'source': 'A', 'dest': 'B'},
            {'trigger': 'run', 'source': 'B', 'dest': 'C'},
            {'trigger': 'sprint', 'source': 'C', 'dest': 'D'}
        ]
        m = self.stuff.machine_cls(states=states, transitions=transitions, initial='A')
        m.walk()
        dump = pickle.dumps(m)
        self.assertIsNotNone(dump)
        m2 = pickle.loads(dump)
        self.assertEqual(m.state, m2.state)
        m2.run()
        m2.to_C_3_a()
        m2.to_C_3_b() 
开发者ID:pytransitions,项目名称:transitions,代码行数:25,代码来源:test_nesting.py

示例11: run_dill_encoded

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def run_dill_encoded(what):
    """Use dill as replacement for pickle to enable multiprocessing on instance methods"""

    fun, args = dill.loads(what)
    return fun(*args) 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:7,代码来源:__init__.py

示例12: load_byte_array

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def load_byte_array(stop_words):
    swords = stop_words[0].split(',')[0:-1]
    if sys.version_info[0] < 3:
        lst = [chr(int(d)) for d in swords]
        dmp = ''.join(lst)
        dmp = zlib.decompress(dmp)
        py_obj = dill.loads(dmp)
        return py_obj
    dmp = bytes([int(i) for i in swords])
    dmp = zlib.decompress(dmp)
    py_obj = dill.loads(dmp)
    return py_obj 
开发者ID:lifeomic,项目名称:sparkflow,代码行数:14,代码来源:pipeline_util.py

示例13: test_dill

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_dill(self):
        import dill
        obj = Range('A:A')
        self.assertEqual(str(obj), str(dill.loads(dill.dumps(obj)))) 
开发者ID:vinci1it2000,项目名称:formulas,代码行数:6,代码来源:test_tokens.py

示例14: test_excel_model_cycles

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_excel_model_cycles(self):
        xl_model = ExcelModel().loads(self.filename_circular).finish(circular=1)
        xl_model.calculate()
        books = xl_model.books
        books = {k: _book2dict(v[BOOK])
                 for k, v in xl_model.write(books).items()}

        self._compare(books, self.results_circular) 
开发者ID:vinci1it2000,项目名称:formulas,代码行数:10,代码来源:test_excel.py

示例15: test_monkey_patch_pickle

# 需要导入模块: import dill [as 别名]
# 或者: from dill import loads [as 别名]
def test_monkey_patch_pickle(f):
    f_temp = _wrap_task_call(f)
    assert dill.pickles(f_temp), "{} is not pickling correctly!".format(f)

    # Pickle everything
    s1 = dill.dumps(f_temp)
    s2 = dill.loads(s1)
    dill.dumps(s2) 
开发者ID:getsentry,项目名称:sentry-python,代码行数:10,代码来源:test_beam.py


注:本文中的dill.loads方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。