dwavesystems / dimod

A shared API for QUBO/Ising samplers.
https://docs.ocean.dwavesys.com/en/stable/docs_dimod/
Apache License 2.0
121 stars 80 forks source link

Prevent adding empty constraints to the CQM model #1177

Open mhramani opened 2 years ago

mhramani commented 2 years ago

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.

arcondello commented 2 years ago

I'll mark it as both! :smile: