Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'CustomSignal' object has no attribute '_loglikelihood' #54

Closed
thjsal opened this issue Sep 1, 2022 · 2 comments
Closed
Labels
bug Something isn't working enhancement New feature or request hackweek2022 Issues to be fixed during the 2022 Hack Week

Comments

@thjsal
Copy link
Contributor

thjsal commented Sep 1, 2022

Calling the likelihood check function seem to result in AttributeError: 'CustomSignal' object has no attribute '_loglikelihood' error at least in the following cases:

  • If calling originally the star object with the same parameter vector p (by star(p)) as that which is provided to the likelihood check function (likelihood.check(None, [-3.27536126e+04], 1.0e-6,physical_points=[p])), and not clearing the cache (likelihood.clear_cache()) before the likelihood check or possibly not calculating the likelihood by calling the likelihood object directly first (likelihood(p)). This happens because the likelihood check then thinks that likelihood was already calculated (and the attribute _loglikelihood would then exist) even though it was actually not.

  • As in the previous case, but if the parameter vector provided is out of the prior bounds, calling just first likelihood(p) does not help since the likelihood will not be fully calculated and the attribute _loglikelihood will not be introduced. Clearing the cache before the likelihood check will anyway solve the problem.

I would suggest either handling this error better to give a more helpful error message about the likely cause of the issue or clearing the cache always by default before doing the rest of the likelihood check (which I think would always prevent the error from happening, at least for these cases). Clearing the cache could be automatically done at the beginning of the check() function in Likelihood.py by adding a line: self.clear_cache(). Unless people think it is good to keep the possibility for cached likelihood checks if parameters are unchanged?

@thjsal thjsal added bug Something isn't working enhancement New feature or request labels Sep 1, 2022
@sguillot
Copy link
Contributor

sguillot commented Sep 2, 2022

This error rings a bell. I think I've encountered it too!

@thjsal
Copy link
Contributor Author

thjsal commented Sep 2, 2022

@sguillot yep! I noticed your slack thread with Tom. Apparently this same error can also happen when starting to sample with MultiNest if not using the option likelihood.externally_updated = True. Clearing the cache before sampling is not enough in that case unless that done every time inside the call function of the Likelihood class.

For simple likelihood checks that I mentioned above the externally updating would also fix the problem, but for some reason externally_updated is set to always False in the check() function at the moment.

@thjsal thjsal added the hackweek2022 Issues to be fixed during the 2022 Hack Week label Sep 5, 2022
@thjsal thjsal closed this as completed in 350815c Sep 16, 2022
dhuppenkothen pushed a commit that referenced this issue Sep 23, 2022
Added options allowing user to force update likelihood and avoid errors caused by unintended functioning of the automatic need-update-check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request hackweek2022 Issues to be fixed during the 2022 Hack Week
Projects
None yet
Development

No branches or pull requests

2 participants