dwavesystems / dwavesystems/dimod
Implement arithmetic operators for BinaryPolynomial
- Dominant language
- Python
- Stars
- 143
- Forks
- 91
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 3
Description
**Application**
It's frustrating that the higher order polynomial class (`BinaryPolynomial`), does not support basic arithmetic operators. It's also inconsistent with `BinaryQuadraticModel`, which does support such operators. This limits the usability of this class, since one cannot manipulate its objects in a convenient way.
**Proposed Solution**
`dimod` should support, at the minimum, the operators that `BinaryQuadraticModel` supports (see [here](https://github.com/dwavesystems/dimod/blob/0.11.3/dimod/binary/binary_quadratic_model.py)). In particular: addition, subtraction, multiplication (at least by a scalar!), and division (by a scalar).
(Take a look at [qubovert](https://qubovert.readthedocs.io/en/latest/BO/PUBO.html), where this is all implemented...)
**Additional Context**
Here's a minimal reproducer. First, this works fine for `BinaryQuadraticModel`:
```python
bqm = dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): 2}, 0.0, dimod.BINARY)
bqm-bqm
```
and fails for a `BinaryPolynomial`:
```python
poly = BinaryPolynomial({(1,): -1, (1,2): .5, (1,2,3): .5}, dimod.SPIN)
poly-poly
```
By giving the following error:
```python
TypeError: unsupported operand type(s) for -: 'BinaryPolynomial' and 'BinaryPolynomial'
```
Contributor guide
Assessment
This issue has not been assessed yet.