dwavesystems / dwavesystems/dimod
Consider filtering functionality in `ConstrainedQuadraticModel.iter_constraint_data()`
- Dominant language
- Python
- Stars
- 143
- Forks
- 91
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 3
Description
Currently [`ConstrainedQuadraticModel.iter_constraint_data()`](https://github.com/dwavesystems/dimod/blob/835688330a6979bb6eeab7d21bbc8f845f37acbe/dimod/constrained/constrained.py#L1147) always iterates over every constraint in the model.
We should consider adding some keyword arguments to make that a bit easier when handling constraints in bulk. I am imagining something like
```Python
def iter_constraint_data(sample_like, *, filter_function=None):
if callable(filter_function):
yield from filter(filter_function, self.iter_constraint_data(sample_like))
return
...
```
and/or
```Python
def iter_constraint_data(sample_like, *, labels=None):
...
if labels is None:
labels = self.constraint_labels
for label in labels:
constraint = self.constraint(label)
lhs = constraint.lhs.energy((sample, labels))
rhs = constraint.rhs
sense = constraint.sense
...
```
Contributor guide
Assessment
This issue has not been assessed yet.