Skip to content

Symbolic higher order binary polynomials #988

Open
@mhlr

Description

@mhlr

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 <module>
----> 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 #864)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionQuestion or general discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions