California-Planet-Search / radvel

General Toolkit for Modeling Radial Velocity Data
http://radvel.readthedocs.io
MIT License
57 stars 52 forks source link

posterior object cannot access residuals anymore! #330

Closed sealauren closed 3 years ago

sealauren commented 3 years ago

This code, which used to work, is broken. It looks like the new "vector" instance being misused is the problem?

resids = post.residuals()

~/opt/anaconda3/lib/python3.7/site-packages/radvel/posterior.py in residuals(self) 82 """Overwrite inherited residuals method that does not work""" 83 ---> 84 return self.likelihood.residuals() 85 86 def bic(self):

~/opt/anaconda3/lib/python3.7/site-packages/radvel/likelihood.py in residuals(self) 295 """ 296 --> 297 res = self.like_list[0].residuals() 298 for like in self.like_list[1:]: 299 res = np.append(res, like.residuals())

~/opt/anaconda3/lib/python3.7/site-packages/radvel/likelihood.py in residuals(self) 353 Data minus model 354 """ --> 355 mod = self.model(self.x) 356 357 if self.vector.vector[self.gamma_index][3] and not self.vector.vector[self.gamma_index][1]:

~/opt/anaconda3/lib/python3.7/site-packages/radvel/model.py in call(self, t, *args, *kwargs) 285 vel (array of floats): model at each time in t 286 """ --> 287 vel = self._forward_model(t,self.params,self.vector,args,kwargs) 288 vel += self.vector.vector[self.vector.indices['dvdt']][0] (t - self.time_base) 289 vel += self.vector.vector[self.vector.indices['curv']][0] (t - self.time_base)2

AttributeError: 'RVModel' object has no attribute 'vector'

sealauren commented 3 years ago

To clarify, the thing that broke this is I was loading a pickled "post" object. I found that rerunning my MCMC code to make a new posterior object and then loading that one instead solved the problem. I think a best-practice strategy is to avoid forward-development that makes people's old posteriors no longer compatible, so let's be thoughtful about this in the future.

bjfultn commented 3 years ago

Unfortunately, this issue is a known limitation of using pickle/dill to store our saved objects. Old pickled objects will never be able to be loaded using a newer version if there has been any functional changes to the object. Its best to stick to a single version of RadVel for the duration of a project unless a new feature is required. You can always downgrade to an older version of RadVel within a conda/virtualenv environment as needed (e.g. pip install radvel==1.3.7).

We should strive to ensure backwards compatibility between minor releases (e.g. v1.4.0 objects can be read in v1.4.2), but we can't ensure this for major releases (e.g. v1.3.8 objects likely can not be read in v1.4.0+).