Allow sampling by id from DWaveSampler, LeapHybridSampler, LeapHybridDQMSampler
We could either accept ids in the .sample method,
sampleset = LeapHybridSampler().sample(id_)
or be more explicit
sampleset = LeapHybridSampler().sample_id(id_)
My preference is for the latter, since the former might lead users to do things like
sampleset = EmbeddingComposite(DWaveSampler()).sample(id_)
which isn't well defined.
This can be done currently via the cloud-client interface. Something like
import dimod
from dwave.system import LeapHybridSampler
sampler = LeapHybridSampler()
bqm = dimod.BQM('SPIN')
kwargs = dict(time_limit=sampler.min_time_limit(bqm))
bqm_id = sampler.solver.upload_bqm(bqm.to_file()).result()
ss1 = sampler.solver.sample_bqm(bqm_id, **kwargs).sampleset
ss2 = sampler.solver.sample_bqm(bqm_id, **kwargs).sampleset
print(ss1)
print(ss2)
edit: this was fixed based on @randomir 's comments below
Actually, we first need to implement #398, i.e. https://github.com/dwavesystems/dwave-cloud-client/issues/466.
I am not sure I understand, the snippet I provided works for me for both BQM and CQM, I haven't tested for the QPU.
Agree that the bigger feature needs work in several places.
I'm not sure how it can work, because id_ refers to problem id (i.e. "job id"), and sample_cqm requires uploaded problem id (a.k.a bqm_id).
Because I didn't actually resolve to see the error :flushed: , my mistake. I'll fix and update, one sec
Ok, updated the comment, thanks @randomir
Or if you realize you want to re-submit a hybrid problem long after the initial sampling, you can do:
# get problem id, either from Leap Dashboard, or your previous sampling
problem_id = '...'
# or: problem_id = sampleset.info['problem_id']
# or: problem_id = sampleset.wait_id()
# get problem info
from dwave.cloud.api import Problems
problems = Problems.from_config()
info = problems.get_problem_info(problem_id)
# initialize the relevant solver, e.g. CQM
from dwave.system import LeapHybridCQMSampler
sampler = LeapHybridCQMSampler()
# re-submit the original problem
sampleset = sampler.solver.sample_cqm(info.data.data, **info.params).sampleset