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


Python dill.HIGHEST_PROTOCOL属性代码示例

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


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

示例1: dump_to_file

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def dump_to_file(self, filename):
        """ Dump the ParallelArchipelago object to a pickle file

        The file will contain a pickle dump of a list of all the processors'
        ParallelArchipelago objects.

        Parameters
        ----------
        filename : str
            the name of the pickle file to dump
        """
        if self.comm_rank == 0:
            LOGGER.log(INFO, "Saving checkpoint: %s", filename)

        pickleable_copy = self._copy_without_mpi()
        all_par_archs = self.comm.gather(pickleable_copy, root=0)

        if self.comm_rank == 0:
            with open(filename, "wb") as dump_file:
                dill.dump(all_par_archs, dump_file,
                          protocol=dill.HIGHEST_PROTOCOL)
            LOGGER.log(DETAILED_INFO, "Saved successfully") 
开发者ID:nasa,项目名称:bingo,代码行数:24,代码来源:parallel_archipelago.py

示例2: dump

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def dump(obj, filename):
  """ Wrapper to dump an object to a file."""
  with tf.gfile.Open(filename, 'wb') as f:
    pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL) 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:6,代码来源:preprocess.py

示例3: dump

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def dump(obj, filename):
  with tf.gfile.Open(filename, 'wb') as f:
    pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL) 
开发者ID:GoogleCloudPlatform,项目名称:cloudml-samples,代码行数:5,代码来源:task.py

示例4: save

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def save(filename, study):
    """
    Save an instance of a bayesloop study class to file.

    Args:
        filename(str): Path + filename to store bayesloop study
        study: Instance of study class (Study, HyperStudy, etc.)
    """
    with open(filename, 'wb') as f:
        dill.dump(study, f, protocol=dill.HIGHEST_PROTOCOL)
    print('+ Successfully saved current study.') 
开发者ID:christophmark,项目名称:bayesloop,代码行数:13,代码来源:fileIO.py

示例5: serialize

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def serialize(ruleset, path):
    logger = logging.getLogger("oa-logger")
    logger.info("Compiling ruleset to %s", path)
    try:
        with open(os.path.expanduser(path), "wb") as f:
            pickle.dump(ruleset, f, pickle.HIGHEST_PROTOCOL)
    except (OSError, IOError) as e:
        logger.critical("Cannot open the file: %s", e)
        sys.exit(1) 
开发者ID:SpamExperts,项目名称:OrangeAssassin,代码行数:11,代码来源:compile.py

示例6: dump_to_file

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def dump_to_file(self, filename):
        """ Dump the evolutionary_optimizers object to a pickle file

        Parameters
        ----------
        filename : str
            the name of the pickle file to dump
        """
        LOGGER.log(INFO, "Saving checkpoint: %s", filename)
        with open(filename, "wb") as dump_file:
            dill.dump(self, dump_file, protocol=dill.HIGHEST_PROTOCOL)
        LOGGER.log(DETAILED_INFO, "Saved successfully") 
开发者ID:nasa,项目名称:bingo,代码行数:14,代码来源:evolutionary_optimizer.py

示例7: _remove_proc_from_pickle

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def _remove_proc_from_pickle(file_name):
    if COMM_RANK == 0:
        with open(file_name, "rb") as pkl_file:
            par_arch_list = dill.load(pkl_file)
        par_arch_list.pop(0)
        with open(file_name, "wb") as pkl_file:
            dill.dump(par_arch_list, pkl_file, protocol=dill.HIGHEST_PROTOCOL) 
开发者ID:nasa,项目名称:bingo,代码行数:9,代码来源:mpitest_parallel_archipelago.py

示例8: _add_proc_to_pickle

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def _add_proc_to_pickle(file_name):
    if COMM_RANK == 0:
        with open(file_name, "rb") as pkl_file:
            par_arch_list = dill.load(pkl_file)
        par_arch_list += par_arch_list[:2]
        par_arch_list.pop(0)
        with open(file_name, "wb") as pkl_file:
            dill.dump(par_arch_list, pkl_file, protocol=dill.HIGHEST_PROTOCOL) 
开发者ID:nasa,项目名称:bingo,代码行数:10,代码来源:mpitest_parallel_archipelago.py

示例9: test_serialization

# 需要导入模块: import dill [as 别名]
# 或者: from dill import HIGHEST_PROTOCOL [as 别名]
def test_serialization(self):
        """Check that we can serialize States and restore a world from them
        afterwards."""
        self.world.load_snapshot('initial')
        
        # get the initial snapshot
        state = self.world._snapshots['initial']

        # remember the initial world state
        world_state = deepcopy(self.world.state)
        
        # replace the world agent with a random agent
        self.world.agent = 'random'

        # step for a bit
        for i in xrange(100):
            self.world.step()
            
        # save a snapshot at the end of the simulation
        self.world.save_snapshot('foo')

        # get the final snapshot
        state2 = self.world._snapshots['foo']
        
        # remember the final world state
        world_state2 = deepcopy(self.world.state)
        
        # check that we can restore from the given states
        w = state.restore()
        self.assertTrue(np.array_equal(world_state, w.state))
        
        w = state2.restore()
        self.assertTrue(np.array_equal(world_state2, w.state))

        # serialize and deserialize the states
        state3 = dill.loads(dill.dumps(state, dill.HIGHEST_PROTOCOL))
        state4 = dill.loads(dill.dumps(state2, dill.HIGHEST_PROTOCOL))

        # check that we can restore from the initial snapshot, and that the
        # world state is equal to the original initial world state
        w = state3.restore()
        self.assertEqual(w.time, 0)
        self.assertTrue(np.array_equal(world_state, w.state))

        # check that we can restore from the final snapshot, and that the world
        # state is equal to the original final world state
        w = state4.restore()
        self.assertEqual(w.time, 100)
        self.assertTrue(np.array_equal(world_state2, w.state)) 
开发者ID:vicariousinc,项目名称:pixelworld,代码行数:51,代码来源:test_core.py


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