Make lower-level utilities available to third-party frameworks
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.
I think there are two specific features we'd like to support:
- 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.
- Variable format massaging. See https://github.com/dwavesystems/dwave-cloud-client/issues/465
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)?
Yes, it should subclass both, like the DWaveSampler.
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):
...