dimod
dimod copied to clipboard
Prevent adding empty constraints to the CQM model
Not sure if this is a bug or a feature request. Since I didn't expect this to happen, I file it as a bug, please change to feature request if more appropriate.
I do not expect to be able to add an empty constraint to a CQM model.
import dimod
cqm = dimod.CQM()
cqm.add_constraint( dimod.quicksum([]) <= 0)
print(len(cqm.constraints))
While there might be some rare use cases for this, like creating a constraint first and filling it later, it would be better to prevent this as the empty constraint might be counted toward maximum constraint allowed by the HSS system. I also suggest to remove empty constraints resulted from variable fixing or constraint removing.
I'll mark it as both! :smile: