from qiskit_optimization import QuadraticProgram
from qiskit_optimization.converters import QuadraticProgramToQubo
from dwave.system import DWaveSampler, EmbeddingComposite
import dimod
import dwave.inspector

# select quadratic program to solve
qp = QuadraticProgram()
qp.read_from_lp_file("example.lp")
qubo = QuadraticProgramToQubo().convert(qp)
bqm_binary = dimod.as_bqm(qubo.objective.linear.to_array(), qubo.objective.quadratic.to_array(), dimod.BINARY)
print(qp)
print(bqm_binary)
bqm_ising = bqm_binary.to_ising()
print("Ising Model form coefficients:")
print(bqm_ising)

sampler = EmbeddingComposite(DWaveSampler())
res = sampler.sample(bqm_binary, label="example_qubo_3_1024", num_reads=1024)
res.to_pandas_dataframe()

dwave.inspector.show(res) # this is a good looking one

