dwave-system icon indicating copy to clipboard operation
dwave-system copied to clipboard

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

Open arcondello opened this issue 3 years ago • 0 comments

Currently this can be done with

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

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.

arcondello avatar Jul 14 '22 22:07 arcondello