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

sample_ising may drop variables when h is a list #393

Open mcfarljm opened 3 years ago

mcfarljm commented 3 years ago

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:

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