QUBO embedding and Solver


I'm trying to solve a Sudoku problem using QA. I reduced it to a QUBO problem and now I'm trying to implement it on the Hardware Solver.

I found this piece of code from 2014 to implement the exact same QUBO. Obviously, the SAPI was very different back then and most methods do not exist anymore or at least under a different name. Could you help me to translate the code, so it fits the current API and Hardware version? Are there any other possibilities to solve the QUBO problem?


from dwave_sapi import RemoteConnection , get_hardware_adjacency , find_embedding , EmbeddingSolver


def embed(self , qubo_problem , size):
      A = get_hardware_adjacency(self.solver)
      A_size = self.solver.properties['num_qubits ']
      return find_embedding(qubo_problem , size , A, A_size ,verbose =1, tries =10, max_no_improvement =10)

def solve(self , qubo_problem , embeddings):
      embedding_solver = EmbeddingSolver(self.solver , embeddings)
      return embedding_solver.solve_qubo(qubo_problem , num_reads =1000)



1 comment
  • Hi Niklas,

    Here is an example of how to use the FixedEmbeddingComposite, which does the same thing:

    from dwave.system.samplers import DWaveSampler
    from dwave.system.composites import FixedEmbeddingComposite
    from minorminer import find_embedding

    solver = DWaveSampler()

    Q = {('x1', 'x2'): 2, ('x1', 'z'): -2}

    __, target_edgelist, target_adjacency = solver.structure

    emb = find_embedding(Q, target_edgelist, verbose=1)

    sampler = FixedEmbeddingComposite(solver, emb)

    result = sampler.sample_qubo(Q, num_reads=100)

    I hope this is helpful!

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post