dwavesystems / dwavesystems/dimod
Automatically remove zero entries from model
- Dominant language
- Python
- Stars
- 143
- Forks
- 91
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 3
Description
**Application**
I find it surprising and frustrating that zero entries are not automatically removed from models.
**Proposed Solution**
Check if a calculation results in a zero, and then remove - perhaps the datastructure could do this automatically.
**Additional Context**
Here's a minimal example. I expected the below to result in a BQM with no couplings (a scalar zero):
```python
bqm = dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): 2}, 0.0, dimod.BINARY)
bqm-bqm
```
Instead, we get:
```python
BinaryQuadraticModel({0: -0.0, 1: -0.0}, {(1, 0): -0.0}, -0.0, 'BINARY')
```
I realize that checking for zeros will incur an overhead. However, that must be weighed against the (potentially much larger) saved overhead when doing any kind of downstream calculation on the polymial, which will require iterating over all terms even the pesky zero ones!
Contributor guide
Assessment
This issue has not been assessed yet.