question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add or tweak a converter to deal with trivial variables and constraints

See original GitHub issue

What is the expected enhancement?

QuadraticProgram may include trivial variables and constraints. For example, #227 includes a trivial variable (lower bound and upper bound are equal).

Here is an example of a trivial constraint.

from qiskit_optimization.problems import QuadraticProgram

qp = QuadraticProgram()
qp.linear_constraint(sense='==', rhs=1)  # constraint: 0 == 1

It is good to eliminate such trivial cases in some existing converters or a new converter.

Fixes #227

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wpoxon-qcicommented, Aug 19, 2021

@wpoxon-qci I made another bug fix of int2bin #230. If you are OK, I can include your suggestion as part of #230. If you want to make your own PR, it’s also alright. What do you think?

@t-imamichi - if you are already working on a PR for another fix in the int2bin code, please go ahead and include the fix for this issue in your other PR. Thank you!

1reaction
wpoxon-qcicommented, Aug 18, 2021

@t-imamichi and @atulanand206 - Thank you again for your quick response and for investigating this issue and working on a fix!

@atulanand206 - are you thinking about a fix that looks something like this?

--- .pyenv/versions/3.8.6/lib/python3.8/site-packages/qiskit_optimization/converters/integer_to_binary.py.orig	2021-08-18 19:41:11.327849767 +0000
+++ .pyenv/versions/3.8.6/lib/python3.8/site-packages/qiskit_optimization/converters/integer_to_binary.py	2021-08-18 19:49:45.889513140 +0000
@@ -101,7 +107,10 @@
         self, name: str, lowerbound: float, upperbound: float
     ) -> List[Tuple[str, int]]:
         var_range = upperbound - lowerbound
-        power = int(np.log2(var_range))
+        if var_range:
+            power = int(np.log2(var_range))
+        else:
+            power = 0
         bounded_coef = var_range - (2 ** power - 1)
 
         coeffs = [2 ** i for i in range(power)] + [bounded_coef]

Read more comments on GitHub >

github_iconTop Results From Across the Web

qiskit_optimization encounters an exception when trying to ...
from qiskit_optimization.problems import QuadraticProgram from ... Add or tweak a converter to deal with trivial variables and constraints # ...
Read more >
Lecture notes for CMU's course on Linear Programming ...
First, we can add slack variables for each constraint aix ≥ bi to get equality constraints aix − si = bi. Second,.
Read more >
Cplex Error: Adding trivial infeasible linear constraint
The error messages tells you what happens: you added a constraint that is trivially infeasible, i.e., that can obviously not be satisfied.
Read more >
My Constraint Programming Blog: October 2010 Archives
This was a straight forward conversion from other implementations. The thing that got me confused somewhat was to convert the 1-based MiniZinc ...
Read more >
Automatically Mapping DTO to Entity on Spring Boot APIs
Let's learn how ModelMapper can help us automate the mapping process of DTOs into entities on Spring Boot APIs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found