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
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.Sign up to join this community
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)
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.