dimod icon indicating copy to clipboard operation
dimod copied to clipboard

Prevent adding empty constraints to the CQM model

Open mhramani opened this issue 3 years ago • 1 comments

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.

mhramani avatar Apr 21 '22 19:04 mhramani

I'll mark it as both! :smile:

arcondello avatar Apr 21 '22 19:04 arcondello