Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sampling by id from DWaveSampler, LeapHybridSampler, LeapHybridDQMSampler #397

Open
arcondello opened this issue Apr 28, 2021 · 7 comments
Labels
feature-request/enhancement New feature or request

Comments

@arcondello
Copy link
Member

arcondello commented Apr 28, 2021

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.

@arcondello arcondello added the feature-request/enhancement New feature or request label Apr 28, 2021
@arcondello arcondello changed the title Allow sampling by problem id from DWaveSampler, LeapHybridSampler, LeapHybridDQMSampler Allow sampling by id from DWaveSampler, LeapHybridSampler, LeapHybridDQMSampler Apr 28, 2021
@arcondello
Copy link
Member Author

arcondello commented Mar 1, 2024

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

@randomir
Copy link
Member

randomir commented Mar 1, 2024

Actually, we first need to implement #398, i.e. dwavesystems/dwave-cloud-client#466.

@arcondello
Copy link
Member Author

arcondello commented Mar 1, 2024

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.

@randomir
Copy link
Member

randomir commented Mar 1, 2024

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).

@arcondello
Copy link
Member Author

arcondello commented Mar 1, 2024

Because I didn't actually resolve to see the error 😳 , my mistake. I'll fix and update, one sec

@arcondello
Copy link
Member Author

Ok, updated the comment, thanks @randomir

@randomir
Copy link
Member

randomir commented Mar 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants