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.

MinimumEigenOptimizer returns a wrong solution

See original GitHub issue

Information

  • Qiskit Optimization version: latest
  • Python version: 3.8.9
  • Operating system: macOS 11.2.3

What is the current behavior?

MinimumEigenOptimizer with qasm_simulator returns a wrong solution.

Steps to reproduce the problem

from docplex.mp.model import Model
mdl = Model("docplex model")
x = mdl.binary_var('x')
y = mdl.binary_var('y')
mdl.minimize(x-2*y)
print(mdl.export_as_lp_string())
result = mdl.solve()
print("result of CPLEX solver")
print(result)

from qiskit_optimization import QuadraticProgram
from qiskit.providers.aer import QasmSimulator
from qiskit.algorithms.optimizers import SPSA
from qiskit.circuit.library import TwoLocal
from qiskit.utils import QuantumInstance
from qiskit.algorithms import VQE
from qiskit_optimization.algorithms import MinimumEigenOptimizer
seed = 1234
qp = QuadraticProgram()
qp.from_docplex(mdl)
backend = QasmSimulator()
optimizer = SPSA(maxiter=100)
ry = TwoLocal(2, 'ry', 'cz', reps=3, entanglement='full')
quantum_instance = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
vqe_mes = VQE(ry, optimizer=optimizer, quantum_instance=quantum_instance)
vqe = MinimumEigenOptimizer(vqe_mes)
result = vqe.solve(qp)
print("result of VQE solver")
print(result)
print(result.raw_samples)

output:

\ This file has been generated by DOcplex
\ ENCODING=ISO-8859-1
\Problem name: docplex model

Minimize
 obj: x - 2 y
Subject To

Bounds
 0 <= x <= 1
 0 <= y <= 1

Binaries
 x y
End

result of CPLEX solver
solution for: docplex model
objective: -2
y=1

result of VQE solver
optimal function value: 1.0
optimal value: [1. 0.]
status: SUCCESS

What is the expected behavior?

The solution of VQE should be [0. 1.].

Suggested solutions

We may need to reverse the bitstrings as x = np.fromiter(list(bitstr[::-1]), dtype=int). But, it may affect other algorithms and unit tests. https://github.com/Qiskit/qiskit-optimization/blob/54a6d0750492132aa019975e3a8648c507b7553c/qiskit_optimization/algorithms/optimization_algorithm.py#L511

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Cryoriscommented, May 12, 2021

Ok 👍🏻 yeah let’s revisit the ordering in another issue, I’m not sure I fully understood where which order is assumed 😉 Thanks for the clarifications!

1reaction
a-matsuocommented, May 7, 2021

@Cryoris Sure. Let me check reversing the Hamiltonian order works correctly as I expect. I will work on it next week. @t-imamichi Ya, we need to clarify the order of Hamiltonian in docstrings if we change it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

qiskit.optimization.algorithms.minimum_eigen_optimizer
Returns : The list of raw solution samples of ``MinimumEigensolver``. ... from qiskit.optimization.algorithms import MinimumEigenOptimizer ...
Read more >
Traveling salesman problem in Qiskit: cannot find a solution ...
ising library, the returned solution is 0→2→3→1→0 with distance 873. But according to matrix D, the total distance should be 731. I can ......
Read more >
Circuit Sessions with Stefan Woerner - Qiskit - YouTube
An error occurred while retrieving sharing information. Please try again later. 0:00. 0:00 / 1:00:08•Watch full video
Read more >
Solving Optimization Problems With A Quantum Computer Is ...
Moreover, you must collect all the solution parts and put them back ... We create a corresponding optimizer ( MinimumEigenOptimizer ) and ...
Read more >
Solving QUBOs with qiskit QAOA example
We finally return the solution vector x and the f-value, ... import MinimumEigenOptimizer from qiskit.aqua import aqua_globals, ...
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