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

Different sorting methods for sample set dictionaries #529

Open krobbinsgit opened 3 months ago

krobbinsgit commented 3 months ago

Current Problem When a sampleset is output by the CQM solver, the dictionary is sorted in lexicographical order. Thus reading the values with sampleset.first.sample.values may not agree with the order of variables input into the problem, creating confusion if we want to independently verify the feasibility of a solution.

Proposed Solution An optional argument to sample_cqm() which sets the order of the sample set's dictionaries. Alternatively we could instead just keep the original order the variables were input into the model; maybe something like maintain_order = True

Alternatives Considered A naive workaround is to simply store the order of variables from the original input and create a new sample set dictionary using the lexicographical sample set's dictionary as a key.

Additional context Several customers have run into this in the past