dwavesystems / dwavesystems/dimod

Implement arithmetic operators for BinaryPolynomial

Open
#1,215 5 comments 0 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.