-
Notifications
You must be signed in to change notification settings - Fork 25
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
Make element total #393
base: master
Are you sure you want to change the base?
Make element total #393
Conversation
After discovering that solvers enforce the element bounds at toplevel, we should do the same. This also simplifies handling reified element constraints |
We decided to enforce strict element bounds at construction time. This eliminates the need for checking the bounds in the decomposition, and any trouble with incomplete functions. |
Another option would be to allow the creation of such an element constraint, but enforcing the bounds at toplevel and throwing an error when trying to get the value of an element constraint with index out of bounds. |
Enforced that element is Total at construction time, and because of that also enforce strict bounds for Inverse and Circuit global constraints. Added tests for this and altered the existing tests to use accurate bounds. |
…-handled-correctly # Conflicts: # tests/test_globalconstraints.py
@Dimosts can you maybe check the changes in the chess example? As you can see this is mostly changes to our tests and examples, so that they use strict bounds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
You can also link to the github issue you created in the error messages.
Then, if anyone has some questions about it they can comment on the issue?
lb = min(lbs) | ||
ub = max(ubs) | ||
if lb < 0 or ub >= len(flatargs): | ||
raise TypeError("Circuit global constraint is only defined if all bounds are between 0 and the length of the array.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't call it a type error, but rather a PartialFunctionError or something? I think we even have one already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make the error message more explicit too?
Smt like: elements in the array must have bounds 0 <= x <= len(flatargs) but got bounds [{lb},{ub}] for arg ...
lb = min(lbs) | ||
ub = max(ubs) | ||
if lb < 0 or ub >= len(fwd): | ||
raise TypeError("All arguments must be within array bounds for Inverse to have meaning over the whole domain!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here can be more explicit
I'm wondering if we should have a "vectorized check" util function or something as we are duplicating code quite a bit for these checks. It would take as input a (nested) list of elements and a boolean function which has to be checked for each of the args. |
Yes that could be nice, it's a bit ugly now, the reason I put it there is so the work happens once you already know there is a bounds issue (with an easier check), so that you don't have the overhead on normal inputs. |
No description provided.