Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

optimization/converters/integer_to_binary.py: OverflowError: cannot convert float infinity to integer #1238

Closed
HassanNaseri opened this issue Sep 7, 2020 · 1 comment · Fixed by #1259
Assignees
Labels
type: bug Something isn't working

Comments

@HassanNaseri
Copy link

HassanNaseri commented Sep 7, 2020

Information

  • Qiskit Aqua version: 0.7.3
  • Python version: 3.8.2
  • Operating system: macOS Catalina

What is the current behavior?

I get the following error when converting a MIP to QUBO:

  File "xxx/.pyenv/versions/3.8.2/lib/python3.8/site-packages/qiskit/optimization/converters/integer_to_binary.py", line 114, in _encode_var
    power = int(np.log2(var_range))

OverflowError: cannot convert float infinity to integer

Steps to reproduce the problem

The InequalityToEquality() converter creates slack variables with same upperbund and lowerbound (both zero). This results in _encode_var() function crashing at following line as var_range equals zero.
power = int(np.log2(var_range))

This can be reproduced by trying to encode a least or equal constraint with all positive coefficients in LHS and zero in RHS, e.g. x[1] + x[2] <= 0, which can naturally happen in automatically converting large problems. This can be safely encoded as x[1] + x[2] = 0 without slack variables.

What is the expected behavior?

The expected behaviour is not to create such slack variables at first place.

Suggested solutions

This should be fixed at two places.

  • The InequalityToEquality() converter should not create slack variables if both upperbound and lowerbound are same.
  • The IntegerToBinary() converter should check the var_range before trying to implement binary encoding.
@t-imamichi
Copy link
Contributor

Thank you for reporting the error. We will add a check of var_range.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants