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

`LeapHybridCQMSampler` sometimes generates the wrong `time_limit` for problems with sparse objectives #482

Open arcondello opened 1 year ago

arcondello commented 1 year ago

In dimod 0.12.0, the CQM models started storing the variable info globally rather than in the objective. However, the serialization was not changed to match, see https://github.com/dwavesystems/dimod/issues/1303.

This creates a situation where the serialized model does not have the same number of biases as the given model.

Failing example:

import dimod

from dwave.system import LeapHybridCQMSampler

sampler = LeapHybridCQMSampler()

cqm = dimod.ConstrainedQuadraticModel()
cqm.add_variables('INTEGER', 50_000)
cqm.add_constraint([(0, 1, 1)], '==', 0)

print(sampler.min_time_limit(cqm))

new = dimod.ConstrainedQuadraticModel().from_file(cqm.to_file())

print(sampler.min_time_limit(new))

gives

7.87090906404288
8.10376188704288

Proposed Solution

The correct fix is to implement https://github.com/dwavesystems/dimod/issues/1303, though we could as an interim solution read the relevant timing variables off of the header of the serialized model.