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

Precision errors when converting python floats to SCIP_REALs #794

Open
Joao-Dionisio opened this issue Feb 22, 2024 · 2 comments
Open

Precision errors when converting python floats to SCIP_REALs #794

Joao-Dionisio opened this issue Feb 22, 2024 · 2 comments
Labels

Comments

@Joao-Dionisio
Copy link
Collaborator

Joao-Dionisio commented Feb 22, 2024

Conversion of Python types to C types sometimes yields precision errors. It's not clear to me when and why this happens.

m = Model()
x = m.addVar()
m.setObjective(15.32*x)
m.writeProblem("model.cip")

image

The values stay correct right up the call to SCIPchgVarObj in L1347

Interestingly, if we set the objective at variable creation, the same doesn't happen.

m = Model()
x = m.addVar(obj=15.32)
m.writeProblem("model.cip")

image

System

  • OS: Ubuntu
  • Version 22.04
  • SCIP version 8.1.0
  • How did you install pyscipopt? Source
@leoneifler
Copy link

The number 15.32 is not exactly representable in binary floating-point format. Why this does not happen if you set it at variable creation I have no idea, but I am guessing this is the overall reason for observing this effect.

@Joao-Dionisio
Copy link
Collaborator Author

Joao-Dionisio commented Feb 26, 2024

Hey @leoneifler, thanks for looking into this! That is true, but at least in Python the precision is much higher:

image

In this PR we reverted manual variable typing, which seems to be the cause for this. See here:

image
image

Me and Mo discussed this yesterday, we have a feeling it might be due to calls to float in other files, like expr.pxi. In fact, we played around with some of this (but I can't tell for sure what did it 😞) and the error above no longer appears:

image

I have encountered this behavior in other circumstances as well, that's why I haven't created a PR.

Does this all seem reasonable, Leon? What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants