entropicalabs / openqaoa

Multi-backend SDK for quantum optimisation
MIT License
113 stars 59 forks source link

Expose brute force solver through OpenQAOA workflows #234

Closed vishal-ph closed 1 year ago

vishal-ph commented 1 year ago

Prerequisites

Before raising this feature request, I made sure:

Is your feature request related to a problem? Please describe.

OpenQAOA has a function called ground_state_hamiltonian that takes as input the Cost Hamiltonian corresponding to the QUBO problem and outputs the degenerate solutions (or ground states of the Hamiltonian) along with the lowest energy (i.e. ground state energy). The function is defined in src/openqaoa-core/openqaoa/utilities.py.

Expose this function as a QAOA workflow class method so users can easily access it.

Describe the solution you'd like

Ideal workflow

  1. q = QAOA()
  2. q.compile(qubo)
  3. q.solve_brute_force()

Describe alternatives you've considered

The existing way to obtain the brute force solution of a qubo is described as follows:

  1. construct the problem qubo
  2. `from openqaoa.utilities import ground_state_hamiltonian
  3. Construct the hamiltonian object by calling prob_hamiltonian = qubo.hamiltonian
  4. Obtain the solution solution, energy = ground_state_hamiltonian(prob_hamiltonian)
lumapools commented 1 year ago

Hi, I have attempted to implement the brute_force method as well as added some unit tests, could you please assign me to this issue?

vishal-ph commented 1 year ago

@lumapools, just did! Thanks

lumapools commented 1 year ago

Thank you! Just created the PR with the feature and new tests to be added

Q-lds commented 1 year ago

We currently have 2 PRs addressing this issue:

What I'd propose is to merge the two PRs and share the bounty. I like the implementation of the function from @GiacomoFrn , and @lumapools nicely added some tests. So, maybe we can take the solution from 239 and then add the (updated) tests from 240. What do you guys say? Could this be a fair solution? :)

GiacomoFrn commented 1 year ago

Seems a fair solution to me! It was my first open source contribution and I didn't know I was supposed to add tests, @lumapools instead did it.

lumapools commented 1 year ago

I think it is a good idea too! How should we go about merging ? Should we first merge @GiacomoFrn 's PR and then I modify my PR (or close it to create a new one) to only include the (new) tests for @GiacomoFrn 's code ?

Q-lds commented 1 year ago

Perfect!

@vishal-ph I think we follow @lumapools suggestion. What do you think?

vishal-ph commented 1 year ago

thanks @lumapools, @GiacomoFrn for contributing to OpenQAOA and helping solve this issue!

GiacomoFrn commented 1 year ago

@vishal-ph , @Q-lds I believe I also should be assigned to the issue in order to follow the regulation of the unitaryHack and get part of the bounty

Q-lds commented 1 year ago

@GiacomoFrn I have added you as well. Hope this fixes it! :)