Save time! Reuse your embedding when possible
Recall that both EmbeddingComposite and FixedEmbeddingComposite (from `dwave.system.composites`) act as a map between your source problem (Ising/QUBO) and its minor embedding on the QPU. It takes time and effort to make this mapping.
A sampler created with EmbeddingComposite will call for a new mapping each time the `sample` method is used. A sampler created with FixedEmbeddingComposite will get initialized with a mapping once, and will use that same mapping each time the `sample` method is called.
Your choice of embedding composite should depend on your use case:
- If you're only going to call the `sample` method once, then it is useless to cache the embedding -> use Embedding Composite.
- If you have multiple BQMs (think: energy/optimization function) that can all be represented by the same embedding (think: graph), then it is useful to store the embedding -> use Fixed Embedding Composite.
Fixed Embedding Composite is particularly worthwhile when you are re-sampling a large and complicated embedding.
Below is a simple demo showing how two different BQMs with three variables (a, b, and c) can be sampled. One version of the sampler is done with Embedding Composite, while the other is done with Fixed Embedding Composite. (Note: The initial embedding for FixedEmbeddingComposite does not have to be made by hand. Instead, it can be made with minorminer, a tool used for finding minor embeddings.)
import dwavebinarycsp as dbc
import dwavebinarycsp.factories.constraint.gates as gates
from dwave.system.composites import FixedEmbeddingComposite, EmbeddingComposite
from dwave.system.samplers import DWaveSampler
# Making two different BQMs (think: energy functions or optimization functions)
csp1 = dbc.ConstraintSatisfactionProblem(dbc.BINARY)
csp1.add_constraint(gates.and_gate(['a','b','c']))
bqm1 = dbc.stitch(csp1)
csp2 = dbc.ConstraintSatisfactionProblem(dbc.BINARY)
csp2.add_constraint(gates.or_gate(['a','b','c']))
bqm2 = dbc.stitch(csp2)
# Using Embedding Composite
sampler = EmbeddingComposite(DWaveSampler())
sampler.sample(bqm1) # Gets a new embedding for bqm1
sampler.sample(bqm2) # Gets a new embedding for bqm2
# Using Fixed Embedding Composite
# Note: bqm1 and bqm2 can both be represented by the same graph - triangle graph.
embedding = {'a':[0,4],'b':[1],'c':[5]} # Embedding the triangle graph using QPU indices
fixedSampler = FixedEmbeddingComposite(DWaveSampler(), embedding)
fixedSampler.sample(bqm1)
fixedSampler.sample(bqm2) # in both samples, the SAME embedding gets used
Comments
Please sign in to leave a comment.