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

Fixed bugs of converters in the case of that the range of variable is 0 #1259

Merged
merged 7 commits into from
Sep 28, 2020

Conversation

a-matsuo
Copy link
Contributor

Summary

Fixes #1238

Details and comments

When the range of additional slack variables is 0, the InequalityToEquality and IntegerToBinary converters had unexpected behaviors.
This PR fixes that issue.

@t-imamichi
Copy link
Contributor

How about showing a warning that an integer variable has 0-range?
E.g.,

qp = QuadraticProgram()
qp.integer_var(name='x', lowerbound=0, upperbound=0)
# -> Warning: integer variable 'x' has range 0.

@a-matsuo
Copy link
Contributor Author

I think it does make sense. Shall I add the warning message?

@t-imamichi
Copy link
Contributor

I'm OK. What do you think, @stefan-woerner and @woodsp-ibm?

@woodsp-ibm
Copy link
Member

When adding a variable to QP the Variable class has this

        if lowerbound > self.upperbound:
            raise QiskitOptimizationError("Lowerbound is greater than upperbound!")

This seems to imply that lowerbound equal to upperbound is a valid Variable, whether it is 0 or some other number. In effect the variable is a constant value assuming at least one of the bounds is an inclusive value.

So this issue is fixing an issue in the conversion, not where the user did this but where a conversion would add a variable which would be a constant and have value 0 due to bounds. I am not sure where the problem arises with this 'constant'. It seems as an end user I am able to create such 'constants' via having the bounds the same. In one of the conversions such a constant is dropped in the other an error is raised.

On the warning suggestion is this some special case with 0 - or is it true for any with upper/lower bounds equal? Should this be a warning or should the check in Variable be changed to include equality such its an error. Maybe this equality is just an issue for these two convertors and it is fine for QP in general to have such Variables with only one possible value i.e. a constant. So I cannot say one way or another if raising a warning is the right thing to do - in my mind it depends on what is the expected behavior when bounds are the same and/or both are 0.

@t-imamichi
Copy link
Contributor

I think lowerbound == self.upperbound is not a valid condition as a variable. Such variable should be given as a constant of the input model. So, it is an option to modify the condition as follows.

        if lowerbound >= self.upperbound:
            raise QiskitOptimizationError("Lowerbound is equal to or greater than upperbound!")

The conversion algorithm uses an assumption that the range of bounds is non-zero.

@stefan-woerner
Copy link
Contributor

stefan-woerner commented Sep 18, 2020

I think having lb == ub is valid. E.g. think about some higher level algorithms (decomposition etc.) that automatically update bounds and leverage a QUBO solver underneath, then that might happen (and is not necessarily handled specifically).

So I would not at a warning.
You can either let the converter replace it by a constant and introduce the value again later to the solution. But for transparency reasons, I would just handle it as is, i.e., have a single binary variable, that is forced to be 0.

@t-imamichi
Copy link
Contributor

I see. Then, we maybe need another converter to substitute 0-range integer variables with constants. It is possible to implement it using QuadraticProgram.substitute_variables.

@stefan-woerner
Copy link
Contributor

yes, we already have this functionality via substitute_variables. We can add such a converter on our backlog. For now, I would let the user handle this special case.

@t-imamichi
Copy link
Contributor

OK. So, I think this pullreq is ready if the conflict is resolved. We need to make another converter IntegerToConstant as another pullreq.

@woodsp-ibm woodsp-ibm added the Changelog: Bugfix Include in the Fixed section of the changelog label Sep 18, 2020
@woodsp-ibm woodsp-ibm added this to the 0.8 milestone Sep 18, 2020
@woodsp-ibm
Copy link
Member

Can we fix the conflict here so this can be merged - I believe the PR is ready.

@a-matsuo
Copy link
Contributor Author

Hi Steve, sorry, I had not merged the master. Now, the conflict should be solved. Ya, the PR is ready.

@manoelmarques manoelmarques merged commit 0132e08 into qiskit-community:master Sep 28, 2020
manoelmarques added a commit to qiskit-community/qiskit-optimization that referenced this pull request Jan 14, 2021
… 0 (qiskit-community/qiskit-aqua#1259)

* fixed ineq2eq and int2bin converters

* removed the warning msg

* fix test

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Changelog: Bugfix Include in the Fixed section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimization/converters/integer_to_binary.py: OverflowError: cannot convert float infinity to integer
5 participants