dwavesystems / dwavesystems/dwave-system

Add the ability to filter out infeasible samples when calling the LeapHybridCQMSampler

Open
#460 0 comments 0 reactions 0 assignees View on GitHub
feature-request/enhancement
Dominant language
Python
Stars
98
Forks
67
Avg merge
7m
Merged PRs (30d)
1

Description

Currently this can be done with
```python
sampleset = LeapHybridCQMSampler().sample_cqm(cqm)
feasible_sampleset = sampleset.filter(lambda d: d.is_feasible)
```
see https://github.com/dwavesystems/dimod/blob/ec9c3b274ff4104c00fe702d680b320f0bffca25/dimod/sampleset.py#L1371

It would be relatively straightforward to add a `filter_feasible` (or similar) keyword argument to the `LeapHybridCQMSampler.sample_cqm()` method. Something like
```python
feasible_sampleset = LeapHybridCQMSampler().sample_cqm(cqm, filter_feasible=True)
```

Some issues:
* Need to decide what to do in the case that there are no feasible solutions. Probably return an empty sample set, but could consider raising an exception.
* Would need to make `SampleSet.filter()` non-blocking, or handle this server-side. I don't think there is much performance benefit from doing it server-side though.

I personally feel like the existing syntax is explicit and unsurprising at the cost of one additional line of code, but perhaps some syntactic sugar here would be appreciated by users.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.