Skip to content

Commit

Permalink
use gzip and pickletools
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Jul 10, 2020
1 parent 1ec0182 commit 8722b23
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gpkit/solution_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from operator import sub
import warnings as pywarnings
import pickle
import bz2
import gzip
import pickletools
import numpy as np
import _pickle as cPickle
from .nomials import NomialArray
Expand Down Expand Up @@ -423,13 +424,15 @@ def save(self, filename="solution.pkl", **pickleargs):

def save_compressed(self, title="solution", **cpickleargs):
"Pickle a file and then compress it into a file with extension."
with bz2.BZ2File(title + ".pbz2", "w") as f:
cPickle.dump(self, f, **cpickleargs)
with gzip.open(title + ".pgz", "wb") as f:
pickled = cPickle.dumps(self, **cpickleargs)
f.write(pickletools.optimize(pickled))

@staticmethod
def decompress_file(file):
"Load any compressed pickle file"
return cPickle.load(bz2.BZ2File(file, "rb"))
with gzip.open(file, "rb") as f:
return cPickle.Unpickler(f).load()

def varnames(self, showvars, exclude):
"Returns list of variables, optionally with minimal unique names"
Expand Down

0 comments on commit 8722b23

Please sign in to comment.