embed_problem, solve_ising and unembed_answer
Hi,
embed_problem, solve_ising and unembed_answer were all API's available from dwave_sapi2 which is not available.
I have code that looks like this
-------------------------------------------------------------------------------------------------------------
from minorminer import find_embedding
embeddings = find_embedding(S, A, verbose=1)
from dwave_sapi2.embedding import embed_problem
(h0, j0, jc, new_emb) = embed_problem(h, J, embeddings, A, clean=True, smear=True)
s = 1
h0 = [s*i for i in h0]
j_emb = jc.copy()
for x,y in j0:
j_emb[(x,y)] = s*j0[(x,y)]
from dwave_sapi2.core import solve_ising
result = solve_ising(solver_c16, h0, j_emb, num_reads=1000,annealing_time=1000)
from dwave_sapi2.embedding import unembed_answer
configs = unembed_answer(result['solutions'], new_emb, 'minimize_energy', h, J)
--------------------------------------------------------------------------------------------------------------------
As you can see I am trying to experiment with embeddings.
Is there a way to rewrite the above piece of code in the new scheme of things?
I know there is a way to specify manual minor embedding to DWaveSampler as per the example given in Section 8.1.1 of 09-1076A-"Getting started with the DWave System" document.
But that's too cumbersome to do for larger size of the problems. The way I do it as in the above code is more preferable.
Manoj
Comments
Is the minorminer library the sort of thing you are looking for?
https://docs.ocean.dwavesys.com/projects/minorminer/en/latest/
It will do embeddings, and also let you provide hints and constraints for those embeddings.
I understand that part.
But it won't let me do what I was doing earlier - making specific manipulations(please correct me if I am wrong)
So that is why I am looking for alternatives on ''embed_problem, solve_ising and unembed_answer" which were available in dwave_sapi2.
Hello Manoj,
I take it from your description that you would like to create embeddings and sample the QPU in separate steps, so that you can save and analyze the most effective embeddings. For this case I would recommend find_embedding and FixedEmbeddingComposite. These are both in the Ocean tool suite.
Take a look at Alex's code snippet on this community post about embedding. You can use find_embedding to create embeddings with optional parameters as arguments, and in the next step use FixedEmbeddingComposite to create a sampler with the provided embedding built-in. That way you can store the best embeddings and pick them apart after seeing the results.
Hi Luca,
I just looked at Alex's code snippet.
But I am not clear how to get the h and J values used in the physical embedding on the target QPU.
I think find_embedding returns for every logical qubit - the set of physical qubits it is mapped to. But not the h and J values.
Is it possible to get/set the h and J values in physical embedding?
Hi Manoj,
Thanks for the clarification, I believe I understand your use case better now. Please see the following tools in dimod:
Let me know if these provide the functionality you are looking for.
Hi Luca,
Here is what my new code looks now
---------------------------------------------------------------------------------------
#Q initialized earliear as per problem requirement. Was happening in the previous code as well in the same way.
from dimod.utilities import qubo_to_ising
from dimod import BinaryQuadraticModel
(h, J, ising_offset) = qubo_to_ising(Q) # this line is same as in previous code
bqm = BinaryQuadraticModel.from_qubo(Q)
from minorminer import find_embedding
embeddings = find_embedding(S, A, verbose=1)
from dimod import embed_ising
h0, j0 = embed_ising(h, J, embeddings, AD)
s = 1
h0 = [s*i for i in h0]
j_emb = jc.copy()
for x,y in j0:
j_emb[(x,y)] = s*j0[(x,y)]
result = sampler.sample_ising(h0, j_emb, num_reads=1000,annealing_time=200,answer_mode='histogram')
from dimod import unembed_response
configs = unembed_response(result, embeddings, bqm)
---------------------------------------------------------------------------------------------------
Thanks very much.
Manoj
No problem Manoj, happy to help.
Please sign in to leave a comment.