This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
Fix a bug of the integer to binary converter #1256
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix a bug reported at stackexchange.
This PR fixes the bug and add a unit test to cover this case.
The following code raises an error in
IntegerToBinary
.Details and comments
The main reason is that there were some codes missing
use_name=True
ofLinearExpression.to_dict
andQuadraticExpression.to_dict
.I also notice that the return type does not match the definition
QuadraticExpression.to_dict
.Especially, the signature of
to_dict
isDict[Union[Tuple[int, int], Tuple[str, str]], float]
;but, the following returns
Tuple[np.int32, np.int32], float]
. Becauseisinstance(value, int) == False
withvalue: np.int32
. This is the reason why only quadratic constraints raises this bug. I fix this issue as well.https://github.com/Qiskit/qiskit-aqua/blob/793ffc5cfc3cfbab470ba0243fb80d42fcd28ebb/qiskit/optimization/problems/quadratic_expression.py#L171