Embedding Ising

I'm currently working on implementing the algorithm discussed in the following paper:


I'm confused with how to code equation (12) in appendix B.

Is there a general way to implement it for any set of qubits? 



  • Hi Ramy,

    Apologies for the delayed response!

    Instead of manually embedding your problem onto the QPU as described in the paper, you can use one of the tools available in the Ocean SDK to automatically embed it. Here is a good community post that goes over different embedding composites you can use depending on the structure of your problem: https://support.dwavesys.com/hc/en-us/community/posts/1500000022701-What-is-the-difference-between-different-embedding-composites-.

    For large problems, it is recommended that you reuse the embedding. So, you start by finding the embedding using find_embedding or find_clique_embedding and then use FixedEmbeddingComposite to pass the same mapping each time.

    Here is a small code example on how to do this using find_embedding:

    from dwave.system import DWaveSampler, FixedEmbeddingComposite
    from minorminer import find_embedding

    J = {('A','B'): -0.5, 
        ('B','C'): -0.5, 
        ('A','C'): 0.5} 

    solver = DWaveSampler(solver={'topology__type': 'pegasus'})
    __, target_edgelist, target_adjacency = solver.structure

    embedding = find_embedding(J, target_edgelist, verbose=1)
    # {'A': [2198], 'B': [2213], 'C': [4496]}

    sampler = FixedEmbeddingComposite(solver, embedding)

    sampleset = sampler.sample_ising({},J, num_reads = 10)

    If you are working with a fully connected problem, you might want to use DWaveCliqueSampler() instead of DWaveSampler. This sampler wraps find_clique_embedding which generates a fully-connected embedding with even chain length.

    Also, here is a detailed article if you want to learn more about minor-embedding: https://docs.dwavesys.com/docs/latest/handbook_embedding.html

    Comment actions Permalink
  • Hi Tanvi M,

    Thank you for the explanation!

    I've tried using FixedEmbeddingComposite with DwaveCliqueSampler with the embedding returned by find_clique_embedding as follows:


    dwave_sampler=DWaveCliqueSampler( solver={'topology__type': 'chimera'})
    embedding = find_clique_embedding(2, 1, 1)
    sampler = FixedEmbeddingComposite(dwave_sampler,embedding=embedding)

    but I get this error: 

    ValueError: no structured sampler found

    Do you have any idea how to fix this?


    Comment actions Permalink
  • Hello,

    In your code example, you are using two methods that both do the same thing. 
    You can either use the DWaveCliqueSampler, or use the FixedEmbeddingComposite with the find_clique_embedding function.

    The DWaveCliqueSampler deals with the embedding part automatically, so you just need to provide it with a BQM.

    If you use the return_embedding=True parameter, the sample function will return the embedding in the sampleset variable in the code example below:

    sampler = DWaveCliqueSampler()
    sampleset = sampler.sample(bqm, return_embedding=True)

    The FixedEmbeddingComposite can be used with an embedding, so you would do something similar to what you have above, finding the embedding and then providing it to the FixedEmbeddingComposite. The first parameter that you have provided should be an instance of the DWaveSampler.

    embedding = find_clique_embedding(2, 1, 1)
    sampler = FixedEmbeddingComposite(DWaveSampler(), embedding=embedding)

    You can also use the embedding returned by the sample function call when using the DWaveCliqueSampler.

    Hopefully this helps you move forward with development. 
    Please let us know if you have any further questions.

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post