CQM to BQM running on LeapHybridSampler and LeapHybridBQMSampler
I am successfully using CQM with LeapHybridCQMSampler for solving a problem (beautifully I might add).
I am also succesfully using dimod.cqm_to_bqm() to run the CQM model as a BQM using SimulatedAnnealingSampler for testing and benchmarks.
Now I would like to run the same BQM using LeapHybridBQMSampler and I am getting the following error:
TypeError: expected input vartype to be one of: Vartype.SPIN, 'SPIN', {-1, 1}, Vartype.BINARY, 'BINARY', or {0, 1}; received None.
What might I be missing to make the BQM from cqm_to_bqm compliant with LeapHybridBQMSampler ? Is it possible?
Thanks,
Mario
Here is the full stack
/usr/local/lib/python3.7/dist-packages/dwave/system/samplers/leap_hybrid_sampler.py in sample(self, bqm, time_limit, **kwargs) 223 """ 224 if not isinstance(bqm, BQM): --> 225 bqm = BQM(bqm) 226 227 num_vars = bqm.num_variables
/usr/local/lib/python3.7/dist-packages/dimod/binary/binary_quadratic_model.py in __init__(self, offset, vartype, dtype, *args) 167 self._init_bqm(args[0], vartype=args[0].vartype, dtype=dtype) 168 else: --> 169 self._init_empty(vartype=args[0], dtype=dtype) 170 elif len(args) == 2: 171 # BQM(bqm, vartype), BQM(n, vartype) or BQM(M, vartype)
/usr/local/lib/python3.7/dist-packages/dimod/binary/binary_quadratic_model.py in _init_empty(self, vartype, dtype) 262 def _init_empty(self, vartype, dtype): 263 dtype = self.DEFAULT_DTYPE if dtype is None else dtype --> 264 self.data = type(self)._DATA_CLASSES[np.dtype(dtype)](vartype) 265 266 def __init_subclass__(cls, default_dtype=np.float64, **kwargs):
/usr/local/lib/python3.7/dist-packages/dimod/binary/cybqm/cybqm_template.pyx.pxi in dimod.binary.cybqm.cybqm_float64.cyBQM_template.__init__()
/usr/local/lib/python3.7/dist-packages/dimod/binary/cybqm/cybqm_template.pyx.pxi in dimod.binary.cybqm.cybqm_float64.cyBQM_template.change_vartype()
/usr/local/lib/python3.7/dist-packages/dimod/vartypes.py in as_vartype(vartype, extended) 171 raise _vartype_miss(vartype, extended) from None 172 else: --> 173 raise _vartype_miss(vartype, extended) 174 175 if not extended and vartype != SPIN and vartype != BINARY:
TypeError: expected input vartype to be one of: Vartype.SPIN, 'SPIN', {-1, 1}, Vartype.BINARY, 'BINARY', or {0, 1}; received None.
Comments
Hello,
It sounds like you might be using the object returned from the dimod.cqm_to_bqm() function directly.
If you take a look at the reference docs, this function actually returns a tuple:
https://docs.ocean.dwavesys.com/en/latest/docs_dimod/reference/generated/dimod.cqm_to_bqm.html
In order to access the BQM returned, the function should be called like this:
Hopefully this resolves your issue.
Please feel free to reach out with more questions or for clarification.
Hello David,
Well... that was interesting. An additional condition I added to select Quantum BQM vs Classical was inadvertently excluding the cqm_to_bqm in the specific case of wanting to use CQM->BQM Simulated -> BQM->Quantum.
Thanks for the pointer, I could not see the forest from the trees on this one.
Mario
Hello,
It sounds like you have sorted out the problem.
Was this specific to your implementation or could we possibly make something more clear in the documentation?
Thank you for reaching out to us.
Hello,
All good, this was entirely a coding oversight on my part.
Thank you.
Please sign in to leave a comment.