California-Planet-Search / radvel

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

UserDefinedPrior fails (including documentation example) #346

Open parkerholzer opened 3 years ago

parkerholzer commented 3 years ago

I'm working to put a user-defined prior on the eccentricity, but the example given in the documentation for how to do this produces an error. From the traceback, I suspect it has something to do with the TexString argument:

AttributeError: 'str' object has no attribute 'name'

bjfultn commented 3 years ago

Could you expand a little on how you are setting this up and provide a more complete traceback?

parkerholzer commented 3 years ago

Sure, I open the .py file where the parameterization, optimization starting points, and priors are defined. Then I define the function that returns the density for the user defined prior. (Is this the file where that is supposed to go???)

I did manage to get around the issue by simply adding a class to the priors.py file in the radvel code, keeping the same structure as the other existing classes.

The complete Traceback is as follows though:

Traceback (most recent call last): File "/opt/anaconda3/bin/radvel", line 8, in sys.exit(main()) File "/opt/anaconda3/lib/python3.7/site-packages/radvel/cli.py", line 197, in main args.func(args) File "/opt/anaconda3/lib/python3.7/site-packages/radvel/driver.py", line 151, in fit post.writeto(postfile) File "/opt/anaconda3/lib/python3.7/site-packages/radvel/posterior.py", line 79, in writeto pickle.dump(self, f) File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 267, in dump Pickler(file, protocol, *_kwds).dump(obj) File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 454, in dump StockPickler.dump(self, obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 437, in dump self.save(obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, rv) File "/opt/anaconda3/lib/python3.7/pickle.py", line 662, in save_reduce save(state) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 941, in save_module_dict StockPickler.save_dict(pickler, obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 859, in save_dict self._batch_setitems(obj.items()) File "/opt/anaconda3/lib/python3.7/pickle.py", line 885, in _batch_setitems save(v) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/pickle.py", line 819, in save_list self._batch_appends(obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 843, in _batch_appends save(x) File "/opt/anaconda3/lib/python3.7/pickle.py", line 549, in save self.save_reduce(obj=obj, *rv) File "/opt/anaconda3/lib/python3.7/pickle.py", line 662, in save_reduce save(state) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 941, in save_module_dict StockPickler.save_dict(pickler, obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 859, in save_dict self._batch_setitems(obj.items()) File "/opt/anaconda3/lib/python3.7/pickle.py", line 885, in _batch_setitems save(v) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 1447, in save_function obj.dict, fkwdefaults), obj=obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 638, in save_reduce save(args) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/pickle.py", line 789, in save_tuple save(element) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 941, in save_module_dict StockPickler.save_dict(pickler, obj) File "/opt/anaconda3/lib/python3.7/pickle.py", line 859, in save_dict self._batch_setitems(obj.items()) File "/opt/anaconda3/lib/python3.7/pickle.py", line 885, in _batch_setitems save(v) File "/opt/anaconda3/lib/python3.7/pickle.py", line 504, in save f(self, obj) # Call unbound method with explicit self File "/opt/anaconda3/lib/python3.7/site-packages/dill/_dill.py", line 1330, in save_module log.info("M2: %s" % obj) File "", line 286, in _module_repr File "", line 596, in _module_repr_from_spec AttributeError: 'str' object has no attribute 'name'

bjfultn commented 2 years ago

I'm glad you found a workaround, but I still would like to track this down.

Could you share density function and the line that initializes the prior?

If you have a generally-useful prior that you think should be included with the radvel package I'd be happy to look over a pull request for what you've implemented.

ngierty commented 1 year ago

I'm also having a similar User-Defined Prior issue when using the command line to fit a model. I can use the command line fit function just fine but when I try to sample using mcmc I get a pickle error. I've attached my code that's causing the error that uses the example from the docs as a test. I'll try the work-around suggested above.

User_Defined_Prior.txt