Skip to content

Instantly share code, notes, and snippets.

@roban
Created December 11, 2012 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roban/4261708 to your computer and use it in GitHub Desktop.
Save roban/4261708 to your computer and use it in GitHub Desktop.
copy pymc traces from a db instance to a new db.
def copy_traces(db1, dbname, dbclass, traceclass, **kwargs):
"""Copy traces from a db to a new db.
"""
db = dbclass(dbname=dbname, dbmode='w', **kwargs)
db._initialize({}, 1)
db.trace_names = db1.trace_names
db.chains = 1
# Create the Traces.
for name, trace in db1._traces.iteritems():
db._traces[name] = traceclass(name=name, value={0:trace[:]}, db=db)
setattr(db, name, db._traces[name])
# Load the state.
db._state_ = db1.getstate()
db._finalize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment