dwavesystems / dwavesystems/dwave-system
Consider creating a mechanism for submitting multiple times to the same hybrid sampler
- Dominant language
- Python
- Stars
- 98
- Forks
- 67
- Avg merge
- 7m
- Merged PRs (30d)
- 1
Description
For example, if you wanted to submit multiple times to the hybrid NL solver without reuploading the model between runs, you could do so with something like
```python
import numpy as np
from dwave.cloud.computation import Future
from dwave.optimization.generators import knapsack
from dwave.system import LeapHybridNLSampler
model = knapsack(range(100), range(100), capacity=100)
x, = model.iter_decisions()
sampler = LeapHybridNLSampler()
# Get the timelimit for the problem
time_limit = sampler.estimated_min_time_limit(model)
# We can upload at most one state
problem_data_id = sampler.solver.upload_nlm(model, max_num_states=1).result()
def hook(model, future):
model.states.from_file(future.answer_data, check_header=False)
# 10 submissions
futures = []
for _ in range(10):
futures.append(sampler.solver.sample_nlm(problem_data_id, time_limit=time_limit))
states = []
for completed in Future.as_completed(futures):
model.states.from_future(completed, hook)
# This needs to be saved "off" the model! It will be overwritten in the
# next loop
print(x.state())
states.extend(np.asarray(x.state(i)) for i in range(len(model.states)))
print(states)
```
This seems to be a semi-common use case so bundling it into a method or function might be helpful.
Probably needs https://github.com/dwavesystems/dwave-optimization/issues/185 in the case of NL to be done elegantly. For CQM/BQM/DQM we could use [dimod.concatenate()](https://docs.ocean.dwavesys.com/en/stable/docs_dimod/reference/generated/dimod.concatenate.html).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.