entropicalabs / openqaoa

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

UF: adding the SK problem #258

Closed alejomonbar closed 12 months ago

alejomonbar commented 1 year ago

Unitary Fund

Adding the Sherrington–Kirkpatrick (SK) problem class with its corresponding test. https://en.wikipedia.org/wiki/Spin_glass

Description

This pull request adds support for the SK problem, an optimization problem related to spin glass. The SK problem involves finding the minimum energy Hamiltonian based on the interaction between spins.

The implementation includes a new class SK in the problem module. The SK class allows the creation of instances of the SK problem. It provides methods for solving the problem using the Docplex solver, visualizing the graph with a given solution, and obtaining the qubo.

Example:

from openqaoa.problems import SK
import matplotlib.pyplot as plt
from openqaoa import QAOA

sk = SK.random_instance(n_nodes=5)
sol = sk.classical_solution()

qaoa = QAOA()
qaoa.compile(sk.qubo)
qaoa.optimize()

sol_qaoa = qaoa.result.lowest_cost_bitstrings()["solutions_bitstrings"][0]

fig, ax = plt.subplots(1, 2, figsize = (10, 5))
sk.plot_solution(sol_qaoa, ax=ax[0])
ax[0].set_title("QAOA Results")
sk.plot_solution(sol, ax=ax[1])
ax[1].set_title("CPLEX Results")
Screenshot 2023-08-16 at 3 00 18 PM

Checklist

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

the test is inside './tests/test_sk.py' and './tests/test_qubo.py'