dwavesystems / dwavesystems/dimod

Symbolic higher order binary polynomials

Open
#988 4 comments 0 reactions 0 assignees View on GitHub
enhancement question
Dominant language
Python
Stars
143
Forks
91
Avg merge
1h 24m
Merged PRs (30d)
3

Description

**Application**
Currently dimod has a BinaryPolynomial class that can be constructed from higher order mappings like {(1,2,3): 1}
which can be passed to `make_quadratic` to create BQMs. We also have symbolic experssions for constructing BQMs.
However it is not possible to construct higher order BinomialPolynomials symbolically
```
dimod.Binary(1)*dimod.Binary(2)*dimod.Binary(3)
```
throws
```
TypeError Traceback (most recent call last)
/tmp/ipykernel_1301/2702588800.py in
----> 1 dimod.Binary(1)*dimod.Binary(2)*dimod.Binary(3)

~/anaconda3/lib/python3.8/site-packages/dimod/binary/binary_quadratic_model.py in __mul__(self, other)
258 if isinstance(other, BinaryQuadraticModel):
259 if not (self.is_linear() and other.is_linear()):
--> 260 raise TypeError(
261 "cannot multiply BQMs with interactions")
262 elif other.num_variables and other.vartype != self.vartype:

TypeError: cannot multiply BQMs with interactions
```
**Proposed Solution**
Extend symbolic expressions to BQMs with interactions and BinaryPolynomials:

BQM * BQM --> BinaryPolynomial, if either argument contains interactions
BQM BinaryPolynomial --> BinaryPolynomial
BinaryPolynomial BQM --> BinaryPolynomial
BinaryPolynomial BinaryPolynomial --> BinaryPolynomial

Also support non-negative integer powers of BQMs and BinaryPolynomials (see https://github.com/dwavesystems/dimod/issues/864)

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.