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

Bounded parameters of -1.0 are ignored! #323

Open
ThomasTram opened this issue Apr 17, 2023 · 1 comment
Open

Bounded parameters of -1.0 are ignored! #323

ThomasTram opened this issue Apr 17, 2023 · 1 comment
Labels
bug Something isn't working enhancement New feature or request

Comments

@ThomasTram
Copy link

Hi there

The commit c692dee substituted the identity comparison operator is for the equality comparison operator ==:

self.prior_range = [a if not((a == -1) or (a == None)) else None
for a in deepcopy(array[1:3])]

However, this means that, contrary to statements in the parameter files, -1.0 can no longer be used as a prior bound! The reason it worked before was that, in CPython, the integers -5 to 256 are pre-allocated, so every integer in this range are in fact the exact same object. MontePython was relying on this to ensure that only -1 was set to None, and not -1.0.

A few comments are in order:

  • The idea that -1 can be used to signal "no bound" is crazy, and should never have been implemented. None (which also works) is appropriate.
  • The fact that all -1's are the same object is not guaranteed by the Python specification, so it should not be relied upon.

While the original implementation would still work, it will emit a syntax warning since Python 3.8, so it is not a viable solution. My preferred solution would be to remove the "feature" that -1 may signal unbounded parameters. However, the following change should reestablish the intended behaviour:

        self.prior_range = [a if not((a == -1 and type(a) == int) or (a == None)) else None
                            for a in deepcopy(array[1:3])]

Let me know if you want a PR for this!

Cheers,
Thomas

@brinckmann
Copy link
Owner

Hi Thomas,

Thank you for noticing and reporting this. I've never liked that option either, it doesn't make sense. We should stop promoting it. But for the sake of people who just keep doing what they've been doing something like your fix could be a good idea, or maybe returning a warning or error if we see they have passed -1. I'm also worried about cases where people actually want a prior bound at -1 and might not think to make it a float, so returning a statement like "Noticed prior bound of -1 in param file. If no prior bound is intended please pass None, if an actual prior bound of -1.0 is intended please pass a float." What do you think? Or we can ignore the problem and go with your suggestion, which seems workable.

Best,
Thejs

@dchooper dchooper added bug Something isn't working enhancement New feature or request labels Nov 10, 2023
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
Projects
None yet
Development

No branches or pull requests

3 participants