當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。