2
$\begingroup$

Is it possible to solve the following kind of optimization using Quantum Computing?

Minimize
5*x1 - 7*x2

binary
x1
x2

If yes, is it possible to have a sample code using QISKit?

$\endgroup$
2
  • $\begingroup$ Are you sure you want linear polynomial here? Not even quadratic $x1^2$, $x2^2$ or $x1*x2$ terms? $\endgroup$
    – AHusain
    Commented Aug 26, 2020 at 21:51
  • $\begingroup$ Well as a beginner, I'm trying to learn to solve simple linear problems. Next, with multiple constraints, then non-linear and so on... Shall I include them in this question? $\endgroup$
    – Dr.PB
    Commented Aug 27, 2020 at 7:27

1 Answer 1

3
$\begingroup$

Qiskit has an optimization module and you can find tutorials that illustrate its functionality here.

To solve the example you posted, e.g., with the Quantum Approximate Optimization Algorithm (QAOA), you can do the following:

from qiskit import Aer
from qiskit.optimization import QuadraticProgram
from qiskit.aqua.algorithms import QAOA
from qiskit.optimization.algorithms import MinimumEigenOptimizer

# construct optimization problem
qp = QuadraticProgram()
qp.binary_var('x1')
qp.binary_var('x2')
qp.minimize(linear=[5, -7])

# initialize optimizer
qaoa_mes = QAOA(quantum_instance=Aer.get_backend('statevector_simulator'))
qaoa = MinimumEigenOptimizer(qaoa_mes)

# solve problem
result = qaoa.solve(qp)
print(result)

which prints:

optimal function value: -7.0
optimal value: [0. 1.]
status: SUCCESS

Qiskit's optimization module also provides other quantum optimization algorithms for quadratic programs and you can find a more detailed description here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.