Troubleshoot large Ising model graph in python

First post,  I have followed the tutorials and docs.  I have been able to embed a simple real-world problem that I'm interested in, the problem intuitively works as an Ising model, so I've used this to embed my problem.

  It works very well in the simulator and I was impressed to find that simpler experiments embed into 2048 qubits reliably in minorminer, so I tried the problem on a DWave, the results are much noisier than the simulator. :-(  I have tried to play with anneal time, chain strength, and number of reads,  the results vary a bit, but there isn't a clear trend, it feels like I've missed something.  I have max chain lengths in the minor embedding that are 16 long,  is it unreasonable to expect such a large graph to be error free? Could I run minorminer in a more aggressive mode to try to reduce the embedding graph?  Or have I missed something else? 

Is there a resource on how to go about troubleshooting?  I found this troubleshooting post, but I can't work out how use anneal_offset to schedule  the anneal of longer chains. 

Thanks in advance

0

Comments

6 comments
  • update:  OK, still working towards an understanding.  Thanks for your patience.

    I would like to supply an embedding for a problem that I have created using minorminer.  The output of minorminer is a dict that should represent the embedding (?) but this doesn't seem to go into FixedEmbeddingComposite directly (?)  I get an error:

    dwave.embedding.exceptions.MissingChainError: chain for 1392 is empty or not contained in this embedding

    If I take my results and try 'embed' them again:

    c_struct = dnx.chimera_graph(16, 16)
    e_graph = load_embedding("./minorminer_output.pickle")
    embed = dwave.embedding.embed_ising(h, J, e_graph, c_struct)
    sampler = FixedEmbeddingComposite(DWaveSampler(), e_graph)

    I get the following error:

    TypeError: unhashable type: 'dict'

    I might be creating bad graphs in minorminer or I might not understand what I'm doing (or both)...  Any clues?

    0
    Comment actions Permalink
  • Hello,

    I just wanted to mention that an embedding is created for a specific problem, so if you change the problem, then the embedding will no longer be valid.

    For your error, it's not exactly clear which line is causing the error. 

    There is a lot of stuff going on in this code example, so it is hard to tell what exactly is happening.

    It looks like this has something more to do with pickling?

    Maybe a minimal example, or something a bit more complete would help?

    Either way, I would suggest taking a look at this community post that shows an example of using the FixedEmbeddingComposite:
    https://support.dwavesys.com/hc/en-us/community/posts/360029545074

    Also, check this one out that talks about using different embedding methods and the BQM (which is basically just another way to represent both ising and qubo problems conveniently in a single form):
    https://support.dwavesys.com/hc/en-us/community/posts/360016737274

    0
    Comment actions Permalink
  • Hi,

      Thanks for your help, the links that you suggested.  They are similar to what I'm trying to do, although my problem is using Ising models.  The remaining problem is how to put the output of findembedding into a form that suits the FixedEmbeddingComposite input.

    I've created a simpler self contained problem, as follows

    0
    Comment actions Permalink

  • import dwave_networkx as dnx
    import networkx as nx
    import minorminer
    from dwave.embedding import embed_ising
    from dwave.system.samplers import DWaveSampler
    from dwave.system.composites import FixedEmbeddingComposite

    def get_J_and_h():
    #based on https://docs.ocean.dwavesys.com/projects/system/en/latest/reference/generated/dwave.embedding.embed_ising.html
    h = {'a': 0, 'b': 0, 'c': 0}
    J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
    return J,h

    J,h = get_J_and_h(1,2)
    connectivity_structure = dnx.chimera_graph(16, 16)
    best_max_length = 1000 # arbitrary 'big' number
    n =0
    while n < 10:
    n+=1
    print("iter {:03d} Trying to fit model into 16x16 chimera graph...".format(n), end=' ')
    #embedded_graph = minorminer.find_embedding(G.edges(), connectivity_structure.edges(), return_overlap=1)
    embedded_graph = minorminer.find_embedding(set(J).union((v,v,) for v in h), connectivity_structure.edges(), return_overlap=1)
    print("complete")
    max_chain_length = 0
    for _, chain in embedded_graph[0].items():
    if len(chain) > max_chain_length:
    max_chain_length = len(chain)
    if ((best_max_length > max_chain_length) and max_chain_length > 0) and embedded_graph[1]:
    best_graph = embedded_graph[0]
    best_max_length = max_chain_length
    print("new max chain lenght: "+ str(max_chain_length))

    embed = embed_ising(h, J, best_graph, nx.Graph(connectivity_structure))
    print(embed)
    sampler = FixedEmbeddingComposite(DWaveSampler(), embed)
    th = embed[0]
    tJ = embed[1]
    response = sampler.sample_ising(th, tJ, chain_strength=1, annealing_time=50, num_reads=10)
    0
    Comment actions Permalink
  • Hello,

    So the code is not quite formatted right (there are some indentation errors).

    That said, I think I was able to tweak it a bit and get it to function how you had intended.

    There are a few minor problems.

    The main issue is that you are using an idealized 16x16 unit cell Chimera graph, when in actual practice, some of these qubits will not be functional, so they can not be embedded to.

    The best way to fix this is to use the actual architecture of the solver you are going to use.

    You can do this by running the find embedding function like this:

    solver = DWaveSampler()
    embedding = minorminer.find_embedding(set(J).union((v,v,) for v in h), solver.edgelist, return_overlap=1)

    You can see here that we just got the list of edges of the solver itself.

    Later we can add the solver to the FixedEmbeddingComposite like this:

    sampler = FixedEmbeddingComposite(solver, embedding)

    Now at this point, there is another issue.

    In the previous line you are running the embed_ising function.

    What this does is actually embed the problem into the graph, which is what the FixedEmbeddingComposite is doing.

    So you don't need to actually run the embed_ising function, because the FixedEmbeddingComposite will do this, run the solver, and then run the unembed_ising function as well!

    So putting it all together you would use something like this:

    solver = DWaveSampler()
    embedding = minorminer.find_embedding(set(J).union((v,v,) for v in h), solver.edgelist)
    sampler = FixedEmbeddingComposite(solver, embedding)
    response = sampler.sample_ising(h, J, chain_strength=1, annealing_time=50, num_reads=10)

    I hope this is helpful.
    Please let us know if you need any more information or have any more questions.

    0
    Comment actions Permalink
  • Hi,

      Yes, this answered my questions perfectly.  Thanks for your help and for picking through my example.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post