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

Allow different coordinate scheme in DWaveSampler #289

Open arcondello opened 4 years ago

arcondello commented 4 years ago

Something like

>>> sampler = DWaveSampler(coordinates=True)
>>> (0, 0, 0, 0) in sampler.nodelist
True 

There are a few problems with this though:

JoelPasvolsky commented 4 years ago

I see why using a flag would be annoying, but can you say something about the advantages of setting this at invocation versus some attribute you can set later?

arcondello commented 4 years ago

@JoelPasvolsky , I am not sure I understand, can you make a quick pseudo code snippet like above?

JoelPasvolsky commented 4 years ago

Something like this:

>>> sampler = DWaveSampler()
>>> sampler.default_coordinates = "coordinates"
>>> (0, 0, 0, 0) in sampler.nodelist
True
>>> sampler.default_coordinates = "nice_coordinates"
>>> (0, 0, 0, 0) in sampler.nodelist
False
arcondello commented 4 years ago

Part of the reason is that we generally consider the attributes of the dimod Samplers to be 'static', because otherwise you might get things like

>>> qpu = DWaveSampler()
>>> sampler = FixedEmbeddingComposite(DWaveSampler(), embedding_using_index)
>>> qpu.default_coordinates = "nice"  # this breaks the sampler

(the exception is the failover flag, which we explicitly warn about)

That said, a method like DWaveSampler.change_coordinates could definitely also exist, if it came with appropriate documentation.

JoelPasvolsky commented 4 years ago

Okay, thanks, I saw that as the user needing to be responsible for being consistent in using a coordinate scheme rather than breaking the sampler, but it is safer to use separate ones like sampler = FixedEmbeddingComposite(DWaveSampler(coordinates=True), embedding) and sampler_nice = FixedEmbeddingComposite(DWaveSampler(nice_coordinates=True), nice_embedding)