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

dtype problem in flatten model process #383

Closed
CharlezXue opened this issue Jul 6, 2023 · 2 comments · Fixed by #390
Closed

dtype problem in flatten model process #383

CharlezXue opened this issue Jul 6, 2023 · 2 comments · Fixed by #390
Assignees

Comments

@CharlezXue
Copy link
Contributor

Hi,

when I was flattening wsum expression like [numpy.int64 objects] * [intvars],
(object numbers are about 1e8, which is below int32 upper bound, but the wsum bound may exceed.)
error occured on cpmpy.expressions.core.Operator.get_bounds, which gives false bounds from overflowed numpy.sum().

problem solved after I raised first object over int32 upper bound.

@tias
Copy link
Collaborator

tias commented Jul 7, 2023

Hi Charlez,

So do I understand correctly that the get_bounds() method returned an overflowed np.int32, instead of an int64? And how did you solve it?

I don't seem to be able to reproduce it, this runs fine:

v = 2 ** 33
print(v)
v3 = np.array([v,v], dtype="int64")
print(v3)
e = sum(v3*cp.intvar(1,9, shape=(2)))
print(e)
print(e.get_bounds())

8589934592
[8589934592 8589934592]
sum([8589934592, 8589934592] * [IV11, IV12])
(17179869184, 154618822656)

@CharlezXue
Copy link
Contributor Author

Hi tias,

Thanks for responding. After revisit, I found that the triggering conditions are not as simple as I originally thought it was.
Here's the code for reproduce this problem.

v = intvar(0,1,(2))
v2 = np.array([int(1e9),int(1e9)], dtype="int64")
v3 = [2,2]
e = min((sum(v * v2 * v3),int(1e9)))
print(e.get_bounds()) # this works fine

m = Model()
m += e == 0
m.solve() # AssertionError: assert (lb <= ub) caused by overflow bounds

And how did you solve it?

Raise 1e9 to 1e10

@CharlezXue CharlezXue reopened this Jul 10, 2023
@Wout4 Wout4 self-assigned this Jul 10, 2023
@Wout4 Wout4 linked a pull request Jul 10, 2023 that will close this issue
@Wout4 Wout4 closed this as completed in #390 Sep 8, 2023
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 a pull request may close this issue.

3 participants