dwavesystems / dwave-system

An API for easily incorporating the D-Wave system as a sampler, either directly or through Leap's cloud-based hybrid samplers
https://docs.ocean.dwavesys.com/
Apache License 2.0
90 stars 64 forks source link

Make lower-level utilities available to third-party frameworks #401

Open speller26 opened 3 years ago

speller26 commented 3 years ago

Current Problem I want to use some of the the low-level utilities provided in dwave-cloud-client directly from a third-party sampler.

For example, I'd like to validate that my problem is compatible with a device's graph. This functionality is available in the DWaveSampler's underlying Client, but not directly from the sampler; I have to access the low-level Client. However, a third-party sampler does not have an underlying Client, so it becomes impossible to use this feature.

Proposed Solution Expose useful lower-level utilities through the Sampler interface.

arcondello commented 3 years ago

I think there are two specific features we'd like to support: 1) Graph validation. This can be done now with

all(v in sampler.adjacency for v in bqm.variables) and (u in sampler.adjacency[v] for u, v in bqm.quadratic)

if you have a StructuredSampler.

One solution might be to add a sampler.check_structure(bqm) method to the structured sampler ABC.

2) Variable format massaging. See https://github.com/dwavesystems/dwave-cloud-client/issues/465

speller26 commented 3 years ago

When you say StructuredSampler, do you just mean that the Sampler implementation should subclass both Sampler and Structured (I don't see a StructuredSampler class; will that be added)?

arcondello commented 3 years ago

Yes, it should subclass both, like the DWaveSampler.

randomir commented 3 years ago

To @speller26's point, adding StructuredSampler with relevant utilities, and then subclassing it in DWaveSampler makes the most sense to me (see https://github.com/dwavesystems/dimod/pull/832#discussion_r644310027).

Something like:

# in dimod
class StructuredSampler(dimod.Structured, dimod.Sampler):
    def samples_from(self, bqm):
        ...

# in dwave-system
class DWaveSampler(dimod.StructuredSampler):
    ...