dimod icon indicating copy to clipboard operation
dimod copied to clipboard

Refactoring & optimizing large BinaryPolynomial construction

Open mhlr opened this issue 4 years ago • 7 comments

Continuing #988 explorations. This produces a >8x speedup in the construction of large BinaryPolynomial instances, see notebook

mhlr avatar Sep 10 '21 02:09 mhlr

I am thinking about making all the operations keep the polynomials zero free

mhlr avatar Sep 16 '21 15:09 mhlr

I am thinking about making all the operations keep the polynomials zero free

That would be a backwards compatibility break. I am not opposed philosophically, but it would need to wait until dimod 0.11.

arcondello avatar Sep 16 '21 15:09 arcondello

I am thinking about making all the operations keep the polynomials zero free

That would be a backwards compatibility break. I am not opposed philosophically, but it would need to wait until dimod 0.11.

Fair enough. I think that could significantly improve scalability, both memory and time.though

mhlr avatar Sep 16 '21 15:09 mhlr

I am thinking about making all the operations keep the polynomials zero free

That would be a backwards compatibility break. I am not opposed philosophically, but it would need to wait until dimod 0.11.

Does anything really rely on the 0 weighted terms being stored explicitly?

mhlr avatar Sep 16 '21 20:09 mhlr

Strictly speaking

In [3]: p = dimod.BinaryPolynomial({}, 'BINARY')

In [4]: p['abc'] = 0

In [5]: p
Out[5]: BinaryPolynomial({frozenset({'b', 'c', 'a'}): 0}, 'BINARY')

In [6]: list(p)
Out[6]: [frozenset({'a', 'b', 'c'})]

whether that "break" actually matters to anyone? :shrug:

FWIW, it is consistent with the BQM/QM behavior where we do explicitly keep 0 bias variables/interactions.

arcondello avatar Sep 16 '21 20:09 arcondello

Should we make a backlog entry for 0.11?

mhlr avatar Sep 17 '21 00:09 mhlr

@arcondello The last set of commits are the make_quadratic refactoring

mhlr avatar Sep 22 '21 18:09 mhlr