I have a non-convex QUBO problem that I'd like to solve by warm-starting QAOA with a solution obtained from a continuous relaxation solution obtained by a classical algorithm. The specifics of the problem is shown below in the code.
I have 2 questions:
- In the code below is CPLEX able to solve the original QUBO. However, when I use CPLEX as input to the WarmStartQAOA optimization in QisKit, it tells me it cannot solve because the problem is non-convex?
- For non-convex problems, there must be an easy reformulation that QisKit and WarmStartQAOA can do on its own since most problems are non-convex. Can someone help me find that functionality in QisKit?
import random
random.seed(0)
def invert_counts(counts):
return {k[::-1]:v for k, v in counts.items()}
qp = QuadraticProgram()
p = 1
m = 4
n = 4
for i in range(m):
for j in range(n):
qp.binary_var("x_{}_{}".format(i,j))
qp.quadratic_dict={}
for i in range(m):
for p in range(n):
for i_2 in range(m):
for p_2 in range(n):
qp.quadratic_dict[("x_{}_{}".format(i,p), "x_{}_{}".format(i_2, p_2))] = 0
for i in range(m):
for p in range(n):
x_i_p = "x_{}_{}".format(i,p)
curr_entry = qp.quadratic_dict[(x_i_p, x_i_p)]
qp.quadratic_dict[(x_i_p, x_i_p)]= curr_entry - 40
qp.minimize(quadratic=qp.quadratic_dict)
def relax_problem(problem) -> QuadraticProgram:
"""Change all variables to continuous."""
relaxed_problem = copy.deepcopy(problem)
for variable in relaxed_problem.variables:
variable.vartype = VarType.CONTINUOUS
return relaxed_problem
sol = CplexOptimizer().solve(qp)
print(sol.prettyprint())
qaoa_mes = QAOA(sampler=Sampler(), optimizer=COBYLA())
ws_qaoa = WarmStartQAOAOptimizer(
pre_solver=CplexOptimizer(), relax_for_pre_solver=True, qaoa=qaoa_mes, epsilon=0.0)
ws_result = ws_qaoa.solve(qp)
print(ws_result.prettyprint())
```