Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading a MinimumEigensolverResult directly into the MinimumEigenOptimizer #325

Open
Cryoris opened this issue Feb 3, 2022 · 4 comments
Labels
type: feature request New feature or request

Comments

@Cryoris
Copy link
Contributor

Cryoris commented Feb 3, 2022

What should we add?

The MinimumEigenOptimizer internally calls a minimum eigensolver and then postprocesses the obtained MinimumEigensolverResult in the context of the quadratic program that we try to solve. It would be great if we could directly pass in a MinimumEigensolverResult into this postprocessing part if we have it already, like:

optimization_result = MinimumEigenOptimizer.process_result(minimum_eigensolver_result, quadratic_program)

This would be particularly useful in context of the QAOA and VQE runtimes as jobs can get stuck locally but we can easily get the result back from the job ID on the quantum experience (see also qiskit-community/qiskit-nature#479). With the feature here we could then have a workflow like

job_id = # my job ID from the quantum experience
vqe_result = VQEClient.retrieve_result(provider, job_id)
opt_result = MinimumEigenOptimizer.process_result(vqe_result, quadratic_program)

Names or function calls here are just suggestions 🙂

The implementation should be rather straightforward since we could restructure MinimumEigenOptimizer.solve to something like

def solve(self, problem):
    # same conversions as now
    problem_ = self._convert(problem, self._converters)
    operator, offset = problem_.to_ising()
        
    # just run MES, no interpretation 
    mes_result = self._solve_mes(operator, offset, problem_, problem)
        
    # interpretation in a separate function
    result = self.process_result(problem)
@Cryoris Cryoris added the type: feature request New feature or request label Feb 3, 2022
@woodsp-ibm
Copy link
Member

This would be particularly useful in context of the QAOA and VQE runtimes as jobs can get stuck locally

This makes it sounds as this happens more frequently than one might like. Hopefully the root cause of that gets looked at too so as to improve things in that regard. However...

Does passing in some result there become stateful on the MEO? I assume you need the same class (or another later instantiated the same way) in order to interpret the result correctly in the context of the original problem; otherwise the result may not make sense. Maybe that's left to the user who somehow needs/wants to interpret a result.

@Cryoris
Copy link
Contributor Author

Cryoris commented Feb 7, 2022

This makes it sounds as this happens more frequently than one might like. Hopefully the root cause of that gets looked at too so as to improve things in that regard. However...

I didn't experience this myself lately (it's coming from another user) so at least for me it doesn't happen often 🙂

Does passing in some result there become stateful on the MEO?

It definitely shouldn't become stateful, that's why the pseudo-code above passes the original quadratic program into the MEO along with the minimum eigensolver result. That should be all the information required to reconstruct the result I think -- but I might be missing something! 😄

@t-imamichi
Copy link
Collaborator

t-imamichi commented Feb 8, 2022

Thank you for the proposal. It would be nice if users easily interpret VQEClient result.
Before applying converter.interpret(result) to a result, we need to convert a problem by converter.convert(problem) so that converter keeps information of the problem.
Moreover, solve method interprets not only the best solution but also all solution samples.
So, restructuring might be a bit complicated. But, it's worthwhile.

Perhaps, it might be useful to separate to_ising part as well as the interpretation (preprocessing of the following example)? What do you think from VQEclient perspective, @Cryoris?

def prepare_operator(self, problem)
    problem_ = self._convert(problem, self._converters)
    operator, offset = problem_.to_ising()
    return operator, offset

def process_result(self, mes_result, problem=None)
    if problem:
        # if users interpret results of `VQEClient`, they need to set the problem.
        _ = self._convert(problem, self._converters)
    samples, best_sol = self._interpret_samples(problem, mes_result)
    return self._interpret(best_sol, samples)

def solve(self, problem):
    # generate Ising Hamiltonian
    operator, offset = self.prepare_operator(problem)
        
    # just run MES, no interpretation 
    mes_result = self._solve_mes(operator, offset, problem_, problem)
        
    # interpretation in a separate function
    result = self.process_result(mes_result)

@Cryoris
Copy link
Contributor Author

Cryoris commented Feb 8, 2022

Yeah that looks good! We'd have to add a check to process_result that makes sure the problem is passed when it is required but other than that I think this implements what we'd like to do 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants