object loaded by pickle is different than the intended

191 Views Asked by At

I am trying to optimize a function with nevergrad and save the resulting recommendation in a pickle. But when I assert saved_obj == loaded_obj it raises an error.

To reproduce the issue I uploaded per_recommendation.pkl : https://drive.google.com/file/d/1bqxO2JjrTP2qh23HT-qdr9Mf1Kfe4mtC/view?usp=sharing

import pickle
import nevergrad

# load obj (in the real code this is the result of some optimization)
with open('/home/franchesoni/Downloads/per_recommendation.pkl', 'rb') as f:
  r2 = pickle.load(f)
# r2 = optimizer.minimize(fn)

# save the object
with open('/home/franchesoni/Downloads/per_recommendation2.pkl', 'wb') as f:
  pickle.dump(r2, f)

# load the object
with open('/home/franchesoni/Downloads/per_recommendation2.pkl', 'rb') as f:
  recommendation = pickle.load(f)

# they are different!
assert r2 == recommendation

Is this normal or expected?

off-question: in the python docs I read pickle is unsafe, is it dangerous to open (for example) the file I uploaded? is it dangerous to reveal paths like /home/franchesoni?

0

There are 0 best solutions below