Skip to content

Commit

Permalink
use bz2 compressed pickles
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Jul 2, 2020
1 parent ada6753 commit 826116b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions gpkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .constraints.sigeq import SignomialEquality
from .constraints.set import ConstraintSet
from .constraints.model import Model
from .solution_array import SolutionArray
from .tools.docstring import parse_variables
from .tests.run_tests import run as run_unit_tests

Expand Down
12 changes: 12 additions & 0 deletions gpkit/solution_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from operator import sub
import warnings as pywarnings
import pickle
import bz2
import _pickle as cPickle
import numpy as np
from .nomials import NomialArray
from .small_classes import DictOfLists, Strings
Expand Down Expand Up @@ -419,6 +421,16 @@ def save(self, filename="solution.pkl", **pickleargs):
"""
pickle.dump(self, open(filename, "wb"), **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)

@staticmethod
def decompress_file(file):
"Load any compressed pickle file"
return cPickle.load(bz2.BZ2File(file, "rb"))

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

0 comments on commit 826116b

Please sign in to comment.