How can a custom embedding be used with reverse annealing?
Hi all,
This is my first post. Perhaps my question is trivial, but hopefully someone can help.
I am solving a rather complicated but practical engineering optimization problem, that has been cast into a QUBO form. In order for the problem to fit onto the physical QPU hardware, I am finding an embedding using the Minorminer find_embedding function. Thus, using standard forward annealing, the procedure is something like this:
child_sampler = DWaveSampler(endpoint='...',token='...')
__, target_edgelist, target_adjacency = child_sampler.structure
emb = find_embedding(QUBO_dict, target_edgelist, verbose=1)
sampler = FixedEmbeddingComposite(child_sampler, emb)
result = sampler.sample_qubo(QUBO_dict, num_reads = 10, chain_strength = 5, annealing_time = 20)
Now, I am wanting to compare the results of the forward annealing procedure, with the results produced by reverse annealing. Since, for my application I may be able to give a good initial guess. However, here is where I start running into problems. For the reverse annealing I set up:
initial_state = [['q00', 0], ['q01', 1], ['q02', 0], ....etc ]
anneal_schedule = [[0.0, 1.0], [10.0, 0.3], [20.0, 1.0]]
reinitialize_state = False
For the reverse annealing I'm pretty sure I need to use one of the other composites, ReverseBatchStatesComposite or ReverseAdvanceComposite. But, as far as I can tell these do not accept the custom embedding in the same way the FixedEmbeddingComposite does. Therefore, the following code gives me an error:
child_sampler=DWaveSampler(endpoint='...',token='...')
__, target_edgelist, target_adjacency = child_sampler.structure
emb = find_embedding(QUBO_dict,target_edgelist,verbose=1)
sampler = ReverseBatchStatesComposite(child_sampler,emb)
result = sampler.sample_qubo(QUBO_dict, num_reads = 10, chain_strength = 5, initial_state = initial_state, anneal_schedule = anneal_schedule, reinitialize_state = False)
The error being:
... sampler = ReverseBatchStatesComposite(child_sampler, emb)
TypeError: __init__() takes 2 positional arguments but 3 were given
So my question is, how do I correctly set up the reverse annealing procedure, while making use of the embedding found by the minorminer?
Apologies if this is too trivial or has been asked before. I looked around (and also checked the reverse annealing jupyter notebook) but couldn't really find what I was looking for.
Kind regards,
Kevin
Comments
Hello,
If you take a look at the Jupyter Notebook for reverse annealing (01-reverse-annealing.ipynb) under leap/techniques/reverse_annealing, there are examples of how to set them up:
https://cloud.dwavesys.com/leap/learning/
You can see that you would use the same sampler, but just include a few things.
An anneal_schedule parameter will set the reverse anneal schedule.
There are examples of how to calculate the schedule in the notebook.
An initial_state parameter is needed, which can be the result of the forward anneal, or as you have mentioned, you can provide a best first guess if you have it.
The reinitialize_state boolean parameter determines whether you want to reinitialize to the initial_state on each read or use the newly calculated state from the end of the previous anneal.
I hope the Jupyter Notebook is helpful.
It has a lot of great information.
Please let us know if you have more questions or any troubles finding it!
Hi David,
Thanks alot for taking the time to answer my question! I suppose it was a relatively straightforward one after all. I just reused the same FixedEmbeddingComposite, with the additional parameters you mentioned. I also needed to change the initial_state to a dictionary rather than a list for it to work.
Thanks for your help, everything is working as expected now! :)
Hello Kevin,
I am attempting something very similar to what you are doing. I guess the only difference is that I am using sample_ising instead of sample_qubo
The issue I am having is probably with the way I am passing the initial_state. You mentioned that you are using a dictionary rather than a list. Are you using the ocean tools? It mentions here that for ocean tools a list should be passed:
https://docs.dwavesys.com/docs/latest/c_solver_parameters.html#initial-state
Is it possible to show a snippet of the way you made it work?
Okay so I found the issue I was running into.
The embedding I was using was for a larger problem, but still valid for the particular problem I was using.
The extra variables in the embedding kept throwing an error. The fix was to get rid of those extra variables by either editing the embedding or generating a new embedding.
Please sign in to leave a comment.