Python dill.HIGHEST_PROTOCOL Examples
The following are 9
code examples of dill.HIGHEST_PROTOCOL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dill
, or try the search function
.
Example #1
Source File: parallel_archipelago.py From bingo with Apache License 2.0 | 6 votes |
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")
Example #2
Source File: preprocess.py From cloudml-samples with Apache License 2.0 | 5 votes |
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)
Example #3
Source File: task.py From cloudml-samples with Apache License 2.0 | 5 votes |
def dump(obj, filename): with tf.gfile.Open(filename, 'wb') as f: pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL)
Example #4
Source File: fileIO.py From bayesloop with MIT License | 5 votes |
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.')
Example #5
Source File: compile.py From OrangeAssassin with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: evolutionary_optimizer.py From bingo with Apache License 2.0 | 5 votes |
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")
Example #7
Source File: mpitest_parallel_archipelago.py From bingo with Apache License 2.0 | 5 votes |
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)
Example #8
Source File: mpitest_parallel_archipelago.py From bingo with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: test_core.py From pixelworld with MIT License | 4 votes |
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))