Does SimulatedAnnealingSampler work with ConstrainedQuadraticModels?
I know that the SimulatedAnnealingSampler works with BinaryQuadraticModels, but I'm not able to find any examples of its application to ConstrainedQuadraticModels. I wasn't able to find anything in the documentation indicating yes or now. So, I tried this out myself:
```
# Does SAS work with a CQM model?
from dwave.samplers import SimulatedAnnealingSampler
from dimod import QuadraticModel, BinaryQuadraticModel, ConstrainedQuadraticModel
bqm = BinaryQuadraticModel({'a': 0.1, 'b': 0.2}, {'ab': -1}, 'SPIN')
cqm_model = ConstrainedQuadraticModel().from_bqm(bqm)
sampler = SimulatedAnnealingSampler()
sampleset = sampler.sample(cqm_model)
```
It gives the following error: "
TypeError: change_vartype() takes exactly 2 positional arguments (1 given)"
Is this expected? If not, then how might I use the SimulatedAnnealingSampler on a ConstrainedQuadraticModel?
Comments
Hi Jordan,
SimulatedAnnealingSampler cannot be used to sample CQM directly. You can convert your CQM to BQM with dimod.cqm_to_bqm and then sample the resulting BQM using SimulatedAnnealingSampler.
Alternatively, for testing and debugging purposes, you can try using ExactCQMSolver that runs problems locally. However, as it calculates energy for all possible solutions, it is only suitable for small problems.
Please sign in to leave a comment.