self._verify_compatibility(problem)
// convert problem to QUBO
qubo_converter = QuadraticProgramToQubo()
problem_ = qubo_converter.encode(problem)
// construct operator and offset
operator_converter = QuadraticProgramToIsing()
After Change
self._verify_compatibility(problem)
// convert problem to QUBO
problem_ = self._qubo_converter.convert(problem)
// construct operator and offset
operator, offset = problem_.to_ising()
// only try to solve non-empty Ising Hamiltonians
x = None // type: Optional[Any]
if operator.num_qubits > 0:
// approximate ground state of operator using min eigen solver
eigen_results = self._min_eigen_solver.compute_minimum_eigenvalue(operator)
// analyze results
// backend = getattr(self._min_eigen_solver, "quantum_instance", None)
samples = _eigenvector_to_solutions(eigen_results.eigenstate, problem_)
// print(offset, samples)
// samples = [(res[0], problem_.objective.sense.value * (res[1] + offset), res[2])
// for res in samples]
samples.sort(key=lambda x: problem_.objective.sense.value * x[1])
x = samples[0][0]
fval = samples[0][1]
// if Hamiltonian is empty, then the objective function is constant to the offset
else:
x = [0]*problem_.get_num_binary_vars()
fval = offset
x_str = "0"*problem_.get_num_binary_vars()
samples = [(x_str, offset, 1.0)]
// translate result back to integers
opt_res = MinimumEigenOptimizerResult(x=x, fval=fval, samples=samples,
results={"qubo_converter": copy.deepcopy(
self._qubo_converter)},
variables=problem.variables)
opt_res = cast(MinimumEigenOptimizerResult, self._qubo_converter.interpret(opt_res))
// translate results back to original problem
return opt_res