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

Make element total #393

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Wout4
Copy link
Collaborator

@Wout4 Wout4 commented Jul 11, 2023

No description provided.

@Wout4 Wout4 linked an issue Jul 11, 2023 that may be closed by this pull request
@Wout4 Wout4 marked this pull request as draft July 11, 2023 19:42
@Wout4
Copy link
Collaborator Author

Wout4 commented Aug 22, 2023

After discovering that solvers enforce the element bounds at toplevel, we should do the same. This also simplifies handling reified element constraints

@Wout4 Wout4 marked this pull request as ready for review September 8, 2023 13:06
@Wout4
Copy link
Collaborator Author

Wout4 commented Sep 8, 2023

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.
It comes however at a slight inconvenience to the user, that has to give precise bounds to the index variable.

@Wout4
Copy link
Collaborator Author

Wout4 commented Sep 8, 2023

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.

@Wout4 Wout4 requested a review from tias October 2, 2023 12:52
@Wout4
Copy link
Collaborator Author

Wout4 commented Oct 9, 2023

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.
@tias if you want you can take a look now.

@Wout4
Copy link
Collaborator Author

Wout4 commented Dec 21, 2023

@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

Copy link
Collaborator

@IgnaceBleukx IgnaceBleukx left a 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.")
Copy link
Collaborator

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

Copy link
Collaborator

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!")
Copy link
Collaborator

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

@IgnaceBleukx
Copy link
Collaborator

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.
Then you can return the object vioating the condition if any? It would also simplify several type checks in other constraints

@Wout4
Copy link
Collaborator Author

Wout4 commented Dec 22, 2023

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.
Seems marginal however.. Will check it out in another pr, since it will involve a lot of other globals

@Wout4 Wout4 changed the title remove special element case from reify_rewrite Make element total Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reified element constraints do not get handled correctly
2 participants