Skip to content

Pickled Object created by Python 3.6 cannot be loaded in Python 3.7 #738

Closed
@bantin

Description

I'm new to sacred, and I am running into an issue trying to load an object created by a different python version.

I run my experiments on a SLurm cluster (Python 3.6.1) through my academic institution, and save out a dictionary of results using pickle. However, when I try to then load the pickled data on my laptop (which runs Python 3.7) I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-a7579d7c1c2b> in <module>
      2 # elbos = pickle.load(open("./poisson_lds_elbos.pkl", "rb"))
      3 # posterior = pickle.load(open("./poisson_lds_posterior.pkl", "rb"))
----> 4 results = pickle.load(open("./lds_fit_results_poisson_rotational_orthog.pkl", "rb"))
      5 lds = results["lds"]
      6 elbos = results["elbos"]

~/anaconda3/envs/ssm/lib/python3.7/site-packages/sacred/config/custom_containers.py in _readonly(self, *args, **kwargs)
    171 
    172     def _readonly(self, *args, **kwargs):
--> 173         raise SacredError(self.message, filter_traceback="always")
    174 
    175 

AttributeError: 'ReadOnlyList' object has no attribute 'message'

Here is the script which I ran to create the object:

import numpy as np
import matplotlib.pyplot as plt
import ssm
import pickle

from scipy.io import loadmat
from sacred import Experiment

ex = Experiment('poisson_lds_pjpca')

def load_data(path, sqrt=True):
    struct = loadmat(path)
    spikes = struct["binned"]
    spikes = spikes.astype(int)
    if sqrt:
        spikes = np.sqrt(spikes)
    spikes = np.swapaxes(spikes, -1, -2)
    return [x for x in spikes]

@ex.config
def cfg():
  data_path = "./binned_start-60_end190_width10_all_units.mat"
  datas = load_data(data_path, sqrt=False)
  D = 10
  N = datas[0].shape[-1]
  dynamics = "rotational"
  emissions = "poisson_orthog"
  masks = None
  num_iters = 50
  method = "laplace_em"
  results_path = "lds_fit_results_poisson_rotational_orthog.pkl"

@ex.automain
def run(N, D, data_path, datas, dynamics, emissions, masks, num_iters, method, results_path):
  ex.add_resource(data_path)
  lds = ssm.LDS(N, D, dynamics=dynamics, emissions=emissions)
  elbos, posterior = lds.fit(datas, num_iters=num_iters, method=method, masks=masks)
  results = dict(lds=lds,
                 posterior=posterior,
                 elbos=elbos,
                 datas=datas)

  print("saving results to %s" % results_path)
  pickle.dump(results, open(results_path, "wb"))
  ex.add_artifact(results_path)
  return elbos

Is there something obviously wrong with saving data using Pickle during a Sacred experiment? Or perhaps this is a bug?

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions