# Optimization using Quantum Logics

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?

• Are you sure you want linear polynomial here? Not even quadratic $x1^2$, $x2^2$ or $x1*x2$ terms? Aug 26, 2020 at 21:51
• 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? Aug 27, 2020 at 7:27

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.aqua.algorithms import QAOA
from qiskit.optimization.algorithms import MinimumEigenOptimizer

# construct optimization problem
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.