Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample_ising may drop variables when h is a list #393

Open
mcfarljm opened this issue Apr 8, 2021 · 0 comments
Open

sample_ising may drop variables when h is a list #393

mcfarljm opened this issue Apr 8, 2021 · 0 comments

Comments

@mcfarljm
Copy link

mcfarljm commented Apr 8, 2021

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:

def sample_ising(self, h, *args, **kwargs):
# to be consistent with the cloud-client, we ignore the 0 biases
# on missing nodes for lists
if isinstance(h, list):
if len(h) > self.solver.num_qubits:
msg = "Problem graph incompatible with solver."
raise BinaryQuadraticModelStructureError(msg)
nodes = self.solver.nodes
h = dict((v, b) for v, b in enumerate(h) if b and v in nodes)
return super().sample_ising(h, *args, **kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant