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

sample_ising may drop variables when h is a list

Open mcfarljm opened this issue 4 years ago • 0 comments

For example, using a structured sampler where qubit 0 is not available, the following silently drops the variable and produces an empty sampleset:

DWaveSampler().sample_ising([1], {})

whereas using a dict for h that includes an invalid qubit (or as part of J) will raise an error:

DWaveSampler().sample_ising({0: 1}, {})
BinaryQuadraticModelStructureError: Problem graph incompatible with solver.

Documentation for the base class method is: https://github.com/dwavesystems/dimod/blob/25065ad8d30154098f55d827022b815421822864/dimod/core/sampler.py#L200-L205

Possibilities for addressing this include:

  • Deprecating the use of a list for h in sample_ising (altogether or just for DWaveSampler?) Con: may still be value in allowing it from memory efficiency perspective.
  • Propagate a warning
  • Raise an exception. This would be more consistent with the behavior when h is a dict, and it matches the docstring of the original behavior.

Original docstring:

        *h* --- List or tuple of the linear Ising coefficients. The
         :math:`h` value of a non-working qubit must be zero or an
         exception will be raised. Inactive qubits are disabled during
         annealing and cannot distinguish their states.

Relevant code in DWaveSampler: https://github.com/dwavesystems/dwave-system/blob/bedfe5143a8579348be07e4ef5e8fe0646ce81ff/dwave/system/samplers/dwave_sampler.py#L365-L375

mcfarljm avatar Apr 08 '21 17:04 mcfarljm