Skip to content

Make Approximation serializeable #2615

@pstjohn

Description

@pstjohn

If I have a (lengthy) advi optimization, whats the best way to store the result for a future notebook?

with pymc_model:

    approx = pm.fit(
        method='advi', n=50000, random_seed=1, callbacks=cb,
        obj_optimizer=pm.adagrad_window(learning_rate=.5, n_win=100))

    trace = approx.sample(1000)

Pickling the trace works,

import pickle

with open('trace.p', 'wb') as f:
    pickle.dump(trace, f)
    
with open('trace.p', 'rb') as f:
    test1 = pickle.load(f)

But pickling the approx class fails when I try to load it.

with open('approx.p', 'wb') as f:
    pickle.dump(approx, f)
    
with open('approx.p', 'rb') as f:
    test2 = pickle.load(f)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-54dd7d55c9e6> in <module>()
      3 
      4 with open('approx.p', 'rb') as f:
----> 5     test2 = pickle.load(f)

TypeError: __new__() missing 1 required positional argument: 'group'

Versions and main components

  • PyMC3 Version: 3.1
  • Theano Version: 0.9.0
  • Python Version: 3.6
  • Operating system: Mac OS X
  • How did you install PyMC3: from source

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions